当前位置: 首页 > 文档资料 > PyTorch 中文文档 >

torchvision.models

优质
小牛编辑
132浏览
2023-12-01

torchvision.models模块的 子模块中包含以下模型结构。

  • AlexNet
  • VGG
  • ResNet
  • SqueezeNet
  • DenseNet You can construct a model with random weights by calling its constructor:

你可以使用随机初始化的权重来创建这些模型。

import torchvision.models as models
resnet18 = models.resnet18()
alexnet = models.alexnet()
squeezenet = models.squeezenet1_0()
densenet = models.densenet_161()

We provide pre-trained models for the ResNet variants and AlexNet, using the PyTorch torch.utils.model_zoo. These can constructed by passing pretrained=True: 对于ResNet variantsAlexNet,我们也提供了预训练(pre-trained)的模型。

import torchvision.models as models
#pretrained=True就可以使用预训练的模型
resnet18 = models.resnet18(pretrained=True)
alexnet = models.alexnet(pretrained=True)

ImageNet 1-crop error rates (224x224)

NetworkTop-1 errorTop-5 error
ResNet-1830.2410.92
ResNet-3426.708.58
ResNet-5023.857.13
ResNet-10122.636.44
ResNet-15221.695.94
Inception v322.556.44
AlexNet43.4520.91
VGG-1130.9811.37
VGG-1330.0710.75
VGG-1628.419.62
VGG-1927.629.12
SqueezeNet 1.041.9019.58
SqueezeNet 1.141.8119.38
Densenet-12125.357.83
Densenet-16924.007.00
Densenet-20122.806.43
Densenet-16122.356.20

torchvision.models.alexnet(pretrained=False, ** kwargs)

AlexNet 模型结构 paper地址

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.resnet18(pretrained=False, ** kwargs)

构建一个resnet18模型

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.resnet34(pretrained=False, ** kwargs)

构建一个ResNet-34 模型.

Parameters: pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.resnet50(pretrained=False, ** kwargs)

构建一个ResNet-50模型

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.resnet101(pretrained=False, ** kwargs)

Constructs a ResNet-101 model.

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.resnet152(pretrained=False, ** kwargs)

Constructs a ResNet-152 model.

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.vgg11(pretrained=False, ** kwargs)

VGG 11-layer model (configuration “A”) - pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.vgg11_bn(** kwargs)

VGG 11-layer model (configuration “A”) with batch normalization

torchvision.models.vgg13(pretrained=False, ** kwargs)

VGG 13-layer model (configuration “B”)

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.vgg13_bn(** kwargs)

VGG 13-layer model (configuration “B”) with batch normalization

torchvision.models.vgg16(pretrained=False, ** kwargs)

VGG 16-layer model (configuration “D”)

Parameters: pretrained (bool) – If True, returns a model pre-trained on ImageNet

torchvision.models.vgg16_bn(** kwargs)

VGG 16-layer model (configuration “D”) with batch normalization

torchvision.models.vgg19(pretrained=False, ** kwargs)

VGG 19-layer model (configuration “E”)

  • pretrained (bool) – True, 返回在ImageNet上训练好的模型。

torchvision.models.vgg19_bn(** kwargs)

VGG 19-layer model (configuration ‘E’) with batch normalization