Python torchvision.models.resnet152() Examples
The following are 30
code examples of torchvision.models.resnet152().
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
torchvision.models
, or try the search function
.
Example #1
Source File: imsitu_model.py From verb-attributes with MIT License | 9 votes |
def get_pretrained_resnet(new_fc_dim=None): """ Fetches a pretrained resnet model (downloading if necessary) and chops off the top linear layer. If new_fc_dim isn't None, then a new linear layer is added. :param new_fc_dim: :return: """ resnet152 = models.resnet152(pretrained=True) del resnet152.fc if new_fc_dim is not None: resnet152.fc = nn.Linear(ENCODING_SIZE, new_fc_dim) _init_fc(resnet152.fc) else: resnet152.fc = lambda x: x return resnet152
Example #2
Source File: resnet_encoder.py From packnet-sfm with MIT License | 8 votes |
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
Example #3
Source File: test_attack_Gaussian_blur.py From perceptron-benchmark with Apache License 2.0 | 7 votes |
def test_untargeted_resnet152(image, label=None): import torch import torchvision.models as models from perceptron.models.classification import PyTorchModel mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) model_pyt = models.resnet152(pretrained=True).eval() if torch.cuda.is_available(): model_pyt = model_pyt.cuda() model = PyTorchModel( model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) print(np.argmax(model.predictions(image))) attack = Attack(model, criterion=Misclassification()) adversarial_obj = attack(image, label, unpack=False, epsilons=10000) distance = adversarial_obj.distance adversarial = adversarial_obj.image return distance, adversarial
Example #4
Source File: basenet.py From MCD_DA with MIT License | 6 votes |
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)
Example #5
Source File: basenet.py From MCD_DA with MIT License | 6 votes |
def __init__(self,option = 'resnet18',pret=True): super(ResFreeze, self).__init__() self.dim = 2048*2*2 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() self.conv1 = model_ft.conv1 self.bn0 = model_ft.bn1 self.relu = model_ft.relu self.maxpool = model_ft.maxpool self.layer1 = model_ft.layer1 self.layer2 = model_ft.layer2 self.layer3 = model_ft.layer3 self.layer4 = model_ft.layer4 self.avgpool = model_ft.avgpool
Example #6
Source File: model.py From video_feature_extractor with Apache License 2.0 | 6 votes |
def get_model(args): assert args.type in ['2d', '3d'] if args.type == '2d': print('Loading 2D-ResNet-152 ...') model = models.resnet152(pretrained=True) model = nn.Sequential(*list(model.children())[:-2], GlobalAvgPool()) model = model.cuda() else: print('Loading 3D-ResneXt-101 ...') model = resnext.resnet101( num_classes=400, shortcut_type='B', cardinality=32, sample_size=112, sample_duration=16, last_fc=False) model = model.cuda() model_data = th.load(args.resnext101_model_path) model.load_state_dict(model_data) model.eval() print('loaded') return model
Example #7
Source File: resnet_encoder.py From DF-VO with MIT License | 6 votes |
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
Example #8
Source File: pretrained_networks.py From PerceptualSimilarity with BSD 2-Clause "Simplified" License | 6 votes |
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
Example #9
Source File: pretrained_networks.py From TecoGAN with Apache License 2.0 | 6 votes |
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
Example #10
Source File: test_attack_MotionBlurAttack.py From perceptron-benchmark with Apache License 2.0 | 6 votes |
def test_untargeted_resnet152(image, label=None): import torch import torchvision.models as models from perceptron.models.classification import PyTorchModel mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) model_pyt = models.resnet152(pretrained=True).eval() if torch.cuda.is_available(): model_pyt = model_pyt.cuda() model = PyTorchModel( model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) print(np.argmax(model.predictions(image))) attack = Attack(model, criterion=Misclassification()) adversarial_obj = attack(image, label, unpack=False, epsilons=10000) distance = adversarial_obj.distance adversarial = adversarial_obj.image return distance, adversarial
Example #11
Source File: test_attack_BlendedUniformNoiseAttack.py From perceptron-benchmark with Apache License 2.0 | 6 votes |
def test_untargeted_resnet152(image, label=None): import torch import torchvision.models as models from perceptron.models.classification import PyTorchModel mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) model_pyt = models.resnet152(pretrained=True).eval() if torch.cuda.is_available(): model_pyt = model_pyt.cuda() model = PyTorchModel( model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) print(np.argmax(model.predictions(image))) attack = Attack(model, criterion=Misclassification()) adversarial_obj = attack(image, label, unpack=False, epsilons=10000) distance = adversarial_obj.distance adversarial = adversarial_obj.image return distance, adversarial
Example #12
Source File: test_attack_AdditiveUniformNoiseAttack.py From perceptron-benchmark with Apache License 2.0 | 6 votes |
def test_untargeted_resnet152(image, label=None): import torch import torchvision.models as models from perceptron.models.classification import PyTorchModel mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) model_pyt = models.resnet152(pretrained=True).eval() if torch.cuda.is_available(): model_pyt = model_pyt.cuda() model = PyTorchModel( model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) print(np.argmax(model.predictions(image))) attack = Attack(model, criterion=Misclassification()) adversarial_obj = attack(image, label, unpack=False, epsilons=10000) distance = adversarial_obj.distance adversarial = adversarial_obj.image return distance, adversarial
Example #13
Source File: test_attack_AdditiveGaussianNoiseAttack.py From perceptron-benchmark with Apache License 2.0 | 6 votes |
def test_untargeted_resnet152(image, label=None): import torch import torchvision.models as models from perceptron.models.classification import PyTorchModel mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1)) std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1)) model_pyt = models.resnet152(pretrained=True).eval() if torch.cuda.is_available(): model_pyt = model_pyt.cuda() model = PyTorchModel( model_pyt, bounds=(0, 1), num_classes=1000, preprocessing=(mean, std)) print(np.argmax(model.predictions(image))) attack = Attack(model, criterion=Misclassification()) adversarial_obj = attack(image, label, unpack=False, epsilons=10000) distance = adversarial_obj.distance adversarial = adversarial_obj.image return distance, adversarial
Example #14
Source File: pretrained_networks.py From SMIT with MIT License | 6 votes |
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
Example #15
Source File: resnet_encoder.py From SC-SfMLearner-Release with GNU General Public License v3.0 | 6 votes |
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
Example #16
Source File: resnet.py From deeplabv3plus-pytorch with MIT License | 6 votes |
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)
Example #17
Source File: weldonModel.py From dsve-loc with BSD 3-Clause Clear License | 6 votes |
def __init__(self, args, pretrained=True, weldon_pretrained_path=None): super(ResNet_weldon, self).__init__() resnet = models.resnet152(pretrained=pretrained) self.base_layer = nn.Sequential(*list(resnet.children())[:-2]) self.spaConv = nn.Conv2d(2048, 2400, 1,) # add spatial aggregation layer self.wldPool = WeldonPooling(15) # Linear layer for imagenet classification self.fc = nn.Linear(2400, 1000) # Loading pretrained weights of resnet weldon on imagenet classification if pretrained: try: state_di = torch.load( weldon_pretrained_path, map_location=lambda storage, loc: storage)['state_dict'] self.load_state_dict(state_di) except Exception: print("Error when loading pretrained resnet weldon")
Example #18
Source File: ResNet.py From XueLangTianchi with MIT License | 6 votes |
def __init__(self): super(ResNet152_bo,self).__init__() # 设置网络名称,保存模型时命名使用 self.moduel_name=str("ResNet152_bo") # 加载预训练好的网络权重 model = resnet152(pretrained=True) # 固定权重 nn.Module有成员函数parameters() if opt.fixed_weight: for param in model.parameters(): param.requires_grad = False # 结论:self.model_bo只有修改过的新层(即最后两层全连接层)的值为True # 替换最后一层全连接层 # 新层默认requires_grad=True # resnet152中有self.fc,作为前向过程的最后一层 # (修改输入图像大小,可通过报错信息来调整下面参数) model.fc = nn.Linear(2048, 2) #420:131072 224:2048 # 此时self.model_bo的权重为预训练权重,修改的新层(全连接层)权重为自动初始化的 self.model_bo=model #手动初始化fc层 self._initialize_weights()
Example #19
Source File: encoder.py From pytorch-segmentation with MIT License | 5 votes |
def resnet(name, pretrained=False): def get_channels(layer): block = layer[-1] if isinstance(block, models.resnet.BasicBlock): return block.conv2.out_channels elif isinstance(block, models.resnet.Bottleneck): return block.conv3.out_channels raise RuntimeError("unknown resnet block: {}".format(block)) if name == 'resnet18': resnet = models.resnet18(pretrained=pretrained) elif name == 'resnet34': resnet = models.resnet34(pretrained=pretrained) elif name == 'resnet50': resnet = models.resnet50(pretrained=pretrained) elif name == 'resnet101': resnet = models.resnet101(pretrained=pretrained) elif name == 'resnet152': resnet = models.resnet152(pretrained=pretrained) else: return NotImplemented layer0 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.relu, resnet.maxpool) layer0.out_channels = resnet.bn1.num_features resnet.layer1.out_channels = get_channels(resnet.layer1) resnet.layer2.out_channels = get_channels(resnet.layer2) resnet.layer3.out_channels = get_channels(resnet.layer3) resnet.layer4.out_channels = get_channels(resnet.layer4) return [layer0, resnet.layer1, resnet.layer2, resnet.layer3, resnet.layer4]
Example #20
Source File: resnet.py From deeplabv3 with MIT License | 5 votes |
def __init__(self, num_layers): super(ResNet_Bottleneck_OS16, self).__init__() if num_layers == 50: resnet = models.resnet50() # load pretrained model: resnet.load_state_dict(torch.load("/root/deeplabv3/pretrained_models/resnet/resnet50-19c8e357.pth")) # remove fully connected layer, avg pool and layer5: self.resnet = nn.Sequential(*list(resnet.children())[:-3]) print ("pretrained resnet, 50") elif num_layers == 101: resnet = models.resnet101() # load pretrained model: resnet.load_state_dict(torch.load("/root/deeplabv3/pretrained_models/resnet/resnet101-5d3b4d8f.pth")) # remove fully connected layer, avg pool and layer5: self.resnet = nn.Sequential(*list(resnet.children())[:-3]) print ("pretrained resnet, 101") elif num_layers == 152: resnet = models.resnet152() # load pretrained model: resnet.load_state_dict(torch.load("/root/deeplabv3/pretrained_models/resnet/resnet152-b121ed2d.pth")) # remove fully connected layer, avg pool and layer5: self.resnet = nn.Sequential(*list(resnet.children())[:-3]) print ("pretrained resnet, 152") else: raise Exception("num_layers must be in {50, 101, 152}!") self.layer5 = make_layer(Bottleneck, in_channels=4*256, channels=512, num_blocks=3, stride=1, dilation=2)
Example #21
Source File: basenet.py From MCD_DA with MIT License | 5 votes |
def __init__(self,option = 'resnet18',pret=True): super(ResBasePlus, 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.layer = nn.Sequential( nn.Dropout(), nn.Linear(2048, 1000), nn.ReLU(inplace=True), nn.BatchNorm1d(1000,affine=True), nn.Dropout(), nn.ReLU(inplace=True), ) self.features = nn.Sequential(*mod)
Example #22
Source File: basenet.py From MCD_DA with MIT License | 5 votes |
def __init__(self,option = 'resnet18',pret=True): super(ResNet_all, 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.conv1 = model_ft.conv1 self.bn0 = model_ft.bn1 self.relu = model_ft.relu self.maxpool = model_ft.maxpool self.layer1 = model_ft.layer1 self.layer2 = model_ft.layer2 self.layer3 = model_ft.layer3 self.layer4 = model_ft.layer4 self.pool = model_ft.avgpool self.fc = nn.Linear(2048,12)
Example #23
Source File: basenet.py From MCD_DA with MIT License | 5 votes |
def __init__(self,option = 'resnet18',pret=True): super(ResBase_office, 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.conv1 = model_ft.conv1 self.bn0 = model_ft.bn1 self.relu = model_ft.relu self.maxpool = model_ft.maxpool self.layer1 = model_ft.layer1 self.layer2 = model_ft.layer2 self.layer3 = model_ft.layer3 self.layer4 = model_ft.layer4 self.pool = model_ft.avgpool #self.bottleneck = nn.Sequential(*layers) #self.features = nn.Sequential(*mod)
Example #24
Source File: basenet.py From MCD_DA with MIT License | 5 votes |
def __init__(self,option = 'resnet18',pret=True): super(ResBase_D, 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.conv1 = model_ft.conv1 self.bn0 = model_ft.bn1 self.relu = model_ft.relu self.maxpool = model_ft.maxpool self.drop0 = nn.Dropout2d() self.layer1 = model_ft.layer1 self.drop1 = nn.Dropout2d() self.layer2 = model_ft.layer2 self.drop2 = nn.Dropout2d() self.layer3 = model_ft.layer3 self.drop3 = nn.Dropout2d() self.layer4 = model_ft.layer4 self.drop4 = nn.Dropout2d() self.pool = model_ft.avgpool #self.features = nn.Sequential(*mod)
Example #25
Source File: resnet_qc.py From AD-DL with MIT License | 5 votes |
def resnet_qc_152(pretrained=False, **kwargs): """Constructs a ResNet-152 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet """ model = ResNetQC(Bottleneck, [3, 8, 36, 3], **kwargs) if pretrained: model_ft = models.resnet152(pretrained=True) model.load_from_std(model_ft) return model
Example #26
Source File: image_captioner.py From strike-with-a-pose with GNU General Public License v3.0 | 5 votes |
def __init__(self, embed_size): """Load the pretrained ResNet-152 and replace top fc layer.""" super(EncoderCNN, self).__init__() resnet = models.resnet152(pretrained=True) modules = list(resnet.children())[:-1] self.resnet = nn.Sequential(*modules) self.linear = nn.Linear(resnet.fc.in_features, embed_size) self.bn = nn.BatchNorm1d(embed_size, momentum=0.01)
Example #27
Source File: model.py From pytorch-tutorial with MIT License | 5 votes |
def __init__(self, embed_size): """Load the pretrained ResNet-152 and replace top fc layer.""" super(EncoderCNN, self).__init__() resnet = models.resnet152(pretrained=True) modules = list(resnet.children())[:-1] # delete the last fc layer. self.resnet = nn.Sequential(*modules) self.linear = nn.Linear(resnet.fc.in_features, embed_size) self.bn = nn.BatchNorm1d(embed_size, momentum=0.01)
Example #28
Source File: archs.py From pytorch-adacos with MIT License | 5 votes |
def __init__(self, args): super().__init__() if args.backbone == 'resnet18': self.backbone = models.resnet18(pretrained=True) last_channels = 512 elif args.backbone == 'resnet34': self.backbone = models.resnet34(pretrained=True) last_channels = 512 elif args.backbone == 'resnet50': self.backbone = models.resnet50(pretrained=True) last_channels = 2048 elif args.backbone == 'resnet101': self.backbone = models.resnet101(pretrained=True) last_channels = 2048 elif args.backbone == 'resnet152': self.backbone = models.resnet152(pretrained=True) last_channels = 2048 self.features = nn.Sequential( self.backbone.conv1, self.backbone.bn1, self.backbone.relu, self.backbone.layer1, self.backbone.layer2, self.backbone.layer3, self.backbone.layer4) self.bn1 = nn.BatchNorm2d(last_channels) self.dropout = nn.Dropout2d(0.5) self.fc = nn.Linear(8*8*last_channels, args.num_features) self.bn2 = nn.BatchNorm1d(args.num_features)
Example #29
Source File: gcn152.py From segmentation-networks-benchmark with MIT License | 5 votes |
def __init__(self, num_classes, input_size, pretrained=True): super(GCN152, self).__init__() self.input_size = input_size self.num_classes = num_classes resnet = models.resnet152(pretrained) self.layer0 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.relu) self.layer1 = nn.Sequential(resnet.maxpool, resnet.layer1) self.layer2 = resnet.layer2 self.layer3 = resnet.layer3 self.layer4 = resnet.layer4 self.gcm1 = _GlobalConvModule(2048, num_classes, (7, 7)) self.gcm2 = _GlobalConvModule(1024, num_classes, (7, 7)) self.gcm3 = _GlobalConvModule(512, num_classes, (7, 7)) self.gcm4 = _GlobalConvModule(256, num_classes, (7, 7)) self.brm1 = _BoundaryRefineModule(num_classes) self.brm2 = _BoundaryRefineModule(num_classes) self.brm3 = _BoundaryRefineModule(num_classes) self.brm4 = _BoundaryRefineModule(num_classes) self.brm5 = _BoundaryRefineModule(num_classes) self.brm6 = _BoundaryRefineModule(num_classes) self.brm7 = _BoundaryRefineModule(num_classes) self.brm8 = _BoundaryRefineModule(num_classes) self.brm9 = _BoundaryRefineModule(num_classes) initialize_weights(self.gcm1, self.gcm2, self.gcm3, self.gcm4, self.brm1, self.brm2, self.brm3, self.brm4, self.brm5, self.brm6, self.brm7, self.brm8, self.brm9)
Example #30
Source File: duc_hdc.py From segmentation-networks-benchmark with MIT License | 5 votes |
def __init__(self, num_classes, pretrained=True): super(ResNetDUCHDC, self).__init__() resnet = models.resnet152(pretrained=pretrained) self.num_classes = num_classes self.layer0 = nn.Sequential(resnet.conv1, resnet.bn1, resnet.relu, resnet.maxpool) self.layer1 = resnet.layer1 self.layer2 = resnet.layer2 self.layer3 = resnet.layer3 self.layer4 = resnet.layer4 for n, m in self.layer3.named_modules(): if 'conv2' in n or 'downsample.0' in n: m.stride = (1, 1) for n, m in self.layer4.named_modules(): if 'conv2' in n or 'downsample.0' in n: m.stride = (1, 1) layer3_group_config = [1, 2, 5, 9] for idx in range(len(self.layer3)): self.layer3[idx].conv2.dilation = (layer3_group_config[idx % 4], layer3_group_config[idx % 4]) self.layer3[idx].conv2.padding = (layer3_group_config[idx % 4], layer3_group_config[idx % 4]) layer4_group_config = [5, 9, 17] for idx in range(len(self.layer4)): self.layer4[idx].conv2.dilation = (layer4_group_config[idx], layer4_group_config[idx]) self.layer4[idx].conv2.padding = (layer4_group_config[idx], layer4_group_config[idx]) self.duc = _DenseUpsamplingConvModule(8, 2048, num_classes)