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


Python pretrainedmodels.resnet152方法代码示例

本文整理汇总了Python中pretrainedmodels.resnet152方法的典型用法代码示例。如果您正苦于以下问题:Python pretrainedmodels.resnet152方法的具体用法?Python pretrainedmodels.resnet152怎么用?Python pretrainedmodels.resnet152使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pretrainedmodels的用法示例。


在下文中一共展示了pretrainedmodels.resnet152方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import resnet152 [as 别名]
def main(args):
    global C, H, W
    coco_labels = json.load(open(args.coco_labels))
    num_classes = coco_labels['num_classes']
    if args.model == 'inception_v3':
        C, H, W = 3, 299, 299
        model = pretrainedmodels.inceptionv3(pretrained='imagenet')

    elif args.model == 'resnet152':
        C, H, W = 3, 224, 224
        model = pretrainedmodels.resnet152(pretrained='imagenet')

    elif args.model == 'inception_v4':
        C, H, W = 3, 299, 299
        model = pretrainedmodels.inceptionv4(
            num_classes=1000, pretrained='imagenet')

    else:
        print("doesn't support %s" % (args['model']))

    load_image_fn = utils.LoadTransformImage(model)
    dim_feats = model.last_linear.in_features
    model = MILModel(model, dim_feats, num_classes)
    model = model.cuda()
    dataset = CocoDataset(coco_labels)
    dataloader = DataLoader(
        dataset, batch_size=args.batch_size, shuffle=True)
    optimizer = optim.Adam(
        model.parameters(), lr=args.learning_rate, weight_decay=args.weight_decay)
    exp_lr_scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=args.learning_rate_decay_every,
                                                 gamma=args.learning_rate_decay_rate)

    crit = nn.MultiLabelSoftMarginLoss()
    if not os.path.isdir(args.checkpoint_path):
        os.mkdir(args.checkpoint_path)
    train(dataloader, model, crit, optimizer,
          exp_lr_scheduler, load_image_fn, args) 
开发者ID:Sundrops,项目名称:video-caption.pytorch,代码行数:39,代码来源:finetune_cnn.py

示例2: __init__

# 需要导入模块: import pretrainedmodels [as 别名]
# 或者: from pretrainedmodels import resnet152 [as 别名]
def __init__(self):
        super(FeatureExtractor, self).__init__()
        self.model = pretrainedmodels.resnet152()
        self.FEAT_SIZE = 2048 
开发者ID:OpenNMT,项目名称:OpenNMT-py,代码行数:6,代码来源:vid_feature_extractor.py


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