當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。