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


Python resnet.ResNet方法代码示例

本文整理汇总了Python中torchvision.models.resnet.ResNet方法的典型用法代码示例。如果您正苦于以下问题:Python resnet.ResNet方法的具体用法?Python resnet.ResNet怎么用?Python resnet.ResNet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torchvision.models.resnet的用法示例。


在下文中一共展示了resnet.ResNet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def __init__(self, raw_model_dir, use_flow, logger):
        super(BackboneModel, self).__init__()
        self.use_flow = use_flow
        model = ResNet(Bottleneck, [3, 4, 6, 3])

        model.load_state_dict(
            model_zoo.load_url(model_urls['resnet50'], model_dir=raw_model_dir))
        logger.info('Model restored from pretrained resnet50')

        self.feature = nn.Sequential(*list(model.children())[:-2])
        self.base = list(self.feature.parameters())

        if self.use_flow:
            self.flow_branch = self.get_flow_branch(model)
            self.rgb_branch = nn.Sequential(model.conv1, model.bn1, model.relu, model.maxpool)
            self.fuse_branch = nn.Sequential(*list(model.children())[4:-2])
        self.fea_dim = model.fc.in_features 
开发者ID:yolomax,项目名称:person-reid-lib,代码行数:19,代码来源:resnet50.py

示例2: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def __init__(self, block, layers, dim=128, **kwargs):
        """Initializes original ResNet and overwrites fully connected layer."""

        super(TriNet, self).__init__(block, layers, 1) # 0 classes thows an error
        batch_norm = nn.BatchNorm1d(1024)
        self.avgpool = nn.AvgPool2d((8,4))
        self.fc = nn.Sequential(
            nn.Linear(512 * block.expansion, 1024),
            batch_norm,
            nn.ReLU(),
            nn.Linear(1024, dim)
        )
        batch_norm.weight.data.fill_(1)
        batch_norm.bias.data.zero_()
        self.dim = dim
        self.dimensions = {'emb': (self.dim, )} 
开发者ID:kilsenp,项目名称:triplet-reid-pytorch,代码行数:18,代码来源:trinet.py

示例3: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def __init__(self, block, layers, num_classes, dim=128, **kwargs):
        """Initializes original ResNet and overwrites fully connected layer."""

        super().__init__(block, layers, 1) # 0 classes thows an error

        #overwrite self.inplanes which is set by make_layer
        self.inplanes = 256 * block.expansion
        self.layer4 = self._make_dilated_layer4(DilatedBottleneck, 512, layers[3])
        self.avgpool = nn.AvgPool2d((16, 8))
        self.fc1 = nn.Linear(512 * block.expansion, 1024)
        self.batch_norm = nn.BatchNorm1d(1024)
        self.relu = nn.ReLU()
        self.fc_emb = nn.Linear(1024, dim)
        self.fc_soft = nn.Linear(1024, num_classes)
        self.batch_norm.weight.data.fill_(1)
        self.batch_norm.bias.data.zero_()
        self.dim = dim 
开发者ID:kilsenp,项目名称:triplet-reid-pytorch,代码行数:19,代码来源:dilated.py

示例4: resnet18

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet18(config_channels, anchors, num_cls, **kwargs):
    model = ResNet(config_channels, anchors, num_cls, BasicBlock, [2, 2, 2, 2], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet18']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:resnet.py

示例5: resnet34

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet34(config_channels, anchors, num_cls, **kwargs):
    model = ResNet(config_channels, anchors, num_cls, BasicBlock, [3, 4, 6, 3], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet34']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:resnet.py

示例6: resnet50

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet50(config_channels, anchors, num_cls, **kwargs):
    model = ResNet(config_channels, anchors, num_cls, Bottleneck, [3, 4, 6, 3], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet50']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:resnet.py

示例7: resnet101

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet101(config_channels, anchors, num_cls, **kwargs):
    model = ResNet(config_channels, anchors, num_cls, Bottleneck, [3, 4, 23, 3], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet101']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:resnet.py

示例8: resnet152

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet152(config_channels, anchors, num_cls, **kwargs):
    model = ResNet(config_channels, anchors, num_cls, Bottleneck, [3, 8, 36, 3], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet152']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:13,代码来源:resnet.py

示例9: ResNet18C4

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def ResNet18C4():
    return ResNet(layers=[2, 2, 2, 2], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet18']) 
开发者ID:NVIDIA,项目名称:retinanet-examples,代码行数:4,代码来源:resnet.py

示例10: ResNet34C4

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def ResNet34C4():
    return ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet34']) 
开发者ID:NVIDIA,项目名称:retinanet-examples,代码行数:4,代码来源:resnet.py

示例11: _resnext

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def _resnext(arch, block, layers, pretrained, progress, **kwargs):
    model = ResNet(block, layers, **kwargs)
    state_dict = load_state_dict_from_url(model_urls[arch], progress=progress)
    model.load_state_dict(state_dict)
    return model 
开发者ID:openseg-group,项目名称:openseg.pytorch,代码行数:7,代码来源:wsl_resnext_models.py

示例12: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def __init__(self, block, layers, num_classes=1000, drop_prob=0., block_size=5):
        super(ResNet, self).__init__()
        self.inplanes = 64
        self.conv1 = nn.Conv2d(3, 64, kernel_size=7, stride=2, padding=3,
                               bias=False)
        self.bn1 = nn.BatchNorm2d(64)
        self.relu = nn.ReLU(inplace=True)
        self.dropblock = LinearScheduler(
            DropBlock2D(drop_prob=drop_prob, block_size=block_size),
            start_value=0.,
            stop_value=drop_prob,
            nr_steps=5e3
        )
        self.maxpool = nn.MaxPool2d(kernel_size=3, stride=2, padding=1)
        self.layer1 = self._make_layer(block, 64, layers[0])
        self.layer2 = self._make_layer(block, 128, layers[1], stride=2)
        self.layer3 = self._make_layer(block, 256, layers[2], stride=2)
        self.layer4 = self._make_layer(block, 512, layers[3], stride=2)
        self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
        self.fc = nn.Linear(512 * block.expansion, num_classes)

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
            elif isinstance(m, nn.BatchNorm2d):
                nn.init.constant_(m.weight, 1)
                nn.init.constant_(m.bias, 0) 
开发者ID:miguelvr,项目名称:dropblock,代码行数:29,代码来源:resnet-cifar10.py

示例13: __init__

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def __init__(self, layers=[3, 4, 6, 3]):
        block = resnet.BasicBlock
        num_classes = 7
        self.model = resnet.ResNet(block, layers, num_classes)
        if torch.cuda.is_available():
            self.model.cuda()
        self.bestaccur = 0.0 
开发者ID:co60ca,项目名称:EmotionNet2,代码行数:9,代码来源:emotionnet.py

示例14: resnet18

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet18(config_channels, **kwargs):
    model = ResNet(config_channels, BasicBlock, [2, 2, 2, 2], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet18']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:13,代码来源:resnet.py

示例15: resnet34

# 需要导入模块: from torchvision.models import resnet [as 别名]
# 或者: from torchvision.models.resnet import ResNet [as 别名]
def resnet34(config_channels, **kwargs):
    model = ResNet(config_channels, BasicBlock, [3, 4, 6, 3], **kwargs)
    if config_channels.config.getboolean('model', 'pretrained'):
        url = _model.model_urls['resnet34']
        logging.info('use pretrained model: ' + url)
        state_dict = model.state_dict()
        for key, value in model_zoo.load_url(url).items():
            if key in state_dict:
                state_dict[key] = value
        model.load_state_dict(state_dict)
    return model 
开发者ID:ruiminshen,项目名称:openpose-pytorch,代码行数:13,代码来源:resnet.py


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