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


Python resnet.resnet34方法代码示例

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


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

示例1: get_model_param

# 需要导入模块: from models import resnet [as 别名]
# 或者: from models.resnet import resnet34 [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() 
开发者ID:husencd,项目名称:DriverPostureClassification,代码行数:42,代码来源:model.py

示例2: get_net

# 需要导入模块: from models import resnet [as 别名]
# 或者: from models.resnet import resnet34 [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 
开发者ID:google-research,项目名称:s4l,代码行数:40,代码来源:utils.py


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