ImageNet 预训练模型的推断吞吐量与验证准确率的可视化如下图所示。吞吐量是在单块 V100 GPU 和批量大小为 64 的条件下测量的。

../_images/plot_help.png 分类 - GluonCV 文档

如何使用预训练模型

  • 以下示例需要 GluonCV>=0.4MXNet>=1.4.0。如有必要,请遵循 我们的安装指南 来安装或升级 GluonCV 和 MXNet。

  • 请自行准备一张图片或使用 我们的示例图片。您可以将图片保存到工作目录中,文件名为 classification-demo.png;如果您使用其他文件名,请修改源代码中的文件名。

  • 使用预训练模型。模型由其名称指定。

我们来试试吧!

import mxnet as mx
import gluoncv

# you can change it to your image filename
filename = 'classification-demo.png'
# you may modify it to switch to another model. The name is case-insensitive
model_name = 'ResNet50_v1d'
# download and load the pre-trained model
net = gluoncv.model_zoo.get_model(model_name, pretrained=True)
# load image
img = mx.image.imread(filename)
# apply default data preprocessing
transformed_img = gluoncv.data.transforms.presets.imagenet.transform_eval(img)
# run forward pass to obtain the predicted score for each class
pred = net(transformed_img)
# map predicted values to probability by softmax
prob = mx.nd.softmax(pred)[0].asnumpy()
# find the 5 class indices with the highest score
ind = mx.nd.topk(pred, k=5)[0].astype('int').asnumpy().tolist()
# print the class name and predicted probability
print('The input picture is classified to be')
for i in range(5):
    print('- [%s], with probability %.3f.'%(net.classes[ind[i]], prob[ind[i]]))

我们的 示例图片 的预期输出为

The input picture is classified to be
- [Welsh springer spaniel], with probability 0.899.
- [Irish setter], with probability 0.005.
- [Brittany spaniel], with probability 0.003.
- [cocker spaniel], with probability 0.002.
- [Blenheim spaniel], with probability 0.002.

记住,您可以通过替换 model_name 的值来尝试不同的模型。请继续阅读表格,了解模型名称及其性能。

ImageNet

提示

训练命令适用于此脚本

下载 train_imagenet.py

模型可以拥有不同训练参数的不同哈希标签。带有灰色名称的参数可以通过传入相应的哈希标签来下载。

  • 下载默认预训练权重:net = get_model('ResNet50_v1d', pretrained=True)

  • 下载给定哈希标签的权重:net = get_model('ResNet50_v1d', pretrained='117a384e')

ResNet50_v1_int8MobileNet1.0_int8 是在 ImageNet 数据集上校准的量化模型。

ResNet

提示

  • ResNet50_v1_int8ResNet50_v1 的量化模型。

  • ResNet_v1bResNet_v1 的瓶颈块中修改了 3x3 层的步幅。

  • ResNet_v1c 修改了 ResNet_v1b,用三个 3x3 卷积层取代了 7x7 卷积层。

  • ResNet_v1d 修改了 ResNet_v1c,在残差路径上添加了一个步幅为 2 的 2x2 平均池化层,以保留更多信息。

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

ResNet18_v1 [1]_

70.93

89.92

a0666292

shell 脚本

日志

ResNet34_v1 [1]_

74.37

91.87

48216ba9

shell 脚本

日志

ResNet50_v1 [1]_

77.36

93.57

cc729d95

shell 脚本

日志

ResNet50_v1_int8 [1]_

76.86

93.46

cc729d95

ResNet101_v1 [1]_

78.34

94.01

d988c13d

shell 脚本

日志

ResNet152_v1 [1]_

79.22

94.64

acfd0970

shell 脚本

日志

ResNet18_v1b [1]_

70.94

89.83

2d9d980c

shell 脚本

日志

ResNet34_v1b [1]_

74.65

92.08

8e16b848

shell 脚本

日志

ResNet50_v1b [1]_

77.67

93.82

0ecdba34

shell 脚本

日志

ResNet50_v1b_gn [1]_

77.36

93.59

0ecdba34

shell 脚本

日志

ResNet101_v1b [1]_

79.20

94.61

a455932a

shell 脚本

日志

ResNet152_v1b [1]_

79.69

94.74

a5a61ee1

shell 脚本

日志

ResNet50_v1c [1]_

78.03

94.09

2a4e0708

shell 脚本

日志

ResNet101_v1c [1]_

79.60

94.75

064858f2

shell 脚本

日志

ResNet152_v1c [1]_

80.01

94.96

75babab6

shell 脚本

日志

ResNet50_v1d [1]_

79.15

94.58

117a384e

shell 脚本

日志

ResNet50_v1d [1]_

78.48

94.20

00319ddc

shell 脚本

日志

ResNet101_v1d [1]_

80.51

95.12

1b2b825f

shell 脚本

日志

ResNet101_v1d [1]_

79.78

94.80

8659a9d6

shell 脚本

日志

ResNet152_v1d [1]_

80.61

95.34

cddbc86f

shell 脚本

日志

ResNet152_v1d [1]_

80.26

95.00

cfe0220d

shell 脚本

日志

ResNet18_v2 [2]_

71.00

89.92

a81db45f

shell 脚本

日志

ResNet34_v2 [2]_

74.40

92.08

9d6b80bb

shell 脚本

日志

ResNet50_v2 [2]_

77.11

93.43

ecdde353

shell 脚本

日志

ResNet101_v2 [2]_

78.53

94.17

18e93e4f

shell 脚本

日志

ResNet152_v2 [2]_

79.21

94.31

f2695542

shell 脚本

日志

ResNext

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

ResNext50_32x4d [12]_

79.32

94.53

4ecf62e2

shell 脚本

日志

ResNext101_32x4d [12]_

80.37

95.06

8654ca5d

shell 脚本

日志

ResNext101_64x4d_v1 [12]_

80.69

95.17

2f0d1c9d

shell 脚本

日志

SE_ResNext50_32x4d [12]_ [14]_

79.95

94.93

7906e0e1

shell 脚本

日志

SE_ResNext101_32x4d [12]_ [14]_

80.91

95.39

688e2389

shell 脚本

日志

SE_ResNext101_64x4d [12]_ [14]_

81.01

95.32

11c50114

shell 脚本

日志

ResNeSt

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

ResNeSt14 [17]_

75.75

92.70

7e0b0cae

shell 脚本

日志

ResNeSt26 [17]_

78.68

94.38

36459074

shell 脚本

ResNeSt50 [17]_

81.04

95.42

bcfefe1d

shell 脚本

日志

ResNeSt101 [17]_

82.83

96.42

5da943b3

shell 脚本

日志

ResNeSt200 [17]_

83.86

96.86

0c5d117d

shell 脚本

日志

ResNeSt269 [17]_

84.53

96.98

11ae7f5d

shell 脚本

日志

MobileNet

提示

  • MobileNet1.0_int8MobileNet1.0 的量化模型。

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

MobileNet1.0 [4]_

73.28

91.30

efbb2ca3

shell 脚本

日志

MobileNet1.0_int8 [4]_

72.85

90.99

efbb2ca3

MobileNet1.0 [4]_

72.93

91.14

cce75496

shell 脚本

日志

MobileNet0.75 [4]_

70.25

89.49

84c801e2

shell 脚本

日志

MobileNet0.5 [4]_

65.20

86.34

0130d2aa

shell 脚本

日志

MobileNet0.25 [4]_

52.91

76.94

f0046a3d

shell 脚本

日志

MobileNetV2_1.0 [5]_

72.04

90.57

f9952bcd

shell 脚本

日志

MobileNetV2_0.75 [5]_

69.36

88.50

b56e3d1c

shell 脚本

日志

MobileNetV2_0.5 [5]_

64.43

85.31

08038185

shell 脚本

日志

MobileNetV2_0.25 [5]_

51.76

74.89

9b1d2cc3

shell 脚本

日志

MobileNetV3_Large [15]_

75.32

92.30

eaa44578

shell 脚本

日志

MobileNetV3_Small [15]_

67.72

87.51

33c100a7

shell 脚本

日志

VGG

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

VGG11 [9]_

66.62

87.34

dd221b16

VGG13 [9]_

67.74

88.11

6bc5de58

VGG16 [9]_

73.23

91.31

e660d456

shell 脚本

日志

VGG19 [9]_

74.11

91.35

ad2f660d

shell 脚本

日志

VGG11_bn [9]_

68.59

88.72

ee79a809

VGG13_bn [9]_

68.84

88.82

7d97a06c

VGG16_bn [9]_

73.10

91.76

7f01cf05

shell 脚本

日志

VGG19_bn [9]_

74.33

91.85

f360b758

shell 脚本

日志

SqueezeNet

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

SqueezeNet1.0 [10]_

56.11

79.09

264ba497

SqueezeNet1.1 [10]_

54.96

78.17

33ba0f93

DenseNet

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

DenseNet121 [7]_

74.97

92.25

f27dbf2d

DenseNet161 [7]_

77.70

93.80

b6c8a957

DenseNet169 [7]_

76.17

93.17

2603f878

DenseNet201 [7]_

77.32

93.62

1cdbc116

剪枝 ResNet

模型

Top-1

Top-5

哈希标签

加速比 (相对于原始 ResNet)

resnet18_v1b_0.89

67.2

87.45

54f7742b

2倍

resnet50_v1d_0.86

78.02

93.82

a230c33f

1.68倍

resnet50_v1d_0.48

74.66

92.34

0d3e69bb

3.3倍

resnet50_v1d_0.37

70.71

89.74

9982ae49

5.01倍

resnet50_v1d_0.11

63.22

84.79

6a25eece

8.78倍

resnet101_v1d_0.76

79.46

94.69

a872796b

1.8倍

resnet101_v1d_0.73

78.89

94.48

712fccb1

2.02倍

其他

提示

InceptionV3 使用 299x299 输入尺寸进行评估。

模型

Top-1

Top-5

哈希标签

训练命令

训练日志

AlexNet [6]_

54.92

78.03

44335d1f

darknet53 [3]_

78.56

94.43

2189ea49

shell 脚本

日志

darknet53 [3]_

78.13

93.86

95975047

shell 脚本

日志

InceptionV3 [8]_

78.77

94.39

a5050dbc

shell 脚本

日志

GoogLeNet [16]_

72.87

91.17

c7c89366

shell 脚本

日志

Xception [8]_

79.56

94.77

37c1c90b

shell 脚本

日志

InceptionV3 [8]_

78.41

94.13

e132adf2

shell 脚本

日志

SENet_154 [14]_

81.26

95.51

b5538ef1

CIFAR10

下表列出了在 CIFAR10 上训练的预训练模型。

提示

我们的预训练模型复现了“Mix-Up” [13]_ 的结果。请查阅参考文献以获取更多信息。

表中的训练命令适用于以下脚本

模型

准确率 (传统训练/Mix-Up [13]_ )

训练命令

训练日志

CIFAR_ResNet20_v1 [1]_

92.1 / 92.9

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNet56_v1 [1]_

93.6 / 94.2

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNet110_v1 [1]_

93.0 / 95.2

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNet20_v2 [2]_

92.1 / 92.7

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNet56_v2 [2]_

93.7 / 94.6

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNet110_v2 [2]_

94.3 / 95.5

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_WideResNet16_10 [11]_

95.1 / 96.7

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_WideResNet28_10 [11]_

95.6 / 97.2

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_WideResNet40_8 [11]_

95.9 / 97.3

传统训练 / Mix-Up

传统训练 / Mix-Up

CIFAR_ResNeXt29_16x64d [12]_

96.3 / 97.3

传统训练 / Mix-Up

传统训练 / Mix-Up