当前位置: 首页>>代码示例>>Python>>正文


Python vgg.VGG属性代码示例

本文整理汇总了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 
开发者ID:xuanqing94,项目名称:BayesianDefense,代码行数:41,代码来源:transfer_attack.py


注:本文中的models.vgg.VGG属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。