Flops counter for convolutional networks in pytorch framework
该脚本旨在计算卷积神经网络中理论乘积运算的数量。 它还可以计算参数的数量并打印给定网络的每层计算成本,使用起来非常简单。
安装
1
| pip install --upgrade git+https://github.com/sovrasov/flops-counter.pytorch.git
|
测试
1 2 3 4 5 6 7 8 9 10
| import torchvision.models as models import torch from ptflops import get_model_complexity_info
with torch.cuda.device(0): net = models.densenet161() macs, params = get_model_complexity_info(net, (3, 224, 224), as_strings=True, print_per_layer_stat=True, verbose=True) print('{:<30} {:<8}'.format('Computational complexity: ', macs)) print('{:<30} {:<8}'.format('Number of parameters: ', params))
|
torchvision的部分结果
Model |
Input Resolution |
Params(M) |
MACs(G) |
Top-1 error |
Top-5 error |
alexnet |
224x224 |
61.1 |
0.72 |
43.45 |
20.91 |
vgg11 |
224x224 |
132.86 |
7.63 |
30.98 |
11.37 |
vgg13 |
224x224 |
133.05 |
11.34 |
30.07 |
10.75 |
vgg16 |
224x224 |
138.36 |
15.5 |
28.41 |
9.62 |
vgg19 |
224x224 |
143.67 |
19.67 |
27.62 |
9.12 |
vgg11_bn |
224x224 |
132.87 |
7.64 |
29.62 |
10.19 |
Reference
https://github.com/sovrasov/flops-counter.pytorch