當前位置: 首頁>>代碼示例>>Python>>正文


Python resnet.resnet50方法代碼示例

本文整理匯總了Python中torchvision.models.resnet.resnet50方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet.resnet50方法的具體用法?Python resnet.resnet50怎麽用?Python resnet.resnet50使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torchvision.models.resnet的用法示例。


在下文中一共展示了resnet.resnet50方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load_resnet_imagenet

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def _load_resnet_imagenet(pretrained=True):
    # huge thx to https://github.com/ruotianluo/pytorch-faster-rcnn/blob/master/lib/nets/resnet_v1.py
    backbone = resnet.resnet50(pretrained=pretrained)
    for i in range(2, 4):
        getattr(backbone, 'layer%d' % i)[0].conv1.stride = (2, 2)
        getattr(backbone, 'layer%d' % i)[0].conv2.stride = (1, 1)
    # use stride 1 for the last conv4 layer (same as tf-faster-rcnn)
    backbone.layer4[0].conv2.stride = (1, 1)
    backbone.layer4[0].downsample[0].stride = (1, 1)

    # # Make batchnorm more sensible
    # for submodule in backbone.modules():
    #     if isinstance(submodule, torch.nn.BatchNorm2d):
    #         submodule.momentum = 0.01

    return backbone 
開發者ID:yuweijiang,項目名稱:HGL-pytorch,代碼行數:18,代碼來源:detector.py

示例2: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self, num_classes=None, last_stride=1, pretrained=False):
        super().__init__()
        self.base = ResNet(last_stride)
        if pretrained:
            model_url = 'https://download.pytorch.org/models/resnet50-19c8e357.pth'
            self.base.load_param(model_zoo.load_url(model_url))

        self.num_classes = num_classes
        if num_classes is not None:
            self.bottleneck = nn.Sequential(
                nn.Linear(self.in_planes, 512),
                nn.BatchNorm1d(512),
                nn.LeakyReLU(0.1),
                nn.Dropout(p=0.5)
            )
            self.bottleneck.apply(weights_init_kaiming)
            self.classifier = nn.Linear(512, self.num_classes)
            self.classifier.apply(weights_init_classifier) 
開發者ID:daizuozhuo,項目名稱:batch-dropblock-network,代碼行數:20,代碼來源:networks.py

示例3: _load_resnet

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def _load_resnet(pretrained=True):
    # huge thx to https://github.com/ruotianluo/pytorch-faster-rcnn/blob/master/lib/nets/resnet_v1.py
    backbone = resnet.resnet50(pretrained=False)
    if pretrained:
        backbone.load_state_dict(model_zoo.load_url(
            'https://s3.us-west-2.amazonaws.com/ai2-rowanz/resnet50-e13db6895d81.th'))
    for i in range(2, 4):
        getattr(backbone, 'layer%d' % i)[0].conv1.stride = (2, 2)
        getattr(backbone, 'layer%d' % i)[0].conv2.stride = (1, 1)
    return backbone 
開發者ID:yuweijiang,項目名稱:HGL-pytorch,代碼行數:12,代碼來源:detector.py

示例4: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self, pretrained=True, input_channels=3):
        model = resnet.resnet50(pretrained=pretrained)
        super().__init__(
            model=model,
            input_channels=input_channels) 
開發者ID:PavelOstyakov,項目名稱:pipeline,代碼行數:7,代碼來源:resnet.py

示例5: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self):
        super().__init__()
        self.net = resnet.resnet50(pretrained=True)

        self.stage1 = nn.Sequential(
            self.net.conv1,
            self.net.bn1,
            self.net.relu,
            self.net.maxpool
        )
        self.stage2 = self.net.layer1
        self.stage3 = self.net.layer2
        self.stage4 = self.net.layer3
        self.stage5 = self.net.layer4 
開發者ID:princewang1994,項目名稱:TextSnake.pytorch,代碼行數:16,代碼來源:resnet.py

示例6: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self, feature_channels=2048):
        super().__init__(feature_channels)

        self.res_net = resnet.resnet50()
        self.res_net.avgpool = submodules.identity()
        self.res_net.fc = submodules.identity()

        weight_init.init(self.modules()) 
開發者ID:cmsflash,項目名稱:beauty-net,代碼行數:10,代碼來源:res_net.py

示例7: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self, labelclassMap, numAnchors=9, backbone='resnet50', pretrained=True, out_planes=256, convertToInstanceNorm=False):
        super(RetinaNet, self).__init__()

        self.labelclassMap = labelclassMap
        self.numClasses = len(labelclassMap.keys())
        self.numAnchors = numAnchors
        self.backbone = backbone
        self.pretrained = pretrained
        self.out_planes = out_planes
        self.convertToInstanceNorm = convertToInstanceNorm
        self.fpn = FPN(self.backbone, self.pretrained, self.out_planes, self.convertToInstanceNorm)

        self.loc_head = self._make_head(self.numAnchors*4, dropout=0.2)
        self.cls_head = self._make_head(self.numAnchors*self.numClasses, dropout=None) 
開發者ID:microsoft,項目名稱:aerial_wildlife_detection,代碼行數:16,代碼來源:model.py

示例8: loadFromStateDict

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def loadFromStateDict(stateDict):
        # parse args
        labelclassMap = stateDict['labelclassMap']
        numAnchors = (stateDict['numAnchors'] if 'numAnchors' in stateDict else 9)
        backbone = (stateDict['backbone'] if 'backbone' in stateDict else resnet.resnet50)
        pretrained = (stateDict['pretrained'] if 'pretrained' in stateDict else True)
        out_planes = (stateDict['out_planes'] if 'out_planes' in stateDict else 256)
        convertToInstanceNorm = (stateDict['convertToInstanceNorm'] if 'convertToInstanceNorm' in stateDict else False)
        state = (stateDict['model_state'] if 'model_state' in stateDict else None)

        # return model
        model = RetinaNet(labelclassMap, numAnchors, backbone, pretrained, out_planes, convertToInstanceNorm)
        if state is not None:
            model.load_state_dict(state)
        return model 
開發者ID:microsoft,項目名稱:aerial_wildlife_detection,代碼行數:17,代碼來源:model.py

示例9: get

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def get(cls, args):
        model = ResNet3DAutoencoder([3, 4, 6, 3])  # 50
        if args.pretrained:
            from torchvision.models.resnet import resnet50
            model2d = resnet50(pretrained=True)
            model.encoder.load_2d(model2d)
        return model 
開發者ID:gsig,項目名稱:PyVideoResearch,代碼行數:9,代碼來源:resnet50_3d_autoencoder4.py

示例10: get

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def get(cls, args):
        model = ResNet3DNonLocal(Bottleneck3D, [3, 4, 6, 3])  # 50
        if args.pretrained:
            from torchvision.models.resnet import resnet50
            model2d = resnet50(pretrained=True)
            model.load_2d(model2d)
        model.insert_nonlocal_blocks([0, 2, 3, 0])
        return model 
開發者ID:gsig,項目名稱:PyVideoResearch,代碼行數:10,代碼來源:resnet50_3d_nonlocal.py

示例11: get

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def get(cls, args):
        model = ResNet3DEncoder(Bottleneck3D, [3, 4, 6, 3])  # 50
        if args.pretrained:
            from torchvision.models.resnet import resnet50
            model2d = resnet50(pretrained=True)
            model.load_2d(model2d)
        return model 
開發者ID:gsig,項目名稱:PyVideoResearch,代碼行數:9,代碼來源:resnet50_3d_encoder.py

示例12: get

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def get(cls, args):
        model = ResNet3D(Bottleneck3D, [3, 4, 6, 3])  # 50
        if args.pretrained:
            from torchvision.models.resnet import resnet50
            model2d = resnet50(pretrained=True)
            model.load_2d(model2d)
        return model 
開發者ID:gsig,項目名稱:PyVideoResearch,代碼行數:9,代碼來源:resnet50_3d.py

示例13: test_actor_observer_with_classifier_updates

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def test_actor_observer_with_classifier_updates(self):
        torch.manual_seed(12345)
        from torchvision.models.resnet import resnet50
        from models.wrappers.actor_observer_with_classifier_wrapper import ActorObserverWithClassifierWrapper
        from models.criteria.actor_observer_with_classifier_criterion import ActorObserverWithClassifierCriterion
        args = Args()
        args.nclass = 157
        args.freeze_batchnorm = False
        args.finaldecay = 0.9
        args.decay = 0.9
        args.margin = 0.0
        args.classifier_weight = 1.0
        args.share_selector = False
        args.normalize_per_video = False
        model = resnet50()
        model = ActorObserverWithClassifierWrapper(model, args)
        b, d = 10, 224
        inputs = [torch.randn(b, 3, d, d), torch.randn(b, 3, d, d), torch.randn(b, 3, d, d)]
        meta = {'thirdtime': torch.zeros(b),
                'firsttime_pos': torch.zeros(b),
                'firsttime_neg': torch.zeros(b),
                'n': torch.zeros(b),
                'n_ego': torch.zeros(b),
                'id': ['asdf'] * b,
                }
        target = torch.ones(b, args.nclass)
        target[b//2:, 0] = -1
        args.balanceloss = False
        args.window_smooth = 0
        criterion = ActorObserverWithClassifierCriterion(args)
        test_model_updates(inputs, model, target, criterion, meta) 
開發者ID:gsig,項目名稱:PyVideoResearch,代碼行數:33,代碼來源:test_actor_observer.py

示例14: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def __init__(self, arch, scene_classes=1055):
        super(RGBBranch, self).__init__()

        # --------------------------------#
        #          Base Network           #
        # ------------------------------- #
        if arch == 'ResNet-18':
            # ResNet-18 Network
            base = resnet.resnet18(pretrained=True)
            # Size parameters for ResNet-18
            size_fc_RGB = 512
        elif arch == 'ResNet-50':
            # ResNet-50 Network
            base = resnet.resnet50(pretrained=True)
            # Size parameters for ResNet-50
            size_fc_RGB = 2048

        # --------------------------------#
        #           RGB Branch            #
        # ------------------------------- #
        # First initial block
        self.in_block = nn.Sequential(
            nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3, bias=False),
            nn.BatchNorm2d(64),
            nn.ReLU(inplace=True),
            nn.MaxPool2d(kernel_size=3, stride=2, padding=1, return_indices=True)
        )

        # Encoder
        self.encoder1 = base.layer1
        self.encoder2 = base.layer2
        self.encoder3 = base.layer3
        self.encoder4 = base.layer4

        # -------------------------------------#
        #            RGB Classifier            #
        # ------------------------------------ #
        self.dropout = nn.Dropout(0.3)
        self.avgpool = nn.AvgPool2d(7, stride=1)
        self.fc = nn.Linear(size_fc_RGB, scene_classes)

        # Loss
        self.criterion = nn.CrossEntropyLoss() 
開發者ID:vpulab,項目名稱:Semantic-Aware-Scene-Recognition,代碼行數:45,代碼來源:RGBBranch.py

示例15: create_model

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import resnet50 [as 別名]
def create_model(model_name, num_classes=1000, pretrained=False, **kwargs):
    if 'test_time_pool' in kwargs:
        test_time_pool = kwargs.pop('test_time_pool')
    else:
        test_time_pool = True
    if model_name == 'dpn68':
        model = dpn68(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'dpn68b':
        model = dpn68b(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'dpn92':
        model = dpn92(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'dpn98':
        model = dpn98(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'dpn131':
        model = dpn131(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'dpn107':
        model = dpn107(
            pretrained=pretrained, test_time_pool=test_time_pool, num_classes=num_classes)
    elif model_name == 'resnet18':
        model = resnet18(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'resnet34':
        model = resnet34(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'resnet50':
        model = resnet50(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'resnet101':
        model = resnet101(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'resnet152':
        model = resnet152(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'densenet121':
        model = densenet121(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'densenet161':
        model = densenet161(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'densenet169':
        model = densenet169(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'densenet201':
        model = densenet201(pretrained=pretrained, num_classes=num_classes, **kwargs)
    elif model_name == 'inception_v3':
        model = inception_v3(
            pretrained=pretrained, num_classes=num_classes, transform_input=False, **kwargs)
    else:
        assert False, "Unknown model architecture (%s)" % model_name
    return model 
開發者ID:rwightman,項目名稱:pytorch-dpn-pretrained,代碼行數:49,代碼來源:model_factory.py


注:本文中的torchvision.models.resnet.resnet50方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。