Python resnet.resnet50() Examples
The following are 17
code examples of resnet.resnet50().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
resnet
, or try the search function
.
Example #1
Source File: base_model.py From training_results_v0.5 with Apache License 2.0 | 6 votes |
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))
Example #2
Source File: gazenet.py From GazeFollowing with MIT License | 6 votes |
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)
Example #3
Source File: gazenet.py From GazeFollowing with MIT License | 5 votes |
def __init__(self): super(GazeNet, self).__init__() self.face_net = M.resnet50(pretrained=True) self.face_process = nn.Sequential(nn.Linear(2048, 512), nn.ReLU(inplace=True)) self.fpn_net = FPN() self.eye_position_transform = nn.Sequential(nn.Linear(2, 256), nn.ReLU(inplace=True)) self.fusion = nn.Sequential(nn.Linear(512 + 256, 256), nn.ReLU(inplace=True), nn.Linear(256, 2)) self.relu = nn.ReLU(inplace=False) # change first conv layer for fpn_net because we concatenate # multi-scale gaze field with image image conv = [x.clone() for x in self.fpn_net.resnet.conv1.parameters()][0] new_kernel_channel = conv.data.mean(dim=1, keepdim=True).repeat(1, 3, 1, 1) new_kernel = torch.cat((conv.data, new_kernel_channel), 1) new_conv = nn.Conv2d(6, 64, kernel_size=7, stride=2, padding=3, bias=False) new_conv.weight.data = new_kernel self.fpn_net.resnet.conv1 = new_conv
Example #4
Source File: model.py From A2J with MIT License | 5 votes |
def __init__(self, num_classes, is_3D=True): super(A2J_model, self).__init__() self.is_3D = is_3D self.Backbone = ResNetBackBone() # 1 channel depth only, resnet50 self.regressionModel = RegressionModel(2048, num_classes=num_classes) self.classificationModel = ClassificationModel(1024, num_classes=num_classes) if is_3D: self.DepthRegressionModel = DepthRegressionModel(2048, num_classes=num_classes)
Example #5
Source File: model.py From A2J with MIT License | 5 votes |
def __init__(self): super(ResNetBackBone, self).__init__() modelPreTrain50 = resnet.resnet50(pretrained=True) self.model = modelPreTrain50
Example #6
Source File: model.py From A2J with MIT License | 5 votes |
def __init__(self, num_classes, is_3D=True): super(A2J_model, self).__init__() self.is_3D = is_3D self.Backbone = ResNetBackBone() # 1 channel depth only, resnet50 self.regressionModel = RegressionModel(2048, num_classes=num_classes) self.classificationModel = ClassificationModel(1024, num_classes=num_classes) if is_3D: self.DepthRegressionModel = DepthRegressionModel(2048, num_classes=num_classes)
Example #7
Source File: model.py From A2J with MIT License | 5 votes |
def __init__(self): super(ResNetBackBone, self).__init__() modelPreTrain50 = resnet.resnet50(pretrained=True) self.model = modelPreTrain50
Example #8
Source File: custom.py From SiamMask with MIT License | 5 votes |
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)
Example #9
Source File: custom.py From SiamMask with MIT License | 5 votes |
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)
Example #10
Source File: custom.py From SiamMask with MIT License | 5 votes |
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)
Example #11
Source File: model.py From Silhouette-Guided-3D with MIT License | 5 votes |
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
Example #12
Source File: model.py From Cross-Modal-Re-ID-baseline with MIT License | 5 votes |
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
Example #13
Source File: networks.py From Pyramid-Attention-Networks-pytorch with GNU General Public License v3.0 | 5 votes |
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])
Example #14
Source File: run.py From PytorchConverter with BSD 2-Clause "Simplified" License | 5 votes |
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], {}), }
Example #15
Source File: model.py From Cross-Modal-Re-ID-baseline with MIT License | 5 votes |
def __init__(self, class_num, no_local= 'on', gm_pool = 'on', arch='resnet50'): super(embed_net, self).__init__() self.thermal_module = thermal_module(arch=arch) self.visible_module = visible_module(arch=arch) self.base_resnet = base_resnet(arch=arch) self.non_local = no_local if self.non_local =='on': layers=[3, 4, 6, 3] non_layers=[0,2,3,0] self.NL_1 = nn.ModuleList( [Non_local(256) for i in range(non_layers[0])]) self.NL_1_idx = sorted([layers[0] - (i + 1) for i in range(non_layers[0])]) self.NL_2 = nn.ModuleList( [Non_local(512) for i in range(non_layers[1])]) self.NL_2_idx = sorted([layers[1] - (i + 1) for i in range(non_layers[1])]) self.NL_3 = nn.ModuleList( [Non_local(1024) for i in range(non_layers[2])]) self.NL_3_idx = sorted([layers[2] - (i + 1) for i in range(non_layers[2])]) self.NL_4 = nn.ModuleList( [Non_local(2048) for i in range(non_layers[3])]) self.NL_4_idx = sorted([layers[3] - (i + 1) for i in range(non_layers[3])]) pool_dim = 2048 self.l2norm = Normalize(2) self.bottleneck = nn.BatchNorm1d(pool_dim) self.bottleneck.bias.requires_grad_(False) # no shift self.classifier = nn.Linear(pool_dim, class_num, bias=False) self.bottleneck.apply(weights_init_kaiming) self.classifier.apply(weights_init_classifier) self.avgpool = nn.AdaptiveAvgPool2d((1, 1)) self.gm_pool = gm_pool
Example #16
Source File: model.py From Cross-Modal-Re-ID-baseline with MIT License | 5 votes |
def __init__(self, arch='resnet50'): super(base_resnet, self).__init__() model_base = resnet50(pretrained=True, last_conv_stride=1, last_conv_dilation=1) # avg pooling to global pooling model_base.avgpool = nn.AdaptiveAvgPool2d((1, 1)) self.base = model_base
Example #17
Source File: model.py From Cross-Modal-Re-ID-baseline with MIT License | 5 votes |
def __init__(self, arch='resnet50'): super(thermal_module, self).__init__() model_t = resnet50(pretrained=True, last_conv_stride=1, last_conv_dilation=1) # avg pooling to global pooling self.thermal = model_t