本文整理匯總了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