本文整理汇总了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