GitHub - FRGFM - Torch-Scan - Seamless Analysis of Your PyTorch Models (RAM Usage, FLOPs, MACs, Receptive Field, Etc.)
GitHub - FRGFM - Torch-Scan - Seamless Analysis of Your PyTorch Models (RAM Usage, FLOPs, MACs, Receptive Field, Etc.)
Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
frgfm.github.io/torch-scan/
Apache-2.0 license
Star Notifications
Code Issues 7 Pull requests 1 Discussions Actions Projects Wiki Security Ins
main Go to file
View code
README.md
CI passing docs repo or workflow not found coverage 93% code style black code quality
pypi v0.1.2 Anaconda.org 0.1.2 python 3.6 | 3.7 | 3.8 | 3.9 license Apache-2.0
The very useful summary method of tf.keras.Model but for PyTorch, with more useful information.
Quick Tour
https://github.com/frgfm/torch-scan 1/6
8/10/23, 12:04 AM GitHub - frgfm/torch-scan: Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
model = densenet121().eval().cuda()
summary(model, (3, 224, 224), max_depth=2)
__________________________________________________________________________________________
Layer Type Output Shape Param #
==========================================================================================
densenet DenseNet (-1, 1000) 0
├─features Sequential (-1, 1024, 7, 7) 0
| └─conv0 Conv2d (-1, 64, 112, 112) 9,408
| └─norm0 BatchNorm2d (-1, 64, 112, 112) 257
| └─relu0 ReLU (-1, 64, 112, 112) 0
| └─pool0 MaxPool2d (-1, 64, 56, 56) 0
| └─denseblock1 _DenseBlock (-1, 256, 56, 56) 338,316
| └─transition1 _Transition (-1, 128, 28, 28) 33,793
| └─denseblock2 _DenseBlock (-1, 512, 28, 28) 930,072
| └─transition2 _Transition (-1, 256, 14, 14) 133,121
| └─denseblock3 _DenseBlock (-1, 1024, 14, 14) 2,873,904
| └─transition3 _Transition (-1, 512, 7, 7) 528,385
| └─denseblock4 _DenseBlock (-1, 1024, 7, 7) 2,186,272
| └─norm5 BatchNorm2d (-1, 1024, 7, 7) 4,097
├─classifier Linear (-1, 1000) 1,025,000
==========================================================================================
Trainable params: 7,978,856
Non-trainable params: 0
Total params: 7,978,856
------------------------------------------------------------------------------------------
Model size (params + buffers): 30.76 Mb
Framework & CUDA overhead: 423.57 Mb
Total RAM usage: 454.32 Mb
------------------------------------------------------------------------------------------
Floating Point Operations on forward: 5.74 GFLOPs
Multiply-Accumulations on forward: 2.87 GMACs
Direct memory accesses on forward: 2.90 GDMAs
__________________________________________________________________________________________
FLOPs: floating-point operations (not to be confused with FLOPS which is FLOPs per second)
MACs: mutiply-accumulate operations (cf. wikipedia)
DMAs: direct memory accesses (many argue that it is more relevant than FLOPs or MACs to compare model
inference speeds cf. wikipedia)
Additionally, for highway nets (models without multiple branches / skip connections), torchscan supports
receptive field estimation.
https://github.com/frgfm/torch-scan 2/6
8/10/23, 12:04 AM GitHub - frgfm/torch-scan: Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
model = vgg16().eval().cuda()
summary(model, (3, 224, 224), receptive_field=True, max_depth=0)
which will add the layer's receptive field (relatively to the last convolutional layer) to the summary.
Setup
Python 3.6 (or higher) and pip/conda are required to install Torchscan.
Stable release
You can install the last stable release of the package using pypi as follows:
or using conda:
Developer installation
Alternatively, if you wish to use the latest features of the project that haven't made their way to a release yet, you
can install the package from source:
Benchmark
Below are the results for classification models supported by torchvision for a single image with 3 color channels
of size 224x224 (apart from inception_v3 which uses 299x299 ).
https://github.com/frgfm/torch-scan 3/6
8/10/23, 12:04 AM GitHub - frgfm/torch-scan: Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
Note: receptive field computation is currently only valid for highway nets.
What else
Documentation
https://github.com/frgfm/torch-scan 4/6
8/10/23, 12:04 AM GitHub - frgfm/torch-scan: Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
Example script
An example script is provided for you to benchmark torchvision models using the library:
python scripts/benchmark.py
Credits
This project is developed and maintained by the repo owner, but the implementation was inspired or helped by
the following contributions:
Citation
If you wish to cite this project, feel free to use this BibTeX reference:
@misc{torchscan2020,
title={Torchscan: meaningful module insights},
author={François-Guillaume Fernandez},
year={2020},
month={March},
publisher = {GitHub},
howpublished = {\url{https://github.com/frgfm/torch-scan}}
}
Contributing
Any sort of contribution is greatly appreciated!
You can find a short guide in CONTRIBUTING to help grow this project!
License
Distributed under the Apache 2.0 License. See LICENSE for more information.
Releases 3
v0.1.2: Improved project quality and some layers' support fixed Latest
on Aug 3, 2022
https://github.com/frgfm/torch-scan 5/6
8/10/23, 12:04 AM GitHub - frgfm/torch-scan: Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
+ 2 releases
Sponsor
Used by 39
+ 31
Contributors 2
Languages
https://github.com/frgfm/torch-scan 6/6