当前位置: 首页>>代码示例>>Python>>正文


Python models.resnet101方法代码示例

本文整理汇总了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() 
开发者ID:varunagrawal,项目名称:tiny-faces-pytorch,代码行数:19,代码来源:model.py

示例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() 
开发者ID:YBIGTA,项目名称:pytorch-hair-segmentation,代码行数:26,代码来源:pspnet.py

示例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 
开发者ID:TRI-ML,项目名称:packnet-sfm,代码行数:23,代码来源:resnet_encoder.py

示例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) 
开发者ID:JHUVisionLab,项目名称:multi-modal-regression,代码行数:25,代码来源:featureModels.py

示例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) 
开发者ID:mil-tokyo,项目名称:MCD_DA,代码行数:22,代码来源:basenet.py

示例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 
开发者ID:richzhang,项目名称:PerceptualSimilarity,代码行数:24,代码来源:pretrained_networks.py

示例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 
开发者ID:thunil,项目名称:TecoGAN,代码行数:24,代码来源:pretrained_networks.py

示例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 
开发者ID:BCV-Uniandes,项目名称:SMIT,代码行数:24,代码来源:pretrained_networks.py

示例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) 
开发者ID:YudeWang,项目名称:deeplabv3plus-pytorch,代码行数:25,代码来源:resnet.py

示例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()) 
开发者ID:gjy3035,项目名称:NWPU-Crowd-Sample-Code,代码行数:24,代码来源:Res101_SFCN.py

示例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()) 
开发者ID:gjy3035,项目名称:GCC-SFCN,代码行数:26,代码来源:resSFCN.py

示例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 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:15,代码来源:backbone.py

示例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 
开发者ID:jindongwang,项目名称:transferlearning,代码行数:14,代码来源:backbone.py

示例14: Resnet101

# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import resnet101 [as 别名]
def Resnet101(config):
    return models.resnet101(pretrained=True) 
开发者ID:ngessert,项目名称:isic2019,代码行数:4,代码来源:models.py

示例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),
        ) 
开发者ID:mapleneverfade,项目名称:pytorch-semantic-segmentation,代码行数:32,代码来源:pspnet.py


注:本文中的torchvision.models.resnet101方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。