torchvision.models¶
models 子包包含用于寻址的模型的定义 不同的任务,包括:图像分类、像素语义 分割、对象检测、实例分割、人员 关键点检测和视频分类。
注意
可以保证向后兼容性,以加载序列化到使用旧 PyTorch 版本创建的模型。
相反,加载整个保存的模型或序列化(使用旧版本的 PyTorch 进行序列化)
不得保留历史行为。请参阅以下文档state_dict
ScriptModules
分类¶
models 子包包含以下模型的定义 图像分类架构:
初始 v3
ShuffleNet v2 版本
您可以通过调用其构造函数来构造具有随机权重的模型:
import torchvision.models as models
resnet18 = models.resnet18()
alexnet = models.alexnet()
vgg16 = models.vgg16()
squeezenet = models.squeezenet1_0()
densenet = models.densenet161()
inception = models.inception_v3()
googlenet = models.googlenet()
shufflenet = models.shufflenet_v2_x1_0()
mobilenet_v2 = models.mobilenet_v2()
mobilenet_v3_large = models.mobilenet_v3_large()
mobilenet_v3_small = models.mobilenet_v3_small()
resnext50_32x4d = models.resnext50_32x4d()
wide_resnet50_2 = models.wide_resnet50_2()
mnasnet = models.mnasnet1_0()
efficientnet_b0 = models.efficientnet_b0()
efficientnet_b1 = models.efficientnet_b1()
efficientnet_b2 = models.efficientnet_b2()
efficientnet_b3 = models.efficientnet_b3()
efficientnet_b4 = models.efficientnet_b4()
efficientnet_b5 = models.efficientnet_b5()
efficientnet_b6 = models.efficientnet_b6()
efficientnet_b7 = models.efficientnet_b7()
regnet_y_400mf = models.regnet_y_400mf()
regnet_y_800mf = models.regnet_y_800mf()
regnet_y_1_6gf = models.regnet_y_1_6gf()
regnet_y_3_2gf = models.regnet_y_3_2gf()
regnet_y_8gf = models.regnet_y_8gf()
regnet_y_16gf = models.regnet_y_16gf()
regnet_y_32gf = models.regnet_y_32gf()
regnet_x_400mf = models.regnet_x_400mf()
regnet_x_800mf = models.regnet_x_800mf()
regnet_x_1_6gf = models.regnet_x_1_6gf()
regnet_x_3_2gf = models.regnet_x_3_2gf()
regnet_x_8gf = models.regnet_x_8gf()
regnet_x_16gf = models.regnet_x_16gf()
regnet_x_32gf = models.regnet_x_32gf()
我们使用 PyTorch 提供预训练模型。
这些可以通过传递 :
pretrained=True
import torchvision.models as models
resnet18 = models.resnet18(pretrained=True)
alexnet = models.alexnet(pretrained=True)
squeezenet = models.squeezenet1_0(pretrained=True)
vgg16 = models.vgg16(pretrained=True)
densenet = models.densenet161(pretrained=True)
inception = models.inception_v3(pretrained=True)
googlenet = models.googlenet(pretrained=True)
shufflenet = models.shufflenet_v2_x1_0(pretrained=True)
mobilenet_v2 = models.mobilenet_v2(pretrained=True)
mobilenet_v3_large = models.mobilenet_v3_large(pretrained=True)
mobilenet_v3_small = models.mobilenet_v3_small(pretrained=True)
resnext50_32x4d = models.resnext50_32x4d(pretrained=True)
wide_resnet50_2 = models.wide_resnet50_2(pretrained=True)
mnasnet = models.mnasnet1_0(pretrained=True)
efficientnet_b0 = models.efficientnet_b0(pretrained=True)
efficientnet_b1 = models.efficientnet_b1(pretrained=True)
efficientnet_b2 = models.efficientnet_b2(pretrained=True)
efficientnet_b3 = models.efficientnet_b3(pretrained=True)
efficientnet_b4 = models.efficientnet_b4(pretrained=True)
efficientnet_b5 = models.efficientnet_b5(pretrained=True)
efficientnet_b6 = models.efficientnet_b6(pretrained=True)
efficientnet_b7 = models.efficientnet_b7(pretrained=True)
regnet_y_400mf = models.regnet_y_400mf(pretrained=True)
regnet_y_800mf = models.regnet_y_800mf(pretrained=True)
regnet_y_1_6gf = models.regnet_y_1_6gf(pretrained=True)
regnet_y_3_2gf = models.regnet_y_3_2gf(pretrained=True)
regnet_y_8gf = models.regnet_y_8gf(pretrained=True)
regnet_y_16gf = models.regnet_y_16gf(pretrained=True)
regnet_y_32gf = models.regnet_y_32gf(pretrained=True)
regnet_x_400mf = models.regnet_x_400mf(pretrained=True)
regnet_x_800mf = models.regnet_x_800mf(pretrained=True)
regnet_x_1_6gf = models.regnet_x_1_6gf(pretrained=True)
regnet_x_3_2gf = models.regnet_x_3_2gf(pretrained=True)
regnet_x_8gf = models.regnet_x_8gf(pretrained=True)
regnet_x_16gf = models.regnet_x_16gf(pretrainedTrue)
regnet_x_32gf = models.regnet_x_32gf(pretrained=True)
实例化预先训练的模型会将其权重下载到缓存目录。
可以使用 TORCH_MODEL_ZOO 环境变量设置此目录。有关详细信息,请参阅。
一些模型使用具有不同训练和评估的模块
行为,例如批量规范化。要在这些模式之间切换,请根据需要使用 或。有关详细信息,请参阅 或
。
model.train()
model.eval()
所有预训练模型都期望以相同的方式对输入图像进行归一化。
即形状为 (3 x H x W) 的 3 通道 RGB 图像的小批量,
其中 H 和 W 预计至少为 224。
图像必须加载到 [0, 1] 范围内,然后进行标准化
using 和 .
您可以使用以下转换进行规范化:mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
这种归一化的示例可以在 imagenet 示例中找到
获取 mean 和 std 值的过程大致相等 自:
import torch
from torchvision import datasets, transforms as T
transform = T.Compose([T.Resize(256), T.CenterCrop(224), T.ToTensor()])
dataset = datasets.ImageNet(".", split="train", transform=transform)
means = []
stds = []
for img in subset(dataset):
means.append(torch.mean(img))
stds.append(torch.std(img))
mean = torch.mean(torch.tensor(means))
std = torch.mean(torch.tensor(stds))
遗憾的是,使用的具体子集丢失了。了解更多 信息请参阅此讨论或这些实验。
EfficientNet 模型的大小取决于变体。有关确切的输入大小,请在此处查看
ImageNet 1 裁剪错误率
型 |
Acc@1 |
Acc@5 |
---|---|---|
亚历克斯网络 |
56.522 |
79.066 |
VGG-11型 |
69.020 |
88.628 |
VGG-13型 |
69.928 |
89.246 |
VGG-16型 |
71.592 |
90.382 |
VGG-19型 |
72.376 |
90.876 |
VGG-11 批量归一化 |
70.370 |
89.810 |
VGG-13 批量归一化 |
71.586 |
90.374 |
VGG-16 批量归一化 |
73.360 |
91.516 |
VGG-19 批量归一化 |
74.218 |
91.842 |
ResNet-18 系列 |
69.758 |
89.078 |
ResNet-34 的 |
73.314 |
91.420 |
ResNet-50 系列 |
76.130 |
92.862 |
ResNet-101 系列 |
77.374 |
93.546 |
ResNet-152 系列 |
78.312 |
94.046 |
SqueezeNet 1.0 |
58.092 |
80.420 |
SqueezeNet 1.1 |
58.178 |
80.624 |
Densenet-121 系列 |
74.434 |
91.972 |
登网-169 |
75.600 |
92.806 |
Densenet-201 系列 |
76.896 |
93.370 |
登网-161 |
77.138 |
93.560 |
初始 v3 |
77.294 |
93.450 |
谷歌网络 |
69.778 |
89.530 |
随机播放网 V2 x1.0 |
69.362 |
88.316 |
随机播放网 V2 x0.5 |
60.552 |
81.746 |
移动网络 V2 |
71.878 |
90.286 |
MobileNet V3 大型版 |
74.042 |
91.340 |
MobileNet V3 小型版 |
67.668 |
87.402 |
ResNeXt-50-32x4d |
77.618 |
93.698 |
ResNeXt-101-32x8d |
79.312 |
94.526 |
宽 ResNet-50-2 |
78.468 |
94.086 |
宽网-101-2 |
78.848 |
94.284 |
MNASNet 1.0 |
73.456 |
91.510 |
MNASNet 0.5 |
67.734 |
87.490 |
EfficientNet-B0 系列 |
77.692 |
93.532 |
EfficientNet-B1 系列 |
78.642 |
94.186 |
EfficientNet-B2 系列 |
80.608 |
95.310 |
EfficientNet-B3 高效网 |
82.008 |
96.054 |
EfficientNet-B4 系列 |
83.384 |
96.594 |
EfficientNet-B5 系列 |
83.444 |
96.628 |
EfficientNet-B6 系列 |
84.008 |
96.916 |
EfficientNet-B7 系列 |
84.122 |
96.908 |
regnet_x_400mf |
72.834 |
90.950 |
regnet_x_800mf |
75.212 |
92.348 |
regnet_x_1_6gf |
77.040 |
93.440 |
regnet_x_3_2gf |
78.364 |
93.992 |
regnet_x_8gf |
79.344 |
94.686 |
regnet_x_16gf |
80.058 |
94.944 |
regnet_x_32gf |
80.622 |
95.248 |
regnet_y_400mf |
74.046 |
91.716 |
regnet_y_800mf |
76.420 |
93.136 |
regnet_y_1_6gf |
77.950 |
93.966 |
regnet_y_3_2gf |
78.948 |
94.576 |
regnet_y_8gf |
80.032 |
95.048 |
regnet_y_16gf |
80.424 |
95.240 |
regnet_y_32gf |
80.878 |
95.340 |
亚历克斯内特¶
VGG的¶
-
torchvision.models.
vgg11
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 11 层模型(配置“A”),来自“用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg11_bn
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 11 层模型(配置“A”),具有批量归一化“用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg13
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 13 层模型(配置 “B”)“用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg13_bn
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 13 层模型(配置“B”),具有批量归一化“用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg16
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 16 层模型(配置 “D”) “用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg16_bn
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 16 层模型(配置“D”),具有批量归一化“用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
-
torchvision.models.
vgg19
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.vgg.VGG[来源]¶ VGG 19 层模型(配置 “E”) “用于大规模图像识别的甚深卷积网络”。 模型所需的最小输入大小为 32x32。
ResNet 公司¶
-
torchvision.models.
resnet18
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ 来自“Deep Residual Learning for Image Recognition”的 ResNet-18 模型。
使用 的示例 :
resnet18
-
torchvision.models.
resnet34
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ ResNet-34 模型,来自“Deep Residual Learning for Image Recognition”。
-
torchvision.models.
resnet50
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ 来自“Deep Residual Learning for Image Recognition”的 ResNet-50 模型。
-
torchvision.models.
resnet101
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ ResNet-101 模型,来自“Deep Residual Learning for Image Recognition”。
SqueezeNet (挤压网)¶
-
torchvision.models.
squeezenet1_0
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.squeezenet.SqueezeNet[来源]¶ SqueezeNet 模型架构来自“SqueezeNet:AlexNet 级别 精度,参数减少 50 倍,<0.5MB 模型大小“纸张。 模型所需的最小输入大小为 21x21。
密集网¶
-
torchvision.models.
densenet121
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.densenet.DenseNet[来源]¶ 来自 “Densely Connected Convolutional Networks” 的 Densenet-121 模型。 模型所需的最小输入大小为 29x29。
-
torchvision.models.
densenet169
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.densenet.DenseNet[来源]¶ 来自 “Densely Connected Convolutional Networks” 的 Densenet-169 模型。 模型所需的最小输入大小为 29x29。
-
torchvision.models.
densenet161
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.densenet.DenseNet[来源]¶ 来自 “Densely Connected Convolutional Networks” 的 Densenet-161 模型。 模型所需的最小输入大小为 29x29。
初始 v3¶
-
torchvision.models.
inception_v3
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.inception.Inception3[来源]¶ “重新思考计算机视觉的 Inception 体系结构”中的 Inception v3 模型体系结构。 模型所需的最小输入大小为 75x75。
注意
重要提示:与其他模型相比,inception_v3 期望的张量大小为 N x 3 x 299 x 299,因此请确保您的图像大小相应。
注意
这需要安装 scipy
谷歌网¶
-
torchvision.models.
googlenet
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.googlenet.GoogLeNet[来源]¶ GoogLeNet (Inception v1) 模型架构,来自 “Going Deeper with Convolutions” 的模型架构。 模型所需的最小输入大小为 15x15。
注意
这需要安装 scipy
ShuffleNet v2 版本¶
-
torchvision.models.
shufflenet_v2_x0_5
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.shufflenetv2.ShuffleNetV2[来源]¶ 构造具有 0.5x 输出通道的 ShuffleNetV2,如“ShuffleNet V2:高效 CNN 架构设计的实用指南”中所述。
-
torchvision.models.
shufflenet_v2_x1_0
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.shufflenetv2.ShuffleNetV2[来源]¶ 构造具有 1.0x 输出通道的 ShuffleNetV2,如“ShuffleNet V2:高效 CNN 架构设计的实用指南”中所述。
-
torchvision.models.
shufflenet_v2_x1_5
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.shufflenetv2.ShuffleNetV2[来源]¶ 构造具有 1.5x 输出通道的 ShuffleNetV2,如“ShuffleNet V2:高效 CNN 架构设计的实用指南”中所述。
-
torchvision.models.
shufflenet_v2_x2_0
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.shufflenetv2.ShuffleNetV2[来源]¶ 构造具有 2.0x 输出通道的 ShuffleNetV2,如“ShuffleNet V2:高效 CNN 体系结构设计的实用指南”中所述。
MobileNet v2 版本¶
-
torchvision.models.
mobilenet_v2
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mobilenetv2.MobileNetV2[来源]¶ 根据 “MobileNetV2: Inverted Residuals and Linear Bottlenecks” 构建 MobileNetV2 架构。
MobileNet v3 版本¶
-
torchvision.models.
mobilenet_v3_large
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mobilenetv3.MobileNetV3[来源]¶ 从 “Searching for MobileNetV3” 构建一个大型 MobileNetV3 架构。
-
torchvision.models.
mobilenet_v3_small
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mobilenetv3.MobileNetV3[来源]¶ 从 “Searching for MobileNetV3” 构建一个小型的 MobileNetV3 架构。
Res下一页¶
-
torchvision.models.
resnext50_32x4d
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ ResNeXt-50 32x4d 模型,来自“Aggregated Residual Transformation for Deep Neural Networks”。
-
torchvision.models.
resnext101_32x8d
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ ResNeXt-101 32x8d 模型,来自“Aggregated Residual Transformation for Deep Neural Networks”。
宽 ResNet¶
-
torchvision.models.
wide_resnet50_2
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ 来自 “Wide Residual Networks” 的 Wide ResNet-50-2 模型。
该模型与 ResNet 相同,只是通道数存在瓶颈 在每个区块中,它的大小是两倍。外部 1x1 中的通道数 卷积是相同的,例如 ResNet-50 中的最后一个块有 2048-512-2048 频道,在 Wide ResNet-50-2 中有 2048-1024-2048。
-
torchvision.models.
wide_resnet101_2
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.resnet.ResNet[来源]¶ 来自 “Wide Residual Networks” 的 Wide ResNet-101-2 模型。
该模型与 ResNet 相同,只是通道数存在瓶颈 在每个区块中,它的大小是两倍。外部 1x1 中的通道数 卷积是相同的,例如 ResNet-50 中的最后一个块有 2048-512-2048 频道,在 Wide ResNet-50-2 中有 2048-1024-2048。
MNASNet¶
-
torchvision.models.
mnasnet0_5
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mnasnet.MNASNet[来源]¶ 来自“MnasNet:移动平台感知神经架构搜索”的深度乘数为 0.5 的 MNASNet。
-
torchvision.models.
mnasnet0_75
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mnasnet.MNASNet[来源]¶ 来自“MnasNet:移动平台感知神经架构搜索”的深度乘数为 0.75 的 MNASNet。
-
torchvision.models.
mnasnet1_0
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.mnasnet.MNASNet[来源]¶ 来自“MnasNet:移动平台感知神经架构搜索”的深度乘数为 1.0 的 MNASNet。
EfficientNet (高效网络)¶
-
torchvision.models.
efficientnet_b0
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据 “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” 构建 EfficientNet B0 架构。
-
torchvision.models.
efficientnet_b1
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据 “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” 构建 EfficientNet B1 架构。
-
torchvision.models.
efficientnet_b2
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据“EfficientNet:重新思考卷积神经网络的模型扩展”构建 EfficientNet B2 架构。
-
torchvision.models.
efficientnet_b3
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据“EfficientNet:重新思考卷积神经网络的模型扩展”构建 EfficientNet B3 架构。
-
torchvision.models.
efficientnet_b4
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据 “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” 构建 EfficientNet B4 架构。
-
torchvision.models.
efficientnet_b5
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据 “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” 构建 EfficientNet B5 架构。
-
torchvision.models.
efficientnet_b6
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据 “EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks” 构建 EfficientNet B6 架构。
-
torchvision.models.
efficientnet_b7
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.efficientnet.EfficientNet[来源]¶ 根据“EfficientNet:重新思考卷积神经网络的模型扩展”构建 EfficientNet B7 架构。
RegNet 公司¶
-
torchvision.models.
regnet_y_400mf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建一个 RegNetY_400MF 架构。
-
torchvision.models.
regnet_y_800mf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建RegNetY_800MF架构。
-
torchvision.models.
regnet_y_1_6gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建 RegNetY_1.6GF 架构。
-
torchvision.models.
regnet_y_3_2gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建 RegNetY_3.2GF 架构。
-
torchvision.models.
regnet_y_8gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建一个 RegNetY_8GF 架构。
-
torchvision.models.
regnet_y_16gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建RegNetY_16GF架构。
-
torchvision.models.
regnet_y_32gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建一个 RegNetY_32GF 架构。
-
torchvision.models.
regnet_x_400mf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建RegNetX_400MF架构。
-
torchvision.models.
regnet_x_800mf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建RegNetX_800MF架构。
-
torchvision.models.
regnet_x_1_6gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建 RegNetX_1.6GF 架构。
-
torchvision.models.
regnet_x_3_2gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建 RegNetX_3.2GF 架构。
-
torchvision.models.
regnet_x_8gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “设计网络设计空间” 构建RegNetX_8GF架构。
-
torchvision.models.
regnet_x_16gf
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.regnet.RegNet[来源]¶ 从 “Designing Network Design Spaces” 构建RegNetX_16GF架构。
量化模型¶
以下架构支持 INT8 量化模型。您可以获得 通过调用其构造函数来获得具有随机权重的模型:
import torchvision.models as models
googlenet = models.quantization.googlenet()
inception_v3 = models.quantization.inception_v3()
mobilenet_v2 = models.quantization.mobilenet_v2()
mobilenet_v3_large = models.quantization.mobilenet_v3_large()
resnet18 = models.quantization.resnet18()
resnet50 = models.quantization.resnet50()
resnext101_32x8d = models.quantization.resnext101_32x8d()
shufflenet_v2_x0_5 = models.quantization.shufflenet_v2_x0_5()
shufflenet_v2_x1_0 = models.quantization.shufflenet_v2_x1_0()
shufflenet_v2_x1_5 = models.quantization.shufflenet_v2_x1_5()
shufflenet_v2_x2_0 = models.quantization.shufflenet_v2_x2_0()
只需几行代码即可获得预训练的量化模型:
import torchvision.models as models
model = models.quantization.mobilenet_v2(pretrained=True, quantize=True)
model.eval()
# run the model with quantized inputs and weights
out = model(torch.rand(1, 3, 224, 224))
我们为以下模型提供预训练的量化权重:
型 |
Acc@1 |
Acc@5 |
---|---|---|
移动网络 V2 |
71.658 |
90.150 |
MobileNet V3 大型版 |
73.004 |
90.858 |
随机播放网 V2 |
68.360 |
87.582 |
ResNet 18 系列 |
69.494 |
88.882 |
ResNet 50 系列 |
75.920 |
92.814 |
ResNext 101 32x8d |
78.986 |
94.480 |
初始版本 V3 |
77.176 |
93.354 |
谷歌网络 |
69.826 |
89.404 |
语义分割¶
models 子包包含以下模型的定义 语义分割的架构:
与图像分类模型一样,所有预先训练的模型都希望输入图像以相同的方式进行标准化。
必须将图像加载到一个范围内,然后使用 和 进行标准化。
他们已经接受了调整大小的图像的训练,因此其最小大小为 520。[0, 1]
mean = [0.485, 0.456, 0.406]
std = [0.229, 0.224, 0.225]
有关如何绘制此类模型的掩码的详细信息,您可以参考语义分割模型。
预训练模型已在 COCO train2017 的一个子集上进行了训练,训练了 20 个类别,这些类别是
存在于 Pascal VOC 数据集中。您可以在 中查看有关如何选择子集的更多信息。预训练模型输出的类如下:
挨次:references/segmentation/coco_utils.py
['__background__', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
在 COCO val2017 上评估的预训练模型的准确性如下
网络 |
均值 IoU |
全局像素 ACC |
---|---|---|
FCN ResNet50 |
60.5 |
91.4 |
FCN ResNet101 |
63.7 |
91.9 |
DeepLabV3 ResNet50 |
66.4 |
92.4 |
DeepLabV3 ResNet101 |
67.4 |
92.4 |
DeepLabV3 MobileNetV3-大型 |
60.3 |
91.2 |
LR-ASPP MobileNetV3-Large |
57.9 |
91.2 |
全卷积网络¶
-
torchvision.models.segmentation.
fcn_resnet50
(预训练:bool = False,进度:bool = True,num_classes:int = 21,aux_loss:可选[bool] = None,**kwargs: Any)→ torch.nn.modules.module.Module[源]¶ 构建具有 ResNet-50 主干的全卷积网络模型。
- 参数
使用 的示例 :
fcn_resnet50
深度实验室 V3¶
-
torchvision.models.segmentation.
deeplabv3_resnet50
(预训练:bool = False,进度:bool = True,num_classes:int = 21,aux_loss:可选[bool] = None,**kwargs: Any)→ torch.nn.modules.module.Module[源]¶ 构建具有 ResNet-50 主干的 DeepLabV3 模型。
- 参数
使用 的示例 :
deeplabv3_resnet50
-
torchvision.models.segmentation.
deeplabv3_resnet101
(预训练:bool = False,进度:bool = True,num_classes:int = 21,aux_loss:可选[bool] = None,**kwargs: Any)→ torch.nn.modules.module.Module[源]¶ 构建具有 ResNet-101 主干的 DeepLabV3 模型。
对象检测、实例分割和人员关键点检测¶
models 子包包含以下模型的定义 检测架构:
用于检测、实例分割和 关键点检测使用分类模型进行初始化 在 TorchVision 中。
模型需要 范围 中的 , 列表。
模型在内部调整图像大小,但行为会有所不同
在模型上。检查模型的构造器以获取更多信息。这
此类模型的输出格式在 实例分段模型.Tensor[C, H, W]
0-1
对于对象检测和实例分割,预训练的 模型返回以下类的预测:
COCO_INSTANCE_CATEGORY_NAMES = [ '__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'N/A', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'N/A', 'backpack', 'umbrella', 'N/A', 'N/A', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'N/A', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'N/A', 'dining table', 'N/A', 'N/A', 'toilet', 'N/A', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'N/A', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush' ]
以下是 上训练的模型的准确度摘要 COCO train2017 的实例集,并在 COCO val2017 上评估。
网络 |
盒式 AP |
掩码 AP |
关键点 AP |
---|---|---|---|
更快的 R-CNN ResNet-50 FPN |
37.0 |
||
更快的 R-CNN MobileNetV3-Large FPN |
32.8 |
||
更快的 R-CNN MobileNetV3-Large 320 FPN |
22.8 |
||
RetinaNet ResNet-50 FPN |
36.4 |
||
SSD300 VGG16 |
25.1 |
||
SSDlite320 MobileNetV3-大型 |
21.3 |
||
掩码 R-CNN ResNet-50 FPN |
37.9 |
34.6 |
对于人员关键点检测,预训练的 型号如下
网络 |
盒式 AP |
掩码 AP |
关键点 AP |
---|---|---|---|
关键点 R-CNN ResNet-50 FPN |
54.6 |
65.0 |
对于人员关键点检测,预训练模型返回 keypoints 按以下顺序排列:
COCO_PERSON_KEYPOINT_NAMES = [ 'nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear', 'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow', 'left_wrist', 'right_wrist', 'left_hip', 'right_hip', 'left_knee', 'right_knee', 'left_ankle', 'right_ankle' ]
运行时特性¶
对象检测、实例分割模型的实现 和关键点检测都非常高效。
在下表中,我们使用 8 个 GPU 来报告结果。在训练期间, 对于所有模型,我们使用每个 GPU 2 的批处理大小,但 SSD 除外,它使用 4 和 SSDlite 使用 24.在测试期间,使用批量大小 1。
对于测试时间,我们报告模型评估和后处理的时间 (包括图像中的蒙版粘贴),但不包括计算 precision-recall 调用。
网络 |
火车时间 (S / IT) |
考试时间 (S / It) |
内存 (GB) |
---|---|---|---|
更快的 R-CNN ResNet-50 FPN |
0.2288 |
0.0590 |
5.2 |
更快的 R-CNN MobileNetV3-Large FPN |
0.1020 |
0.0415 |
1.0 |
更快的 R-CNN MobileNetV3-Large 320 FPN |
0.0978 |
0.0376 |
0.6 |
RetinaNet ResNet-50 FPN |
0.2514 |
0.0939 |
4.1 |
SSD300 VGG16 |
0.2093 |
0.0744 |
1.5 |
SSDlite320 MobileNetV3-大型 |
0.1773 |
0.0906 |
1.5 |
掩码 R-CNN ResNet-50 FPN |
0.2728 |
0.0903 |
5.4 |
关键点 R-CNN ResNet-50 FPN |
0.3789 |
0.1242 |
6.8 |
更快的 R-CNN¶
-
torchvision.models.detection.
fasterrcnn_resnet50_fpn
(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=无,**kwargs)[来源]¶ 构建一个具有 ResNet-50-FPN 主干的 Faster R-CNN 模型。
参考资料:“更快的 R-CNN:迈向实时对象检测 区域提案网络”。
模型的输入应是一个张量列表,每个张量的形状为 ,每个张量对应一个 image 的 URL,并且应该在范围内。不同的图像可以具有不同的大小。
[C, H, W]
0-1
模型的行为会发生变化,具体取决于它是处于训练模式还是评估模式。
在训练期间,模型需要输入张量以及目标(字典列表)、 含:
框 ():格式为 和 的真实框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个 ground-truth 框的类标签
Int64Tensor[N]
模型在训练期间返回一个,其中包含分类和回归 RPN 和 R-CNN 的损失。
Dict[Tensor]
在推理过程中,模型只需要输入张量,并返回后处理的 predictions 作为 ,每个输入图像对应一个。的字段为 follows,其中 是检测数量:
List[Dict[Tensor]]
Dict
N
框 ():格式为 和 的预测框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个检测的预测标签
Int64Tensor[N]
scores ():每次检测的分数
Tensor[N]
有关输出的更多详细信息,您可以参考 实例分割模型.
更快的 R-CNN 可导出到 ONNX,以获得固定的批量大小,并带有固定大小的输入图像。
例:
>>> model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) >>> # For training >>> images, boxes = torch.rand(4, 3, 600, 1200), torch.rand(4, 11, 4) >>> labels = torch.randint(1, 91, (4, 11)) >>> images = list(image for image in images) >>> targets = [] >>> for i in range(len(images)): >>> d = {} >>> d['boxes'] = boxes[i] >>> d['labels'] = labels[i] >>> targets.append(d) >>> output = model(images, targets) >>> # For inference >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x) >>> >>> # optionally, if you want to export the model to ONNX: >>> torch.onnx.export(model, x, "faster_rcnn.onnx", opset_version = 11)
- 参数
使用 的示例 :
fasterrcnn_resnet50_fpn
-
torchvision.models.detection.
fasterrcnn_mobilenet_v3_large_fpn
(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=无,**kwargs)[来源]¶ 使用 MobileNetV3-Large FPN 主干构建高分辨率 Faster R-CNN 模型。 它的工作原理类似于带有 ResNet-50 FPN 主干的 Faster R-CNN。查看更多
详。
例:
>>> model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_fpn(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x)
- 参数
-
torchvision.models.detection.
fasterrcnn_mobilenet_v3_large_320_fpn
(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=无,**kwargs)[来源]¶ 构建一个低分辨率更快的 R-CNN 模型,其中包含针对移动用例调整的 MobileNetV3-Large FPN 主干。 它的工作原理类似于带有 ResNet-50 FPN 主干的 Faster R-CNN。查看更多
详。
例:
>>> model = torchvision.models.detection.fasterrcnn_mobilenet_v3_large_320_fpn(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x)
- 参数
RetinaNet¶
-
torchvision.models.detection.
retinanet_resnet50_fpn
(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=无,**kwargs)[来源]¶ 构建具有 ResNet-50-FPN 主干的 RetinaNet 模型。
参考:“密集对象检测的焦点损失”。
模型的输入应是一个张量列表,每个张量的形状为 ,每个张量对应一个 image 的 URL,并且应该在范围内。不同的图像可以具有不同的大小。
[C, H, W]
0-1
模型的行为会发生变化,具体取决于它是处于训练模式还是评估模式。
在训练期间,模型需要输入张量以及目标(字典列表)、 含:
框 ():格式为 和 的真实框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个 ground-truth 框的类标签
Int64Tensor[N]
模型在训练期间返回一个,其中包含分类和回归 损失。
Dict[Tensor]
在推理过程中,模型只需要输入张量,并返回后处理的 predictions 作为 ,每个输入图像对应一个。的字段为 follows,其中 是检测数量:
List[Dict[Tensor]]
Dict
N
框 ():格式为 和 的预测框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个检测的预测标签
Int64Tensor[N]
scores ():每次检测的分数
Tensor[N]
有关输出的更多详细信息,您可以参考 实例分割模型.
例:
>>> model = torchvision.models.detection.retinanet_resnet50_fpn(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x)
- 参数
使用 的示例 :
retinanet_resnet50_fpn
固态硬盘¶
-
torchvision.models.detection.
ssd300_vgg16
(预训练:bool = False,进度:bool = True,num_classes:int = 91,pretrained_backbone:bool = True,trainable_backbone_layers:可选[int] = 无,**kwargs: 任何)[来源]¶ 构建一个输入大小为 300x300 和 VGG16 主干的 SSD 模型。
参考:“SSD:Single Shot MultiBox 检测器”。
模型的输入应是一个张量列表,每个张量的形状为 [C, H, W],每个张量对应一个张量 image,并且应该在 0-1 范围内。不同的图像可以有不同的大小,但它们的大小会调整 移动到固定大小,然后再将其传递给 backbone 。
模型的行为会发生变化,具体取决于它是处于训练模式还是评估模式。
在训练期间,模型需要输入张量以及目标(字典列表)、 含:
框 ():格式为 和 的真实框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels (Int64Tensor[N]):每个真实框的类标签
模型在训练期间返回一个 Dict[Tensor],其中包含分类和回归 损失。
在推理过程中,模型只需要输入张量,并返回后处理的 predictions 作为 List[Dict[Tensor]],每个输入图像一个。Dict 的字段为 follows,其中 是检测数量:
N
框 ():格式为 和 的预测框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels (Int64Tensor[N]):每次检测的预测标签
scores (Tensor[N]):每次检测的分数
例
>>> model = torchvision.models.detection.ssd300_vgg16(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 300), torch.rand(3, 500, 400)] >>> predictions = model(x)
- 参数
使用 的示例 :
ssd300_vgg16
SSDlite的¶
-
torchvision.models.detection.
ssdlite320_mobilenet_v3_large
(预训练:bool = False,进度:bool = True,num_classes:int = 91, pretrained_backbone: bool = False, trainable_backbone_layers: Optional[int] = None, norm_layer: 可选[Callable[[...], torch.nn.modules.module.Module]] = None, **kwargs: Any)[来源]¶ 构造一个输入大小为 320x320 和 MobileNetV3 大型主干网的 SSDlite 模型,如“搜索 MobileNetV3”和“MobileNetV2:反转残差和线性瓶颈”中所述。
例
>>> model = torchvision.models.detection.ssdlite320_mobilenet_v3_large(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 320, 320), torch.rand(3, 500, 400)] >>> predictions = model(x)
- 参数
pretrained (bool) – 如果为 True,则返回在 COCO train2017 上预训练的模型
progress (bool) – 如果为 True,则显示下载到 stderr 的进度条
num_classes (int) – 模型的输出类数量(包括背景)
pretrained_backbone (bool) – 如果为 True,则返回在 Imagenet 上预训练了主干的模型
trainable_backbone_layers (int) – 从最终块开始的可训练(未冻结)resnet 层的数量。 有效值介于 0 和 6 之间,其中 6 表示所有主干层都是可训练的。
norm_layer (可调用,可选) – 指定要使用的规范化层的模块。
使用 的示例 :
ssdlite320_mobilenet_v3_large
掩码 R-CNN¶
-
torchvision.models.detection.
maskrcnn_resnet50_fpn
(pretrained=False, progress=True, num_classes=91, pretrained_backbone=True, trainable_backbone_layers=无,**kwargs)[来源]¶ 构建具有 ResNet-50-FPN 主干的掩码 R-CNN 模型。
参考:“掩码 R-CNN”。
模型的输入应是一个张量列表,每个张量的形状为 ,每个张量对应一个 image 的 URL,并且应该在范围内。不同的图像可以具有不同的大小。
[C, H, W]
0-1
模型的行为会发生变化,具体取决于它是处于训练模式还是评估模式。
在训练期间,模型需要输入张量以及目标(字典列表)、 含:
框 ():格式为 和 的真实框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个 ground-truth 框的类标签
Int64Tensor[N]
masks ():每个实例的分段二进制掩码
UInt8Tensor[N, H, W]
模型在训练期间返回一个,其中包含分类和回归 RPN 和 R-CNN 的损失,以及掩码损失。
Dict[Tensor]
在推理过程中,模型只需要输入张量,并返回后处理的 predictions 作为 ,每个输入图像对应一个。的字段为 下面,其中 是检测到的实例数:
List[Dict[Tensor]]
Dict
N
框 ():格式为 和 的预测框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个实例的预测标签
Int64Tensor[N]
scores () ():分数或每个实例
Tensor[N]
masks ():范围内每个实例的预测掩码。为了 获取最终的分割掩码,通常可以对软掩码进行阈值处理 值为 0.5 (
UInt8Tensor[N, 1, H, W]
0-1
mask >= 0.5
)
有关输出以及如何绘制掩码的更多详细信息,您可以参考实例分割模型。
掩码 R-CNN 可导出到 ONNX,以获得固定的批量大小和固定大小的输入图像。
例:
>>> model = torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x) >>> >>> # optionally, if you want to export the model to ONNX: >>> torch.onnx.export(model, x, "mask_rcnn.onnx", opset_version = 11)
- 参数
使用 的示例 :
maskrcnn_resnet50_fpn
关键点 R-CNN¶
-
torchvision.models.detection.
keypointrcnn_resnet50_fpn
(pretrained=False, progress=True, num_classes=2, num_keypoints=17, pretrained_backbone=True, trainable_backbone_layers=None, **kwargs)[来源]¶ 构建具有 ResNet-50-FPN 主干的关键点 R-CNN 模型。
参考:“掩码 R-CNN”。
模型的输入应是一个张量列表,每个张量的形状为 ,每个张量对应一个 image 的 URL,并且应该在范围内。不同的图像可以具有不同的大小。
[C, H, W]
0-1
模型的行为会发生变化,具体取决于它是处于训练模式还是评估模式。
在训练期间,模型需要输入张量以及目标(字典列表)、 含:
框 ():格式为 和 的真实框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个 ground-truth 框的类标签
Int64Tensor[N]
关键点 ():每个实例的关键点位置,位于 format ,其中 key point 不可见。
FloatTensor[N, K, 3]
K
N
[x, y, visibility]
visibility=0
模型在训练期间返回一个,其中包含分类和回归 RPN 和 R-CNN 的损失,以及关键点的损失。
Dict[Tensor]
在推理过程中,模型只需要输入张量,并返回后处理的 predictions 作为 ,每个输入图像对应一个。的字段为 下面,其中 是检测到的实例数:
List[Dict[Tensor]]
Dict
N
框 ():格式为 和 的预测框。
FloatTensor[N, 4]
[x1, y1, x2, y2]
0 <= x1 < x2 <= W
0 <= y1 < y2 <= H
labels ():每个实例的预测标签
Int64Tensor[N]
scores () ():分数或每个实例
Tensor[N]
关键点 ():预测关键点的位置,格式为。
FloatTensor[N, K, 3]
[x, y, v]
有关输出的更多详细信息,您可以参考 实例分割模型.
Keypoint R-CNN 可导出到 ONNX,以获得固定的批量大小,并带有固定大小的输入图像。
例:
>>> model = torchvision.models.detection.keypointrcnn_resnet50_fpn(pretrained=True) >>> model.eval() >>> x = [torch.rand(3, 300, 400), torch.rand(3, 500, 400)] >>> predictions = model(x) >>> >>> # optionally, if you want to export the model to ONNX: >>> torch.onnx.export(model, x, "keypoint_rcnn.onnx", opset_version = 11)
- 参数
pretrained (bool) – 如果为 True,则返回在 COCO train2017 上预训练的模型
progress (bool) – 如果为 True,则显示下载到 stderr 的进度条
num_classes (int) – 模型的输出类数量(包括背景)
num_keypoints (int) – 关键点数量,默认为 17
pretrained_backbone (bool) – 如果为 True,则返回在 Imagenet 上预训练了主干的模型
trainable_backbone_layers (int) – 从最终块开始的可训练(未冻结)resnet 层的数量。 有效值介于 0 和 5 之间,其中 5 表示所有主干层都是可训练的。
使用 的示例 :
keypointrcnn_resnet50_fpn
视频分类¶
我们提供在 Kinetics-400 上预训练的动作识别模型。
他们都已使用 中提供的脚本进行了训练。references/video_classification
所有预训练模型都期望以相同的方式对输入图像进行归一化。
即形状为 (3 x T x H x W) 的 3 通道 RGB 视频的小批量,
其中 H 和 W 应为 112,T 是剪辑中的视频帧数。
图像必须加载到 [0, 1] 范围内,然后进行标准化
using 和 .mean = [0.43216, 0.394666, 0.37645]
std = [0.22803, 0.22145, 0.216989]
注意
归一化参数与图像分类参数不同,并对应 到 Kinetics-400 的平均值和 std。
注意
目前,规范化代码可以在 中找到。
请参阅那里的函数。请注意,它与
图像,因为它假定视频是 4D 的。references/video_classification/transforms.py
Normalize
剪辑长度 16 (16x112x112) 的 Kinetics 1-crop 精度
网络 |
剪辑acc@1 |
剪辑acc@5 |
---|---|---|
ResNet 3D 18 |
52.75 |
75.45 |
ResNet MC 18 系列 |
53.90 |
76.29 |
ResNet (2+1)D |
57.50 |
78.81 |
ResNet 3D 分辨率¶
-
torchvision.models.video.
r3d_18
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.video.resnet.VideoResNet[来源]¶ 构建 18 层 Resnet3D 模型,如 https://arxiv.org/abs/1711.11248
ResNet 混合卷积¶
-
torchvision.models.video.
mc3_18
(pretrained: bool = False, progress: bool = True, **kwargs: Any) → torchvision.models.video.resnet.VideoResNet[来源]¶ 18 层混合卷积网络的构造函数,如 https://arxiv.org/abs/1711.11248