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


Python model_zoo.load_url方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def __init__(self):
        super(Model2, self).__init__()

        # fine tuning the ResNet helped significantly with the accuracy
        base_model = MyResNet(BasicBlock, [2, 2, 2, 2])
        base_model.load_state_dict(model_zoo.load_url(model_urls['resnet18']))
        # code needed to deactivate fine tuning of resnet
        #for param in base_model.parameters():
        #    param.requires_grad = False
        self.base_model = base_model
        self.drop0 = nn.Dropout2d(0.05)

        self.conv1 = nn.Conv2d(512, 256, 3, padding=1, bias=False)
        self.bn1 = nn.BatchNorm2d(256)
        self.drop1 = nn.Dropout2d(0.05)

        self.conv2 = nn.Conv2d(256, 128, 3, padding=1, bias=False)
        self.bn2 = nn.BatchNorm2d(128)
        self.drop2 = nn.Dropout2d(0.05)

        self.conv3 = nn.Conv2d(128, 1+9, 3, padding=1, bias=False) 
開發者ID:aleju,項目名稱:cat-bbs,代碼行數:23,代碼來源:model.py

示例2: __init__

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def __init__(self, base_model: torch.nn.Module, num_classes: int, weights_url: str = None):
        super().__init__()
        if not hasattr(self, 'decoder_block'):
            self.decoder_block = UnetDecoderBlock
        if not hasattr(self, 'bottleneck_type'):
            self.bottleneck_type = ConvBottleneck

        if weights_url is not None:
            print("Model weights inited by url")

            pretrained_weights = model_zoo.load_url(weights_url)
            model_state_dict = base_model.state_dict()
            pretrained_weights = {k: v for k, v in pretrained_weights.items() if k in model_state_dict}
            base_model.load_state_dict(pretrained_weights)

        filters = [64, 64, 128, 256, 512]

        self.bottlenecks = nn.ModuleList([self.bottleneck_type(f * 2, f) for f in reversed(filters[:-1])])
        self.decoder_stages = nn.ModuleList([self.get_decoder(filters, idx) for idx in range(1, len(filters))])

        self.encoder_stages = nn.ModuleList([self.get_encoder(base_model, idx) for idx in range(len(filters))])

        self.last_upsample = self.decoder_block(filters[0], filters[0])
        self.final = self.make_final_classifier(filters[0], num_classes) 
開發者ID:toodef,項目名稱:neural-pipeline,代碼行數:26,代碼來源:albunet.py

示例3: densenet121

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def densenet121(pretrained=False, **kwargs):
    r"""Densenet-121 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = DenseNet(num_init_features=64, growth_rate=32, block_config=(6, 12, 24, 16),
                     **kwargs)
    if pretrained:
        # '.'s are no longer allowed in module names, but pervious _DenseLayer
        # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
        # They are also in the checkpoints in model_urls. This pattern is used
        # to find such keys.
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = model_zoo.load_url(model_urls['densenet121'])
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        model.load_state_dict(state_dict)
    return model 
開發者ID:jiangtaoxie,項目名稱:fast-MPN-COV,代碼行數:27,代碼來源:densenet.py

示例4: densenet169

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def densenet169(pretrained=False, **kwargs):
    r"""Densenet-169 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = DenseNet(num_init_features=64, growth_rate=32, block_config=(6, 12, 32, 32),
                     **kwargs)
    if pretrained:
        # '.'s are no longer allowed in module names, but pervious _DenseLayer
        # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
        # They are also in the checkpoints in model_urls. This pattern is used
        # to find such keys.
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = model_zoo.load_url(model_urls['densenet169'])
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        model.load_state_dict(state_dict)
    return model 
開發者ID:jiangtaoxie,項目名稱:fast-MPN-COV,代碼行數:27,代碼來源:densenet.py

示例5: densenet201

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def densenet201(pretrained=False, **kwargs):
    r"""Densenet-201 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = DenseNet(num_init_features=64, growth_rate=32, block_config=(6, 12, 48, 32),
                     **kwargs)
    if pretrained:
        # '.'s are no longer allowed in module names, but pervious _DenseLayer
        # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
        # They are also in the checkpoints in model_urls. This pattern is used
        # to find such keys.
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = model_zoo.load_url(model_urls['densenet201'])
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        model.load_state_dict(state_dict)
    return model 
開發者ID:jiangtaoxie,項目名稱:fast-MPN-COV,代碼行數:27,代碼來源:densenet.py

示例6: densenet161

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def densenet161(pretrained=False, **kwargs):
    r"""Densenet-161 model from
    `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = DenseNet(num_init_features=96, growth_rate=48, block_config=(6, 12, 36, 24),
                     **kwargs)
    if pretrained:
        # '.'s are no longer allowed in module names, but pervious _DenseLayer
        # has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
        # They are also in the checkpoints in model_urls. This pattern is used
        # to find such keys.
        pattern = re.compile(
            r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
        state_dict = model_zoo.load_url(model_urls['densenet161'])
        for key in list(state_dict.keys()):
            res = pattern.match(key)
            if res:
                new_key = res.group(1) + res.group(2)
                state_dict[new_key] = state_dict[key]
                del state_dict[key]
        model.load_state_dict(state_dict)
    return model 
開發者ID:jiangtaoxie,項目名稱:fast-MPN-COV,代碼行數:27,代碼來源:densenet.py

示例7: resnet18

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet18(pretrained=False):
  """Constructs a ResNet-18 model.
  Args:
    pretrained (bool): If True, returns a model pre-trained on ImageNet
  """
  model = ResNet(BasicBlock, [2, 2, 2, 2])
  if pretrained:
    model.load_state_dict(model_zoo.load_url(model_urls['resnet18']))
  return model 
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:11,代碼來源:resnet_v1.py

示例8: resnet34

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet34(pretrained=False):
  """Constructs a ResNet-34 model.
  Args:
    pretrained (bool): If True, returns a model pre-trained on ImageNet
  """
  model = ResNet(BasicBlock, [3, 4, 6, 3])
  if pretrained:
    model.load_state_dict(model_zoo.load_url(model_urls['resnet34']))
  return model 
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:11,代碼來源:resnet_v1.py

示例9: resnet50

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet50(pretrained=False):
  """Constructs a ResNet-50 model.
  Args:
    pretrained (bool): If True, returns a model pre-trained on ImageNet
  """
  model = ResNet(Bottleneck, [3, 4, 6, 3])
  if pretrained:
    model.load_state_dict(model_zoo.load_url(model_urls['resnet50']))
  return model 
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:11,代碼來源:resnet_v1.py

示例10: resnet101

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet101(pretrained=False):
  """Constructs a ResNet-101 model.
  Args:
    pretrained (bool): If True, returns a model pre-trained on ImageNet
  """
  model = ResNet(Bottleneck, [3, 4, 23, 3])
  if pretrained:
    model.load_state_dict(model_zoo.load_url(model_urls['resnet101']))
  return model 
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:11,代碼來源:resnet_v1.py

示例11: resnet152

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet152(pretrained=False):
  """Constructs a ResNet-152 model.
  Args:
    pretrained (bool): If True, returns a model pre-trained on ImageNet
  """
  model = ResNet(Bottleneck, [3, 8, 36, 3])
  if pretrained:
    model.load_state_dict(model_zoo.load_url(model_urls['resnet152']))
  return model 
開發者ID:Sunarker,項目名稱:Collaborative-Learning-for-Weakly-Supervised-Object-Detection,代碼行數:11,代碼來源:resnet_v1.py

示例12: _load_pretrained_model

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def _load_pretrained_model(self):
        pretrain_dict = model_zoo.load_url('https://download.pytorch.org/models/resnet101-5d3b4d8f.pth')
        model_dict = {}
        state_dict = self.state_dict()
        for k, v in pretrain_dict.items():
            if k in state_dict:
                model_dict[k] = v
        state_dict.update(model_dict)
        self.load_state_dict(state_dict) 
開發者ID:songdejia,項目名稱:DeepLab_v3_plus,代碼行數:11,代碼來源:deeplab.py

示例13: resnet18

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet18(pretrained=False, **kwargs):
    """Constructs a ResNet-18 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(BasicBlock, [2, 2, 2, 2], **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['resnet18']))
    return model 
開發者ID:kibok90,項目名稱:cvpr2018-hnd,代碼行數:12,代碼來源:cnns.py

示例14: resnet34

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet34(pretrained=False, **kwargs):
    """Constructs a ResNet-34 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(BasicBlock, [3, 4, 6, 3], **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['resnet34']))
    return model 
開發者ID:kibok90,項目名稱:cvpr2018-hnd,代碼行數:12,代碼來源:cnns.py

示例15: resnet50

# 需要導入模塊: from torch.utils import model_zoo [as 別名]
# 或者: from torch.utils.model_zoo import load_url [as 別名]
def resnet50(pretrained=False, **kwargs):
    """Constructs a ResNet-50 model.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
    """
    model = ResNet(Bottleneck, [3, 4, 6, 3], **kwargs)
    if pretrained:
        model.load_state_dict(model_zoo.load_url(model_urls['resnet50']))
    return model 
開發者ID:kibok90,項目名稱:cvpr2018-hnd,代碼行數:12,代碼來源:cnns.py


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