本文整理汇总了Python中torchvision.models.resnet101方法的典型用法代码示例。如果您正苦于以下问题:Python models.resnet101方法的具体用法?Python models.resnet101怎么用?Python models.resnet101使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchvision.models
的用法示例。
在下文中一共展示了models.resnet101方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, base_model=resnet101, num_templates=1, num_objects=1):
super().__init__()
# 4 is for the bounding box offsets
output = (num_objects + 4)*num_templates
self.model = base_model(pretrained=True)
# delete unneeded layer
del self.model.layer4
self.score_res3 = nn.Conv2d(in_channels=512, out_channels=output,
kernel_size=1, padding=0)
self.score_res4 = nn.Conv2d(in_channels=1024, out_channels=output,
kernel_size=1, padding=0)
self.score4_upsample = nn.ConvTranspose2d(in_channels=output, out_channels=output,
kernel_size=4, stride=2, padding=1, bias=False)
self._init_bilinear()
示例2: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, num_class=1, sizes=(1, 2, 3, 6), base_network='resnet101'):
super(PSPNet, self).__init__()
base_network = base_network.lower()
if base_network == 'resnet101':
self.base_network = ResNet101Extractor()
feature_dim = 1024
elif base_network == 'squeezenet':
self.base_network = SqueezeNetExtractor()
feature_dim = 512
else:
raise ValueError
self.psp = PyramidPoolingModule(in_channels=feature_dim, sizes=sizes)
self.drop_1 = nn.Dropout2d(p=0.3)
self.up_1 = UpsampleLayer(2*feature_dim, 256)
self.up_2 = UpsampleLayer(256, 64)
self.up_3 = UpsampleLayer(64, 64)
self.drop_2 = nn.Dropout2d(p=0.15)
self.final = nn.Sequential(
nn.Conv2d(64, num_class, kernel_size=1)
)
self._init_weight()
示例3: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, num_layers, pretrained, num_input_images=1):
super(ResnetEncoder, self).__init__()
self.num_ch_enc = np.array([64, 64, 128, 256, 512])
resnets = {18: models.resnet18,
34: models.resnet34,
50: models.resnet50,
101: models.resnet101,
152: models.resnet152}
if num_layers not in resnets:
raise ValueError("{} is not a valid number of resnet layers".format(num_layers))
if num_input_images > 1:
self.encoder = resnet_multiimage_input(num_layers, pretrained, num_input_images)
else:
self.encoder = resnets[num_layers](pretrained)
if num_layers > 34:
self.num_ch_enc[1:] *= 4
示例4: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, model_type='resnet50', layer_type='layer4'):
super().__init__()
# get model
if model_type == 'resnet50':
original_model = models.resnet50(pretrained=True)
elif model_type == 'resnet101':
original_model = models.resnet101(pretrained=True)
else:
raise NameError('Unknown model_type passed')
# get requisite layer
if layer_type == 'layer2':
num_layers = 6
pool_size = 28
elif layer_type == 'layer3':
num_layers = 7
pool_size = 14
elif layer_type == 'layer4':
num_layers = 8
pool_size = 7
else:
raise NameError('Uknown layer_type passed')
self.features = nn.Sequential(*list(original_model.children())[:num_layers])
self.avgpool = nn.AvgPool2d(pool_size, stride=1)
示例5: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self,option = 'resnet18',pret=True):
super(ResBase, self).__init__()
self.dim = 2048
if option == 'resnet18':
model_ft = models.resnet18(pretrained=pret)
self.dim = 512
if option == 'resnet50':
model_ft = models.resnet50(pretrained=pret)
if option == 'resnet101':
model_ft = models.resnet101(pretrained=pret)
if option == 'resnet152':
model_ft = models.resnet152(pretrained=pret)
if option == 'resnet200':
model_ft = Res200()
if option == 'resnetnext':
model_ft = ResNeXt(layer_num=101)
mod = list(model_ft.children())
mod.pop()
#self.model_ft =model_ft
self.features = nn.Sequential(*mod)
示例6: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
super(resnet, self).__init__()
if(num==18):
self.net = tv.resnet18(pretrained=pretrained)
elif(num==34):
self.net = tv.resnet34(pretrained=pretrained)
elif(num==50):
self.net = tv.resnet50(pretrained=pretrained)
elif(num==101):
self.net = tv.resnet101(pretrained=pretrained)
elif(num==152):
self.net = tv.resnet152(pretrained=pretrained)
self.N_slices = 5
self.conv1 = self.net.conv1
self.bn1 = self.net.bn1
self.relu = self.net.relu
self.maxpool = self.net.maxpool
self.layer1 = self.net.layer1
self.layer2 = self.net.layer2
self.layer3 = self.net.layer3
self.layer4 = self.net.layer4
示例7: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
super(resnet, self).__init__()
if(num==18):
self.net = models.resnet18(pretrained=pretrained)
elif(num==34):
self.net = models.resnet34(pretrained=pretrained)
elif(num==50):
self.net = models.resnet50(pretrained=pretrained)
elif(num==101):
self.net = models.resnet101(pretrained=pretrained)
elif(num==152):
self.net = models.resnet152(pretrained=pretrained)
self.N_slices = 5
self.conv1 = self.net.conv1
self.bn1 = self.net.bn1
self.relu = self.net.relu
self.maxpool = self.net.maxpool
self.layer1 = self.net.layer1
self.layer2 = self.net.layer2
self.layer3 = self.net.layer3
self.layer4 = self.net.layer4
示例8: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, requires_grad=False, pretrained=True, num=18):
super(resnet, self).__init__()
if (num == 18):
self.net = models.resnet18(pretrained=pretrained)
elif (num == 34):
self.net = models.resnet34(pretrained=pretrained)
elif (num == 50):
self.net = models.resnet50(pretrained=pretrained)
elif (num == 101):
self.net = models.resnet101(pretrained=pretrained)
elif (num == 152):
self.net = models.resnet152(pretrained=pretrained)
self.N_slices = 5
self.conv1 = self.net.conv1
self.bn1 = self.net.bn1
self.relu = self.net.relu
self.maxpool = self.net.maxpool
self.layer1 = self.net.layer1
self.layer2 = self.net.layer2
self.layer3 = self.net.layer3
self.layer4 = self.net.layer4
示例9: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, layers, atrous, pretrained=True):
super(ResNet, self).__init__()
self.inner_layer = []
if layers == 18:
self.backbone = models.resnet18(pretrained=pretrained)
elif layers == 34:
self.backbone = models.resnet34(pretrained=pretrained)
elif layers == 50:
self.backbone = models.resnet50(pretrained=pretrained)
elif layers == 101:
self.backbone = models.resnet101(pretrained=pretrained)
elif layers == 152:
self.backbone = models.resnet152(pretrained=pretrained)
else:
raise ValueError('resnet.py: network layers is no support yet')
def hook_func(module, input, output):
self.inner_layer.append(output)
self.backbone.layer1.register_forward_hook(hook_func)
self.backbone.layer2.register_forward_hook(hook_func)
self.backbone.layer3.register_forward_hook(hook_func)
self.backbone.layer4.register_forward_hook(hook_func)
示例10: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, pretrained=True):
super(Res101_SFCN, self).__init__()
self.seen = 0
self.backend_feat = [512, 512, 512,256,128,64]
self.frontend = []
self.backend = make_layers(self.backend_feat,in_channels = 1024,dilation = True)
self.convDU = convDU(in_out_channels=64,kernel_size=(1,9))
self.convLR = convLR(in_out_channels=64,kernel_size=(9,1))
self.output_layer = nn.Sequential(nn.Conv2d(64, 1, kernel_size=1),nn.ReLU())
initialize_weights(self.modules())
res = models.resnet101(pretrained=pretrained)
self.frontend = nn.Sequential(
res.conv1, res.bn1, res.relu, res.maxpool, res.layer1, res.layer2
)
self.own_reslayer_3 = make_res_layer(Bottleneck, 256, 23, stride=1)
self.own_reslayer_3.load_state_dict(res.layer3.state_dict())
示例11: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, ):
super(resSFCN, self).__init__()
self.seen = 0
self.backend_feat = [512, 512, 512,256,128,64]
self.frontend = []
self.backend = make_layers(self.backend_feat,in_channels = 1024,dilation = True)
self.convDU = convDU(in_out_channels=64,kernel_size=(1,9))
self.convLR = convLR(in_out_channels=64,kernel_size=(9,1))
self.output_layer = nn.Sequential(nn.Conv2d(64, 1, kernel_size=1),nn.ReLU())
self._initialize_weights()
res = models.resnet101()
pre_wts = torch.load(model_path)
res.load_state_dict(pre_wts)
self.frontend = nn.Sequential(
res.conv1, res.bn1, res.relu, res.maxpool, res.layer1, res.layer2
)
self.own_reslayer_3 = make_res_layer(Bottleneck, 256, 23, stride=1)
self.own_reslayer_3.load_state_dict(res.layer3.state_dict())
示例12: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self):
super(ResNet101Fc, self).__init__()
model_resnet101 = models.resnet101(pretrained=True)
self.conv1 = model_resnet101.conv1
self.bn1 = model_resnet101.bn1
self.relu = model_resnet101.relu
self.maxpool = model_resnet101.maxpool
self.layer1 = model_resnet101.layer1
self.layer2 = model_resnet101.layer2
self.layer3 = model_resnet101.layer3
self.layer4 = model_resnet101.layer4
self.avgpool = model_resnet101.avgpool
self.__in_features = model_resnet101.fc.in_features
示例13: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self):
super(ResNet101Fc, self).__init__()
model_resnet101 = models.resnet101(pretrained=True)
self.conv1 = model_resnet101.conv1
self.bn1 = model_resnet101.bn1
self.relu = model_resnet101.relu
self.maxpool = model_resnet101.maxpool
self.layer1 = model_resnet101.layer1
self.layer2 = model_resnet101.layer2
self.layer3 = model_resnet101.layer3
self.layer4 = model_resnet101.layer4
self.avgpool = model_resnet101.avgpool
示例14: Resnet101
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def Resnet101(config):
return models.resnet101(pretrained=True)
示例15: __init__
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def __init__(self, num_classes):
super().__init__()
resnet = models.resnet101(pretrained=True)
self.conv1 = resnet.conv1
self.layer1 = resnet.layer1
self.layer2 = resnet.layer2
self.layer3 = resnet.layer3
self.layer4 = resnet.layer4
for m in self.modules():
if isinstance(m, nn.Conv2d):
m.stride = 1
m.requires_grad = False
if isinstance(m, nn.BatchNorm2d):
m.requires_grad = False
self.layer5a = PSPDec(2048, 512, 60)
self.layer5b = PSPDec(2048, 512, 30)
self.layer5c = PSPDec(2048, 512, 20)
self.layer5d = PSPDec(2048, 512, 10)
self.final = nn.Sequential(
nn.Conv2d(2048, 512, 3, padding=1, bias=False),
nn.BatchNorm2d(512, momentum=.95),
nn.ReLU(inplace=True),
nn.Dropout(.1),
nn.Conv2d(512, num_classes, 1),
)