本文整理匯總了Python中models.imagenet.__dict__方法的典型用法代碼示例。如果您正苦於以下問題:Python imagenet.__dict__方法的具體用法?Python imagenet.__dict__怎麽用?Python imagenet.__dict__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.imagenet
的用法示例。
在下文中一共展示了imagenet.__dict__方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_model
# 需要導入模塊: from models import imagenet [as 別名]
# 或者: from models.imagenet import __dict__ [as 別名]
def create_model(pretrained, dataset, arch, parallel=True, device_ids=None):
"""Create a pytorch model based on the model architecture and dataset
Args:
pretrained: True is you wish to load a pretrained model. Only torchvision models
have a pretrained model.
dataset:
arch:
parallel:
"""
msglogger.info('==> using %s dataset' % dataset)
model = None
if dataset == 'imagenet':
str_pretrained = 'pretrained ' if pretrained else ''
msglogger.info("=> using %s%s model for ImageNet" % (str_pretrained, arch))
assert arch in torch_models.__dict__ or arch in imagenet_extra_models.__dict__, \
"Model %s is not supported for dataset %s" % (arch, 'ImageNet')
if arch in torch_models.__dict__:
model = torch_models.__dict__[arch](pretrained=pretrained)
else:
assert not pretrained, "Model %s (ImageNet) does not have a pretrained model" % arch
model = imagenet_extra_models.__dict__[arch]()
elif dataset == 'cifar10':
msglogger.info("=> creating %s model for CIFAR10" % arch)
assert arch in cifar10_models.__dict__, "Model %s is not supported for dataset CIFAR10" % arch
assert not pretrained, "Model %s (CIFAR10) does not have a pretrained model" % arch
model = cifar10_models.__dict__[arch]()
else:
print("FATAL ERROR: create_model does not support models for dataset %s" % dataset)
exit()
if (arch.startswith('alexnet') or arch.startswith('vgg')) and parallel:
model.features = torch.nn.DataParallel(model.features, device_ids=device_ids)
elif parallel:
model = torch.nn.DataParallel(model, device_ids=device_ids)
model.cuda()
return model