本文整理匯總了Python中models.resnet.resnet50方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet.resnet50方法的具體用法?Python resnet.resnet50怎麽用?Python resnet.resnet50使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.resnet
的用法示例。
在下文中一共展示了resnet.resnet50方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_net
# 需要導入模塊: from models import resnet [as 別名]
# 或者: from models.resnet import resnet50 [as 別名]
def get_net(num_classes=None): # pylint: disable=missing-docstring
architecture = FLAGS.architecture
task = FLAGS.task
if "resnet18" in architecture:
net = resnet.resnet18
elif "resnet34" in architecture:
net = resnet.resnet34
elif "resnet50" in architecture or "resnext50" in architecture:
net = resnet.resnet50
elif "resnet101" in architecture or "resnext101" in architecture:
net = resnet.resnet101
elif "resnet152" in architecture or "resnext152" in architecture:
net = resnet.resnet152
elif "revnet18" in architecture:
net = resnet.revnet18
elif "revnet34" in architecture:
net = resnet.revnet34
elif "revnet50" in architecture:
net = resnet.revnet50
elif "revnet101" in architecture:
net = resnet.revnet101
elif "revnet152" in architecture:
net = resnet.revnet152
else:
raise ValueError("Unsupported architecture: %s" % architecture)
net = functools.partial(net, filters_factor=FLAGS.filters_factor, mode="v2")
if "resnext" in architecture:
net = functools.partial(net, groups=32)
# Few things that are common across all models.
net = functools.partial(
net, num_classes=num_classes,
weight_decay=FLAGS.weight_decay)
return net
示例2: define_model
# 需要導入模塊: from models import resnet [as 別名]
# 或者: from models.resnet import resnet50 [as 別名]
def define_model(encoder='resnet'):
if encoder is 'resnet':
original_model = resnet.resnet50(pretrained = True)
Encoder = modules.E_resnet(original_model)
model = net.model(Encoder, num_features=2048, block_channel = [256, 512, 1024, 2048])
if encoder is 'densenet':
original_model = densenet.densenet161(pretrained=True)
Encoder = modules.E_densenet(original_model)
model = net.model(Encoder, num_features=2208, block_channel = [192, 384, 1056, 2208])
if encoder is 'senet':
original_model = senet.senet154(pretrained='imagenet')
Encoder = modules.E_senet(original_model)
model = net.model(Encoder, num_features=2048, block_channel = [256, 512, 1024, 2048])
return model
示例3: get_model_param
# 需要導入模塊: from models import resnet [as 別名]
# 或者: from models.resnet import resnet50 [as 別名]
def get_model_param(args):
# assert args.model in ['resnet', 'vgg']
if args.model == 'resnet':
assert args.model_depth in [18, 34, 50, 101, 152]
from models.resnet import get_fine_tuning_parameters
if args.model_depth == 18:
model = resnet.resnet18(pretrained=False, input_size=args.input_size, num_classes=args.n_classes)
elif args.model_depth == 34:
model = resnet.resnet34(pretrained=False, input_size=args.input_size, num_classes=args.n_classes)
elif args.model_depth == 50:
model = resnet.resnet50(pretrained=False, input_size=args.input_size, num_classes=args.n_classes)
elif args.model_depth == 101:
model = resnet.resnet101(pretrained=False, input_size=args.input_size, num_classes=args.n_classes)
elif args.model_depth == 152:
model = resnet.resnet152(pretrained=False, input_size=args.input_size, num_classes=args.n_classes)
# elif args.model == 'vgg':
# pass
# Load pretrained model here
if args.finetune:
pretrained_model = model_path[args.arch]
args.pretrain_path = os.path.join(args.root_path, 'pretrained_models', pretrained_model)
print("=> loading pretrained model '{}'...".format(pretrained_model))
model.load_state_dict(torch.load(args.pretrain_path))
# Only modify the last layer
if args.model == 'resnet':
model.fc = nn.Linear(model.fc.in_features, args.n_finetune_classes)
# elif args.model == 'vgg':
# pass
parameters = get_fine_tuning_parameters(model, args.ft_begin_index, args.lr_mult1, args.lr_mult2)
return model, parameters
return model, model.parameters()