models.__dict__[args.model]()

import torchvision.models as models
models = models.__dict__

{
name’: ‘torchvision.models’,
doc’: None,
package’: ‘torchvision.models’,



‘DenseNet’: torchvision.models.densenet.DenseNet,
‘densenet121’: ,
‘densenet169’: ,
‘densenet201’: ,
‘densenet161’:
}

输出是一个字典,这个字典包含了该对象里面所有的属性,可以通过这种方式来访问对象的属性

resnet = models.__dict__['resnet18']

你可能感兴趣的:(pytorch,pytorch,深度学习,python)