本文整理汇总了Python中torchvision.models.vgg.model_urls方法的典型用法代码示例。如果您正苦于以下问题:Python vgg.model_urls方法的具体用法?Python vgg.model_urls怎么用?Python vgg.model_urls使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchvision.models.vgg
的用法示例。
在下文中一共展示了vgg.model_urls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_base_weights
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def load_base_weights(self):
"""This is complicated because we converted the base model to be fully
convolutional, so some surgery needs to happen here."""
base_state_dict = model_zoo.load_url(vgg.model_urls['vgg16'])
vgg_state_dict = {k[len('features.'):]: v
for k, v in base_state_dict.items()
if k.startswith('features.')}
self.vgg.load_state_dict(vgg_state_dict)
vgg_head_params = self.vgg_head.parameters()
for k, v in base_state_dict.items():
if not k.startswith('classifier.'):
continue
if k.startswith('classifier.6.'):
# skip final classifier output
continue
vgg_head_param = next(vgg_head_params)
vgg_head_param.data = v.view(vgg_head_param.size())
示例2: load_base_weights
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def load_base_weights(self):
"""This is complicated because we converted the base model to be fully
convolutional, so some surgery needs to happen here."""
base_state_dict = model_zoo.load_url(vgg.model_urls['vgg16'])
vgg_state_dict = {k[len('features.'):]: v
for k, v in base_state_dict.items()
if k.startswith('features.')}
self.vgg.load_state_dict(vgg_state_dict)
vgg_head_params = self.vgg_head.parameters()
for k, v in base_state_dict.items():
if not k.startswith('classifier.'):
continue
if k.startswith('classifier.6.'):
# skip final classifier output
continue
vgg_head_param = next(vgg_head_params)
vgg_head_param.data = v.view(vgg_head_param.size())
示例3: vgg11
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg11(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['A']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg11']
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
示例4: vgg11_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg11_bn(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['A'], batch_norm=True))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg11_bn']
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
示例5: vgg13
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg13(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['B']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg13']
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
示例6: vgg13_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg13_bn(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['B'], batch_norm=True))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg13_bn']
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
示例7: vgg16
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg16(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['D']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg16']
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
示例8: vgg19
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg19(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['E']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg19']
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
示例9: vgg19_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg19_bn(config_channels, anchors, num_cls):
model = VGG(config_channels, anchors, num_cls, make_layers(config_channels, cfg['E'], batch_norm=True))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg19_bn']
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
示例10: __init__
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def __init__(self, pretrained=True, freeze=True):
super(vgg16_bn, self).__init__()
model_urls['vgg16_bn'] = model_urls['vgg16_bn'].replace('https://', 'http://')
vgg_pretrained_features = models.vgg16_bn(pretrained=pretrained).features
self.slice1 = torch.nn.Sequential()
self.slice2 = torch.nn.Sequential()
self.slice3 = torch.nn.Sequential()
self.slice4 = torch.nn.Sequential()
self.slice5 = torch.nn.Sequential()
for x in range(12): # conv2_2
self.slice1.add_module(str(x), vgg_pretrained_features[x])
for x in range(12, 19): # conv3_3
self.slice2.add_module(str(x), vgg_pretrained_features[x])
for x in range(19, 29): # conv4_3
self.slice3.add_module(str(x), vgg_pretrained_features[x])
for x in range(29, 39): # conv5_3
self.slice4.add_module(str(x), vgg_pretrained_features[x])
# fc6, fc7 without atrous conv
self.slice5 = torch.nn.Sequential(
nn.MaxPool2d(kernel_size=3, stride=1, padding=1),
nn.Conv2d(512, 1024, kernel_size=3, padding=6, dilation=6),
nn.Conv2d(1024, 1024, kernel_size=1)
)
if not pretrained:
init_weights(self.slice1.modules())
init_weights(self.slice2.modules())
init_weights(self.slice3.modules())
init_weights(self.slice4.modules())
init_weights(self.slice5.modules()) # no pretrained model for fc6 and fc7
if freeze:
for param in self.slice1.parameters(): # only first conv
param.requires_grad= False
示例11: vgg11
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg11(config_channels):
model = VGG(config_channels, make_layers(config_channels, cfg['A']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg11']
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
示例12: vgg11_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg11_bn(config_channels):
model = VGG(config_channels, make_layers(config_channels, cfg['A'], batch_norm=True))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg11_bn']
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
示例13: vgg13
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg13(config_channels):
model = VGG(config_channels, make_layers(config_channels, cfg['B']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg13']
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
示例14: vgg13_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg13_bn(config_channels):
model = VGG(config_channels, make_layers(config_channels, cfg['B'], batch_norm=True))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg13_bn']
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
示例15: vgg16
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import model_urls [as 别名]
def vgg16(config_channels):
model = VGG(config_channels, make_layers(config_channels, cfg['D']))
if config_channels.config.getboolean('model', 'pretrained'):
url = model_urls['vgg16']
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