本文整理汇总了Python中torchvision.models.vgg.VGG属性的典型用法代码示例。如果您正苦于以下问题:Python vgg.VGG属性的具体用法?Python vgg.VGG怎么用?Python vgg.VGG使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类torchvision.models.vgg
的用法示例。
在下文中一共展示了vgg.VGG属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_vgg_cfg
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [as 别名]
def get_vgg_cfg(model):
"""
return config list to generate VGG instance
:param model: class VGG (torch.nn.Module), model to prune
:return:
list, config list to generate VGG instance
"""
assert isinstance(model, models.VGG)
features = model.features
if isinstance(features, torch.nn.DataParallel):
features = features.module
cfg = []
batch_norm = False
for m in features:
if isinstance(m, torch.nn.modules.conv._ConvNd):
cfg.append(m.out_channels)
elif isinstance(m, torch.nn.modules.pooling._MaxPoolNd):
cfg.append('M')
elif isinstance(m, torch.nn.modules.batchnorm._BatchNorm):
batch_norm = True
return cfg, batch_norm
示例2: vgg11
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例3: vgg11_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例4: vgg13
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例5: vgg13_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例6: vgg16
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例7: vgg19
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例8: vgg19_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例9: get_vgg
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [as 别名]
def get_vgg(in_channels=3, **kwargs):
model = VGG(make_layers(cfg['D'], in_channels), **kwargs)
return model
示例10: make_dilated
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [as 别名]
def make_dilated(self, stage_list, dilation_list):
raise ValueError("'VGG' models do not support dilated mode due to Max Pooling"
" operations for downsampling!")
示例11: forward
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [as 别名]
def forward(self, x):
output = {}
# get the output of each maxpooling layer (5 maxpool in VGG net)
for idx in range(len(self.ranges)):
for layer in range(self.ranges[idx][0], self.ranges[idx][1]):
x = self.features[layer](x)
output["x%d"%(idx+1)] = x
return output
示例12: vgg_face
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [as 别名]
def vgg_face(pretrained=False, **kwargs):
if pretrained:
kwargs['init_weights'] = False
model = vgg.VGG(vgg.make_layers(vgg.cfgs['D'], batch_norm=False), num_classes=2622, **kwargs)
if pretrained:
model.load_state_dict(vgg_face_state_dict())
return model
示例13: vgg11
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例14: vgg11_bn
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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
示例15: vgg13
# 需要导入模块: from torchvision.models import vgg [as 别名]
# 或者: from torchvision.models.vgg import VGG [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