本文整理汇总了Python中resnet.resnet50方法的典型用法代码示例。如果您正苦于以下问题:Python resnet.resnet50方法的具体用法?Python resnet.resnet50怎么用?Python resnet.resnet50使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类resnet
的用法示例。
在下文中一共展示了resnet.resnet50方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self, use_nhwc=False, pad_input=False):
super().__init__()
if use_nhwc:
rn50 = resnet50_nhwc(pretrained=True, pad_input=pad_input)
idx = 5
else:
rn50 = resnet50(pretrained=True)
idx = 6
# discard last Resnet block, avrpooling and classification FC
self.layer1 = nn.Sequential(*list(rn50.children())[:idx])
self.layer2 = nn.Sequential(*list(rn50.children())[idx:idx+1])
self.layer3 = nn.Sequential(*list(rn50.children())[idx+1:idx+2])
# modify conv4 if necessary
padding = None
# Always deal with stride in first block
modulelist = list(self.layer2.children())
_ModifyBlock(modulelist[0], bottleneck=True, stride=(1,1))
示例2: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self):
super(FPN, self).__init__()
self.relu = nn.ReLU(inplace=True)
# bottom up
self.resnet = resnet_fpn.resnet50(pretrained=True)
# top down
self.upsample = nn.Upsample(scale_factor=2, mode='nearest')
self.c5_conv = nn.Conv2d(2048, 256, (1, 1))
self.c4_conv = nn.Conv2d(1024, 256, (1, 1))
self.c3_conv = nn.Conv2d(512, 256, (1, 1))
self.c2_conv = nn.Conv2d(256, 256, (1, 1))
#self.max_pool = nn.MaxPool2d((1, 1), stride=2)
self.p5_conv = nn.Conv2d(256, 256, (3, 3), padding=1)
self.p4_conv = nn.Conv2d(256, 256, (3, 3), padding=1)
self.p3_conv = nn.Conv2d(256, 256, (3, 3), padding=1)
self.p2_conv = nn.Conv2d(256, 256, (3, 3), padding=1)
# predict heatmap
self.sigmoid = nn.Sigmoid()
self.predict = nn.Conv2d(256, 1, (3, 3), padding=1)
示例3: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self, arch='resnet50'):
super(visible_module, self).__init__()
model_v = resnet50(pretrained=True,
last_conv_stride=1, last_conv_dilation=1)
# avg pooling to global pooling
self.visible = model_v
示例4: GenModelZoo
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def GenModelZoo():
""" Specify the input shape and model initializing param """
return {
0: (torchvision.models.squeezenet1_1, [1, 3, 224, 224], [True], {}),
1: (resnet.resnet50, [1, 3, 224, 224], [True], {}),
2: (torchvision.models.densenet121, [1, 3, 224, 224], [False], {}),
3: (MobileNet, [1, 3, 224, 224], [], {}),
17: (models._netG_1, [1, 100, 1, 1], [1, 100, 3, 64, 1], {}),
18: (FaceBoxes, [1, 3, 224, 224], [], {}),
20: (UNet.UNet, [1, 3, 64, 64], [2], {}),
}
示例5: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self, pretrained=True):
"""Declare all needed layers."""
super(ResNet50, self).__init__()
self.model = resnet.resnet50(pretrained=pretrained)
self.relu = self.model.relu # Place a hook
layers_cfg = [4, 5, 6, 7]
self.blocks = []
for i, num_this_layer in enumerate(layers_cfg):
self.blocks.append(list(self.model.children())[num_this_layer])
示例6: initialize_encoder
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def initialize_encoder(model_name, num_classes, use_pretrained=True):
# Initialize these variables which will be set in this if statement. Each of these
# variables is model specific.
model_ft = None
if model_name == "resnet18":
""" Resnet18
"""
model_ft = resnet.resnet18(pretrained=use_pretrained, num_classes=1000)
num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, num_classes)
elif model_name == "resnet34":
""" Resnet34
"""
model_ft = resnet.resnet34(pretrained=use_pretrained, num_classes=1000)
num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, num_classes)
elif model_name == "resnet50":
""" Resnet50
"""
model_ft = resnet.resnet50(pretrained=use_pretrained, num_classes=1000)
num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, num_classes)
else:
print("Invalid model name, exiting...")
exit()
return model_ft
# full model
示例7: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self, pretrain=False):
super(ResDown, self).__init__()
self.features = resnet50(layer3=True, layer4=False)
if pretrain:
load_pretrain(self.features, 'resnet.model')
self.downsample = ResDownS(1024, 256)
self.layers = [self.downsample, self.features.layer2, self.features.layer3]
self.train_nums = [1, 3]
self.change_point = [0, 0.5]
self.unfix(0.0)
示例8: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self, pretrain=False):
super(ResDown, self).__init__()
self.features = resnet50(layer3=True, layer4=False)
if pretrain:
load_pretrain(self.features, 'resnet.model')
self.downsample = ResDownS(1024, 256)
self.layers = [self.downsample, self.features.layer2, self.features.layer3]
self.train_nums = [1, 3]
self.change_point = [0, 0.5]
self.unfix(0.0)
示例9: __init__
# 需要导入模块: import resnet [as 别名]
# 或者: from resnet import resnet50 [as 别名]
def __init__(self):
super(ResNetBackBone, self).__init__()
modelPreTrain50 = resnet.resnet50(pretrained=True)
self.model = modelPreTrain50