本文整理匯總了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)
示例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