本文整理汇总了Python中models.vgg.VGG属性的典型用法代码示例。如果您正苦于以下问题:Python vgg.VGG属性的具体用法?Python vgg.VGG怎么用?Python vgg.VGG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类models.vgg
的用法示例。
在下文中一共展示了vgg.VGG属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_model
# 需要导入模块: from models import vgg [as 别名]
# 或者: from models.vgg import VGG [as 别名]
def get_model(defense):
# load model
if model == 'vgg':
if defense in ('plain', 'adv'):
from models.vgg import VGG
net = nn.DataParallel(VGG('VGG16', nclass, img_width=img_width), device_ids=range(1))
net.load_state_dict(torch.load(f'./checkpoint/{data}_{model}_{defense}.pth'))
elif defense in ('vi', 'adv_vi'):
from models.vgg_vi import VGG
net = nn.DataParallel(VGG(1.0, 1.0, 1.0, 'VGG16', nclass, img_width=img_width), device_ids=range(1))
elif defense in ('rse'):
from models.vgg_rse import VGG
net = nn.DataParallel(VGG('VGG16', nclass, 0.2, 0.1, img_width=img_width), device_ids=range(1))
elif model == 'tiny':
if defense in ('plain', 'adv'):
from models.tiny import Tiny
net = nn.DataParallel(Tiny(nclass), device_ids=range(1))
elif defense in ('vi', 'adv_vi'):
from models.tiny_vi import Tiny
net = nn.DataParallel(Tiny(1.0, 1.0, 1.0, nclass), device_ids=range(1))
elif defense in ('rse'):
from models.tiny_rse import Tiny
net = nn.DataParallel(Tiny(nclass, 0.2, 0.1), device_ids=range(1))
elif model == 'aaron':
if defense in ('plain', 'adv'):
from models.aaron import Aaron
net = nn.DataParallel(Aaron(nclass), device_ids=range(1))
elif defense in ('vi', 'adv_vi'):
from models.aaron_vi import Aaron
net = nn.DataParallel(Aaron(1.0, 1.0, 1.0, nclass), device_ids=range(1))
elif defense in ('rse'):
from models.aaron_rse import Aaron
net = nn.DataParallel(Aaron(nclass, 0.2, 0.1), device_ids=range(1))
else:
raise ValueError('invalid model')
net.load_state_dict(torch.load(f'./checkpoint/{data}_{model}_{defense}.pth'))
net.cuda()
net.eval() # must set to evaluation mode
return net