本文整理汇总了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