本文整理汇总了Python中torchvision.models.vgg13方法的典型用法代码示例。如果您正苦于以下问题:Python models.vgg13方法的具体用法?Python models.vgg13怎么用?Python models.vgg13使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torchvision.models
的用法示例。
在下文中一共展示了models.vgg13方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def main():
# model = models.vgg19_bn(pretrained=True)
# _, summary = weight_watcher.analyze(model, alphas=False)
# for key, value in summary.items():
# print('{:10s} : {:}'.format(key, value))
_, summary = weight_watcher.analyze(models.vgg13(pretrained=True), alphas=False)
print('vgg-13 : {:}'.format(summary['lognorm']))
_, summary = weight_watcher.analyze(models.vgg13_bn(pretrained=True), alphas=False)
print('vgg-13-BN : {:}'.format(summary['lognorm']))
_, summary = weight_watcher.analyze(models.vgg16(pretrained=True), alphas=False)
print('vgg-16 : {:}'.format(summary['lognorm']))
_, summary = weight_watcher.analyze(models.vgg16_bn(pretrained=True), alphas=False)
print('vgg-16-BN : {:}'.format(summary['lognorm']))
_, summary = weight_watcher.analyze(models.vgg19(pretrained=True), alphas=False)
print('vgg-19 : {:}'.format(summary['lognorm']))
_, summary = weight_watcher.analyze(models.vgg19_bn(pretrained=True), alphas=False)
print('vgg-19-BN : {:}'.format(summary['lognorm']))
示例2: vgg13
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def vgg13(num_classes=1000, pretrained='imagenet'):
"""VGG 13-layer model (configuration "B")
"""
model = models.vgg13(pretrained=False)
if pretrained is not None:
settings = pretrained_settings['vgg13'][pretrained]
model = load_pretrained(model, num_classes, settings)
model = modify_vggs(model)
return model
示例3: _load_pytorch_model
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def _load_pytorch_model(model_name, summary):
import torchvision.models as models
switcher = {
'alexnet': lambda: models.alexnet(pretrained=True).eval(),
"vgg11": lambda: models.vgg11(pretrained=True).eval(),
"vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
"vgg13": lambda: models.vgg13(pretrained=True).eval(),
"vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
"vgg16": lambda: models.vgg16(pretrained=True).eval(),
"vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
"vgg19": lambda: models.vgg19(pretrained=True).eval(),
"vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
"resnet18": lambda: models.resnet18(pretrained=True).eval(),
"resnet34": lambda: models.resnet34(pretrained=True).eval(),
"resnet50": lambda: models.resnet50(pretrained=True).eval(),
"resnet101": lambda: models.resnet101(pretrained=True).eval(),
"resnet152": lambda: models.resnet152(pretrained=True).eval(),
"squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
"squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
"densenet121": lambda: models.densenet121(pretrained=True).eval(),
"densenet161": lambda: models.densenet161(pretrained=True).eval(),
"densenet201": lambda: models.densenet201(pretrained=True).eval(),
"inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
}
_load_model = switcher.get(model_name, None)
_model = _load_model()
import torch
if torch.cuda.is_available():
_model = _model.cuda()
from perceptron.models.classification.pytorch import PyTorchModel as ClsPyTorchModel
import numpy as np
mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
std = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
pmodel = ClsPyTorchModel(
_model, bounds=(
0, 1), num_classes=1000, preprocessing=(
mean, std))
return pmodel
示例4: load_pytorch_model
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def load_pytorch_model(model_name):
import torchvision.models as models
switcher = {
'alexnet': lambda: models.alexnet(pretrained=True).eval(),
"vgg11": lambda: models.vgg11(pretrained=True).eval(),
"vgg11_bn": lambda: models.vgg11_bn(pretrained=True).eval(),
"vgg13": lambda: models.vgg13(pretrained=True).eval(),
"vgg13_bn": lambda: models.vgg13_bn(pretrained=True).eval(),
"vgg16": lambda: models.vgg16(pretrained=True).eval(),
"vgg16_bn": lambda: models.vgg16_bn(pretrained=True).eval(),
"vgg19": lambda: models.vgg19(pretrained=True).eval(),
"vgg19_bn": lambda: models.vgg19_bn(pretrained=True).eval(),
"resnet18": lambda: models.resnet18(pretrained=True).eval(),
"resnet34": lambda: models.resnet34(pretrained=True).eval(),
"resnet50": lambda: models.resnet50(pretrained=True).eval(),
"resnet101": lambda: models.resnet101(pretrained=True).eval(),
"resnet152": lambda: models.resnet152(pretrained=True).eval(),
"squeezenet1_0": lambda: models.squeezenet1_0(pretrained=True).eval(),
"squeezenet1_1": lambda: models.squeezenet1_1(pretrained=True).eval(),
"densenet121": lambda: models.densenet121(pretrained=True).eval(),
"densenet161": lambda: models.densenet161(pretrained=True).eval(),
"densenet201": lambda: models.densenet201(pretrained=True).eval(),
"inception_v3": lambda: models.inception_v3(pretrained=True).eval(),
}
_load_model = switcher.get(model_name, None)
_model = _load_model()
return _model
示例5: getNetwork
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def getNetwork(args):
if (args.net_type == 'alexnet'):
net = models.alexnet(pretrained=args.finetune)
file_name = 'alexnet'
elif (args.net_type == 'vggnet'):
if(args.depth == 11):
net = models.vgg11(pretrained=args.finetune)
elif(args.depth == 13):
net = models.vgg13(pretrained=args.finetune)
elif(args.depth == 16):
net = models.vgg16(pretrained=args.finetune)
elif(args.depth == 19):
net = models.vgg19(pretrained=args.finetune)
else:
print('Error : VGGnet should have depth of either [11, 13, 16, 19]')
sys.exit(1)
file_name = 'vgg-%s' %(args.depth)
elif (args.net_type == 'squeezenet'):
net = models.squeezenet1_0(pretrained=args.finetune)
file_name = 'squeeze'
elif (args.net_type == 'resnet'):
net = resnet(args.finetune, args.depth)
file_name = 'resnet-%s' %(args.depth)
elif (args.net_type == 'inception'):
net = pretrainedmodels.inceptionv3(num_classes=1000, pretrained='imagenet')
file_name = 'inception-v3'
elif (args.net_type == 'xception'):
net = pretrainedmodels.xception(num_classes=1000, pretrained='imagenet')
file_name = 'xception'
else:
print('Error : Network should be either [alexnet / squeezenet / vggnet / resnet]')
sys.exit(1)
return net, file_name
示例6: vgg13
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def vgg13(num_classes=1000, pretrained='imagenet'):
"""VGG 13-layer model (configuration "B")
"""
model = models.vgg13(pretrained=False)
if pretrained is not None:
settings = pretrained_settings['vgg13'][pretrained]
model = load_pretrained(model, num_classes, settings)
return model
示例7: getNetwork
# 需要导入模块: from torchvision import models [as 别名]
# 或者: from torchvision.models import vgg13 [as 别名]
def getNetwork(args):
if (args.net_type == 'alexnet'):
net = models.alexnet(pretrained=args.finetune)
file_name = 'alexnet'
elif (args.net_type == 'vggnet'):
if(args.depth == 11):
net = models.vgg11(pretrained=args.finetune)
elif(args.depth == 13):
net = models.vgg13(pretrained=args.finetune)
elif(args.depth == 16):
net = models.vgg16(pretrained=args.finetune)
elif(args.depth == 19):
net = models.vgg19(pretrained=args.finetune)
else:
print('Error : VGGnet should have depth of either [11, 13, 16, 19]')
sys.exit(1)
file_name = 'vgg-%s' %(args.depth)
elif (args.net_type == 'resnet'):
net = resnet(args.finetune, args.depth)
file_name = 'resnet-%s' %(args.depth)
else:
print('Error : Network should be either [alexnet / vggnet / resnet / densenet]')
sys.exit(1)
return net, file_name