Python torchvision.models.resnet.ResNet() Examples
The following are 18
code examples of torchvision.models.resnet.ResNet().
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.resnet
, or try the search function
.
Example #1
Source File: resnet50.py From person-reid-lib with MIT License | 6 votes |
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
Example #2
Source File: dilated.py From triplet-reid-pytorch with MIT License | 6 votes |
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
Example #3
Source File: trinet.py From triplet-reid-pytorch with MIT License | 6 votes |
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, )}
Example #4
Source File: resnet-cifar10.py From dropblock with MIT License | 5 votes |
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)
Example #5
Source File: resnet.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
def resnet152(config_channels, **kwargs): model = ResNet(config_channels, 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
Example #6
Source File: resnet.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
def resnet101(config_channels, **kwargs): model = ResNet(config_channels, 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
Example #7
Source File: resnet.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
def resnet50(config_channels, **kwargs): model = ResNet(config_channels, 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
Example #8
Source File: resnet.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #9
Source File: resnet.py From openpose-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #10
Source File: emotionnet.py From EmotionNet2 with GNU General Public License v3.0 | 5 votes |
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
Example #11
Source File: resnet.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #12
Source File: wsl_resnext_models.py From openseg.pytorch with MIT License | 5 votes |
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
Example #13
Source File: resnet.py From retinanet-examples with BSD 3-Clause "New" or "Revised" License | 5 votes |
def ResNet34C4(): return ResNet(layers=[3, 4, 6, 3], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet34'])
Example #14
Source File: resnet.py From retinanet-examples with BSD 3-Clause "New" or "Revised" License | 5 votes |
def ResNet18C4(): return ResNet(layers=[2, 2, 2, 2], bottleneck=vrn.BasicBlock, outputs=[4], url=vrn.model_urls['resnet18'])
Example #15
Source File: resnet.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #16
Source File: resnet.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #17
Source File: resnet.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #18
Source File: resnet.py From yolo2-pytorch with GNU Lesser General Public License v3.0 | 5 votes |
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