本文整理汇总了Python中torchvision.models.densenet169方法的典型用法代码示例。如果您正苦于以下问题:Python models.densenet169方法的具体用法?Python models.densenet169怎么用?Python models.densenet169使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchvision.models
的用法示例。
在下文中一共展示了models.densenet169方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: densenet169
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet169 [as 别名]
def densenet169(num_classes=1000, pretrained='imagenet'):
r"""Densenet-169 model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`
"""
model = models.densenet169(num_classes=num_classes, pretrained=False)
if pretrained is not None:
# '.'s are no longer allowed in module names, but pervious _DenseLayer
# has keys 'norm.1', 'relu.1', 'conv.1', 'norm.2', 'relu.2', 'conv.2'.
# They are also in the checkpoints in model_urls. This pattern is used
# to find such keys.
settings = pretrained_settings['densenet169'][pretrained]
pattern = re.compile(
r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
state_dict = model_zoo.load_url(settings['url'])
for key in list(state_dict.keys()):
res = pattern.match(key)
if res:
new_key = res.group(1) + res.group(2)
state_dict[new_key] = state_dict[key]
del state_dict[key]
model.load_state_dict(state_dict)
model = modify_densenets(model)
return model
示例2: Dense161
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet169 [as 别名]
def Dense161(config):
return models.densenet169(pretrained=True)
示例3: dn169
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet169 [as 别名]
def dn169(pre): return children(densenet169(pre))[0]
示例4: densenet169
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet169 [as 别名]
def densenet169(num_classes=1000, pretrained='imagenet'):
r"""Densenet-169 model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`
"""
model = models.densenet169(pretrained=False)
if pretrained is not None:
settings = pretrained_settings['densenet169'][pretrained]
model = load_pretrained(model, num_classes, settings)
model = modify_densenets(model)
return model
示例5: denseUnet169
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import densenet169 [as 别名]
def denseUnet169(pretrained=False, d_block_type='basic', init_method='normal', **kwargs):
r"""Densenet-121 model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_
Args:
pretrained (bool): If True, returns a model pre-trained on ImageNet
"""
d_block = get_decoder_block(d_block_type)
model = DenseUNet(num_init_features=64, growth_rate=32, block_config=(6, 12, 32, 32), d_block=d_block,
**kwargs)
if pretrained:
w_init.init_weights(model, init_method)
# Get state dict from the actual model
model_dict = model.state_dict()
# pretrained_dict = model_zoo.load_url(model_urls['resnet50'])
pretrained_dict = models.densenet169(pretrained=True).state_dict()
pretrained_dict = {k: v for k, v in pretrained_dict.items() if k in model_dict}
# added to pytorch 0.4
pattern = re.compile(
r'^(.*denselayer\d+\.(?:norm|relu|conv))\.((?:[12])\.(?:weight|bias|running_mean|running_var))$')
# state_dict = model_zoo.load_url(model_urls['densenet121'])
for key in list(pretrained_dict.keys()):
res = pattern.match(key)
if res:
new_key = res.group(1) + res.group(2)
pretrained_dict[new_key] = pretrained_dict[key]
del pretrained_dict[key]
model_dict.update(pretrained_dict)
model.load_state_dict(model_dict)
# model.load_state_dict(model_zoo.load_url(model_urls['densenet121']))
return model