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


Python resnet.BasicBlock方法代碼示例

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


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

示例1: __init__

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

        self.stride = 128
        self.features = features

        if isinstance(features, ResNet):
            is_light = features.bottleneck == vrn.BasicBlock
            channels = [128, 256, 512] if is_light else [512, 1024, 2048]
        elif isinstance(features, MobileNet):
            channels = [32, 96, 320]

        self.lateral3 = nn.Conv2d(channels[0], 256, 1)
        self.lateral4 = nn.Conv2d(channels[1], 256, 1)
        self.lateral5 = nn.Conv2d(channels[2], 256, 1)
        self.pyramid6 = nn.Conv2d(channels[2], 256, 3, stride=2, padding=1)
        self.pyramid7 = nn.Conv2d(256, 256, 3, stride=2, padding=1)
        self.smooth3 = nn.Conv2d(256, 256, 3, padding=1)
        self.smooth4 = nn.Conv2d(256, 256, 3, padding=1)
        self.smooth5 = nn.Conv2d(256, 256, 3, padding=1) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:22,代碼來源:fpn.py

示例2: resnet18_ids

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def resnet18_ids(num_attributes, ids_embedding_size, 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)
    classifier = ResNetClassifier(BasicBlock, num_classes=num_attributes, **kwargs)
    classifier_ids = ResNetClassifier(BasicBlock, num_classes=ids_embedding_size, **kwargs)
    if pretrained:
        state_dict = model_zoo.load_url(model_urls['resnet18'])
        model.load_state_dict(
            {k: v for k, v in state_dict.items() if k in model.state_dict()}
        )

    return model, classifier, classifier_ids 
開發者ID:leokarlin,項目名稱:LaSO,代碼行數:18,代碼來源:resnet_backup.py

示例3: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def __init__(self, *args, **kw):
        self.inplanes = -1
        super(ResNetRPN, self).__init__(*args, **kw)
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(
                    m.weight, mode='fan_out', nonlinearity='relu')
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0)

        # if zero_init_residual:
        for m in self.modules():
            if isinstance(m, resnet.Bottleneck):
                nn.init.constant_(m.bn3.weight, 0)
            elif isinstance(m, resnet.BasicBlock):
                nn.init.constant_(m.bn2.weight, 0) 
開發者ID:traveller59,項目名稱:second.pytorch,代碼行數:19,代碼來源:rpn.py

示例4: _make_layer

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def _make_layer(self, inplanes, planes, num_blocks, stride=1):
        if self.inplanes == -1:
            self.inplanes = self._num_input_features
        block = resnet.BasicBlock
        downsample = None
        if stride != 1 or self.inplanes != planes * block.expansion:
            downsample = nn.Sequential(
                conv1x1(self.inplanes, planes * block.expansion, stride),
                nn.BatchNorm2d(planes * block.expansion),
            )

        layers = []
        layers.append(block(self.inplanes, planes, stride, downsample))
        self.inplanes = planes * block.expansion
        for _ in range(1, num_blocks):
            layers.append(block(self.inplanes, planes))

        return nn.Sequential(*layers), self.inplanes 
開發者ID:traveller59,項目名稱:second.pytorch,代碼行數:20,代碼來源:rpn.py

示例5: resnet18_vggmconv1

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def resnet18_vggmconv1(output_layers=None, path=None, **kwargs):
    """Constructs a ResNet-18 model with first-layer VGGm features.
    """

    if output_layers is None:
        output_layers = ['default']
    else:
        for l in output_layers:
            if l not in ['vggconv1', 'conv1', 'layer1', 'layer2', 'layer3', 'layer4', 'fc']:
                raise ValueError('Unknown layer: {}'.format(l))

    model = ResNetVGGm1(BasicBlock, [2, 2, 2, 2], output_layers, **kwargs)

    if path is not None:
        model.load_state_dict(torch.load(path), strict=False)
    return model 
開發者ID:visionml,項目名稱:pytracking,代碼行數:18,代碼來源:resnet18_vggm.py

示例6: residual_basic_block

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def residual_basic_block(feature_dim=256, num_blocks=1, l2norm=True, final_conv=False, norm_scale=1.0, out_dim=None,
                         interp_cat=False, final_relu=False, init_pool=False):
    """Construct a network block based on the BasicBlock used in ResNet 18 and 34."""
    if out_dim is None:
        out_dim = feature_dim
    feat_layers = []
    if interp_cat:
        feat_layers.append(InterpCat())
    if init_pool:
        feat_layers.append(nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
    for i in range(num_blocks):
        odim = feature_dim if i < num_blocks - 1 + int(final_conv) else out_dim
        feat_layers.append(BasicBlock(feature_dim, odim))
    if final_conv:
        feat_layers.append(nn.Conv2d(feature_dim, out_dim, kernel_size=3, padding=1, bias=False))
        if final_relu:
            feat_layers.append(nn.ReLU(inplace=True))
    if l2norm:
        feat_layers.append(InstanceL2Norm(scale=norm_scale))
    return nn.Sequential(*feat_layers) 
開發者ID:visionml,項目名稱:pytracking,代碼行數:22,代碼來源:features.py

示例7: residual_basic_block_pool

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def residual_basic_block_pool(feature_dim=256, num_blocks=1, l2norm=True, final_conv=False, norm_scale=1.0, out_dim=None,
                              pool=True):
    """Construct a network block based on the BasicBlock used in ResNet."""
    if out_dim is None:
        out_dim = feature_dim
    feat_layers = []
    for i in range(num_blocks):
        odim = feature_dim if i < num_blocks - 1 + int(final_conv) else out_dim
        feat_layers.append(BasicBlock(feature_dim, odim))
    if final_conv:
        feat_layers.append(nn.Conv2d(feature_dim, out_dim, kernel_size=3, padding=1, bias=False))
    if pool:
        feat_layers.append(nn.MaxPool2d(kernel_size=3, stride=2, padding=1))
    if l2norm:
        feat_layers.append(InstanceL2Norm(scale=norm_scale))

    return nn.Sequential(*feat_layers) 
開發者ID:visionml,項目名稱:pytracking,代碼行數:19,代碼來源:features.py

示例8: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def __init__(self):
    super().__init__(BasicBlock, [3, 4, 6, 3], 1000) 
開發者ID:Kaixhin,項目名稱:FCN-semantic-segmentation,代碼行數:4,代碼來源:model.py

示例9: resnet18

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def resnet18(**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)
  return model 
開發者ID:google,項目名稱:graph_distillation,代碼行數:9,代碼來源:get_cnn.py

示例10: ResNet18FPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def ResNet18FPN():
    return FPN(ResNet(layers=[2, 2, 2, 2], bottleneck=vrn.BasicBlock, outputs=[3, 4, 5], url=vrn.model_urls['resnet18'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例11: ResNet34FPN

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def ResNet34FPN():
    return FPN(ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.BasicBlock, outputs=[3, 4, 5], url=vrn.model_urls['resnet34'])) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:fpn.py

示例12: ResNet18C4

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def ResNet18C4():
    return ResNet(layers=[2, 2, 2, 2], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet18']) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:resnet.py

示例13: ResNet34C4

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def ResNet34C4():
    return ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet34']) 
開發者ID:NVIDIA,項目名稱:retinanet-examples,代碼行數:4,代碼來源:resnet.py

示例14: resnet18

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def resnet18(pretrained=True, **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']), strict=False)
    return model 
開發者ID:Jiaolong,項目名稱:self-supervised-da,代碼行數:11,代碼來源:resnet.py

示例15: __init__

# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import BasicBlock [as 別名]
def __init__(self, resnet_type):
	
        resnet_spec = {18: (BasicBlock, [2, 2, 2, 2], [64, 64, 128, 256, 512], 'resnet18'),
		       34: (BasicBlock, [3, 4, 6, 3], [64, 64, 128, 256, 512], 'resnet34'),
		       50: (Bottleneck, [3, 4, 6, 3], [64, 256, 512, 1024, 2048], 'resnet50'),
		       101: (Bottleneck, [3, 4, 23, 3], [64, 256, 512, 1024, 2048], 'resnet101'),
		       152: (Bottleneck, [3, 8, 36, 3], [64, 256, 512, 1024, 2048], 'resnet152')}
        block, layers, channels, name = resnet_spec[resnet_type]
        
        self.name = name
        self.inplanes = 64
        super(ResNetBackbone, self).__init__()
        self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                # nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
                nn.init.normal_(m.weight, mean=0, std=0.001)
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0) 
開發者ID:mks0601,項目名稱:3DMPPE_POSENET_RELEASE,代碼行數:31,代碼來源:resnet.py


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