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