本文整理匯總了Python中torchvision.models.resnet.__dict__方法的典型用法代碼示例。如果您正苦於以下問題:Python resnet.__dict__方法的具體用法?Python resnet.__dict__怎麽用?Python resnet.__dict__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類torchvision.models.resnet
的用法示例。
在下文中一共展示了resnet.__dict__方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import __dict__ [as 別名]
def __init__(self, model, context_size, context_transform=None, context_nonlinearity=None, spatial_context=True, finetune=True):
super(CNNEncoderBase, self).__init__()
self.model = model
self.finetune = finetune
self.batch_first = True
self.toggle_grad()
self.spatial_context = spatial_context
if context_transform is None:
self.context_size = context_size
else:
if self.spatial_context:
self.context_transform = nn.Conv2d(
context_size, context_transform, 1)
else:
self.context_transform = nn.Linear(
context_size, context_transform)
if context_nonlinearity is not None:
self.context_nonlinearity = F.__dict__[context_nonlinearity]
self.context_size = context_transform
開發者ID:nadavbh12,項目名稱:Character-Level-Language-Modeling-with-Deeper-Self-Attention-pytorch,代碼行數:21,代碼來源:vision_encoders.py
示例2: resnet_fpn_backbone
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import __dict__ [as 別名]
def resnet_fpn_backbone(backbone_name, pretrained):
backbone = resnet.__dict__[backbone_name](
pretrained=pretrained,
norm_layer=misc_nn_ops.FrozenBatchNorm2d)
# freeze layers
for name, parameter in backbone.named_parameters():
if 'layer2' not in name and 'layer3' not in name and 'layer4' not in name:
parameter.requires_grad_(False)
return_layers = {'layer1': 0, 'layer2': 1, 'layer3': 2, 'layer4': 3}
in_channels_stage2 = backbone.inplanes // 8
in_channels_list = [
in_channels_stage2,
in_channels_stage2 * 2,
in_channels_stage2 * 4,
in_channels_stage2 * 8,
]
out_channels = 256
return BackboneWithFPN(backbone, return_layers, in_channels_list, out_channels)
示例3: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import __dict__ [as 別名]
def __init__(self, pretrained=False):
super(DepthCompletionNet, self).__init__()
print ("model_mcdropout.py")
self.layers = 34
self.pretrained = pretrained
self.conv1_d = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)
self.conv1_img = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)
pretrained_model = resnet.__dict__['resnet{}'.format(self.layers)](pretrained=self.pretrained)
if not self.pretrained:
pretrained_model.apply(init_weights)
self.conv2 = pretrained_model._modules['layer1']
self.conv3 = pretrained_model._modules['layer2']
self.conv4 = pretrained_model._modules['layer3']
self.conv5 = pretrained_model._modules['layer4']
del pretrained_model # (clear memory)
if self.layers <= 34:
num_channels = 512
elif self.layers >= 50:
num_channels = 2048
self.conv6 = conv_bn_relu(num_channels, 512, kernel_size=3, stride=2, padding=1)
self.convt5 = convt_bn_relu(in_channels=512, out_channels=256, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt4 = convt_bn_relu(in_channels=768, out_channels=128, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt3 = convt_bn_relu(in_channels=(256+128), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt2 = convt_bn_relu(in_channels=(128+64), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt1 = convt_bn_relu(in_channels=128, out_channels=64, kernel_size=3, stride=1, padding=1)
self.convtf_mean = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)
self.convtf_var = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)
示例4: __init__
# 需要導入模塊: from torchvision.models import resnet [as 別名]
# 或者: from torchvision.models.resnet import __dict__ [as 別名]
def __init__(self, pretrained=False):
super(DepthCompletionNet, self).__init__()
print ("model.py")
self.layers = 34
self.pretrained = pretrained
self.conv1_d = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)
self.conv1_img = conv_bn_relu(1, 32, kernel_size=3, stride=1, padding=1)
pretrained_model = resnet.__dict__['resnet{}'.format(self.layers)](pretrained=self.pretrained)
if not self.pretrained:
pretrained_model.apply(init_weights)
self.conv2 = pretrained_model._modules['layer1']
self.conv3 = pretrained_model._modules['layer2']
self.conv4 = pretrained_model._modules['layer3']
self.conv5 = pretrained_model._modules['layer4']
del pretrained_model # (clear memory)
if self.layers <= 34:
num_channels = 512
elif self.layers >= 50:
num_channels = 2048
self.conv6 = conv_bn_relu(num_channels, 512, kernel_size=3, stride=2, padding=1)
self.convt5 = convt_bn_relu(in_channels=512, out_channels=256, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt4 = convt_bn_relu(in_channels=768, out_channels=128, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt3 = convt_bn_relu(in_channels=(256+128), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt2 = convt_bn_relu(in_channels=(128+64), out_channels=64, kernel_size=3, stride=2, padding=1, output_padding=1)
self.convt1 = convt_bn_relu(in_channels=128, out_channels=64, kernel_size=3, stride=1, padding=1)
self.convtf_mean = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)
self.convtf_var = conv_bn_relu(in_channels=128, out_channels=1, kernel_size=1, stride=1, bn=False, relu=False)