There are some built in models in torchvision.models, such as vgg or resnet. The same page also record a table about the Top1 & Top5 errors of different architecture. However, the parameter size of different models is missing, so I write a program and complement the table.

Network Top-1 error Top-5 error Parameters size
AlexNet 43.45 20.91 61,100,840
VGG-11 30.98 11.37 132,863,336
VGG-13 30.07 10.75 133,047,848
VGG-16 28.41 9.62 138,357,544
VGG-19 27.62 9.12 143,678,248
VGG-11 with BN 29.62 10.19 132,868,840
VGG-13 with BN 28.45 9.63 133,053,736
VGG-16 with BN 26.63 8.50 138,365,992
VGG-19 with BN 25.76 8.15 143,667,240
ResNet-18 30.24 10.92 11,689,512
ResNet-34 26.70 8.58 21,797,672
ResNet-50 23.85 7.13 25,557,032
ResNet-101 22.63 6.44 44,549,160
ResNet-152 21.69 5.94 60,192,808
SqueezeNet 1.0 41.90 19.58 1,248,424
SqueezeNet 1.1 41.81 19.38 1,235,496
Densenet-121 25.35 7.83 7,978,856
Densenet-169 24.00 7.00 28,681,000
Densenet-201 22.80 6.43 14,149,480
Densenet-161 22.35 6.20 20,013,928
Inception v3 22.55 6.44 27,161,264

The code is inspired by pytorch forum, I’ll record my code as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import torch
import torchvision.models as models

alexnet = models.alexnet(pretrained=False)
vgg11 = models.vgg11(pretrained=False)
vgg11_bn = models.vgg11_bn(pretrained=False)
vgg13 = models.vgg13(pretrained=False)
vgg13_bn = models.vgg13_bn(pretrained=False)
vgg16 = models.vgg16(pretrained=False)
vgg16_bn = models.vgg16_bn(pretrained=False)
vgg19 = models.vgg19(pretrained=False)
vgg19_bn = models.vgg19_bn(pretrained=False)
resnet18 = models.resnet18(pretrained=False)
resnet34 = models.resnet34(pretrained=False)
resnet50 = models.resnet50(pretrained=False)
resnet101 = models.resnet101(pretrained=False)
resnet152 = models.resnet152(pretrained=False)
squeezenet1_0 = models.squeezenet1_0(pretrained=False)
squeezenet1_1 = models.squeezenet1_1(pretrained=False)
densenet121 = models.densenet121(pretrained=False)
densenet161 = models.densenet161(pretrained=False)
densenet169 = models.densenet169(pretrained=False)
densenet201 = models.densenet201(pretrained=False)
inception = models.inception_v3(pretrained=False)

print("alexnet parameter num: {0}".format(count_parameters(alexnet)))
print("vgg11 parameter num: {0}".format(count_parameters(vgg11)))
print("vgg11_bn parameter num: {0}".format(count_parameters(vgg11_bn)))
print("vgg13 parameter num: {0}".format(count_parameters(vgg13)))
print("vgg13_bn parameter num: {0}".format(count_parameters(vgg13_bn)))
print("vgg16 parameter num: {0}".format(count_parameters(vgg16)))
print("vgg16_bn parameter num: {0}".format(count_parameters(vgg16_bn)))
print("vgg19 parameter num: {0}".format(count_parameters(vgg19_bn)))
print("vgg19_bn parameter num: {0}".format(count_parameters(vgg19)))
print("resnet18 parameter num: {0}".format(count_parameters(resnet18)))
print("resnet34 parameter num: {0}".format(count_parameters(resnet34)))
print("resnet50 parameter num: {0}".format(count_parameters(resnet50)))
print("resnet101 parameter num: {0}".format(count_parameters(resnet101)))
print("resnet152 parameter num: {0}".format(count_parameters(resnet152)))
print("squeezenet1_0 parameter num: {0}".format(count_parameters(squeezenet1_0)))
print("squeezenet1_1 parameter num: {0}".format(count_parameters(squeezenet1_1)))
print("densenet121 parameter num: {0}".format(count_parameters(densenet121)))
print("densenet161 parameter num: {0}".format(count_parameters(densenet161)))
print("densenet169 parameter num: {0}".format(count_parameters(densenet169)))
print("densenet201 parameter num: {0}".format(count_parameters(densenet201)))
print("inceptionv3 parameter num: {0}".format(count_parameters(inception)))

def count_parameters(model):
return sum(p.numel() for p in model.parameters() if p.requires_grad)


Comments

2019-02-23