frgfm / torch-scan

Seamless analysis of your PyTorch models (RAM usage, FLOPs, MACs, receptive field, etc.)
https://frgfm.github.io/torch-scan/latest
Apache License 2.0
208 stars 22 forks source link

fix: Fixed RF computation and added effective stride and padding #33

Closed frgfm closed 3 years ago

frgfm commented 3 years ago

This PR switched back to initial computation order of the receptive field, and add the possibility to display effective stride and padding.

Computing the receptive field of VGG16 with

from torchvision.models import vgg16
from torchscan import summary

model = vgg16().eval().cuda()
summary(model.features, (3, 224, 224), receptive_field=True, max_depth=0)

would yield an incorrect value before the fix:

____________________________________________________________________________
Layer         Type          Output Shape       Param #       Receptive field
============================================================================
sequential    Sequential    (-1, 512, 7, 7)    14,714,688    308            
============================================================================
Trainable params: 14,714,688
Non-trainable params: 0
Total params: 14,714,688
----------------------------------------------------------------------------
Model size (params + buffers): 56.13 Mb
Framework & CUDA overhead: 479.38 Mb
Total RAM usage: 535.51 Mb
----------------------------------------------------------------------------
Floating Point Operations on forward: 30.71 GFLOPs
Multiply-Accumulations on forward: 15.35 GMACs
Direct memory accesses on forward: 15.40 GDMAs
____________________________________________________________________________

After the fix:

____________________________________________________________________________
Layer         Type          Output Shape       Param #       Receptive field
============================================================================
sequential    Sequential    (-1, 512, 7, 7)    14,714,688    212            
============================================================================
Trainable params: 14,714,688
Non-trainable params: 0
Total params: 14,714,688
----------------------------------------------------------------------------
Model size (params + buffers): 56.13 Mb
Framework & CUDA overhead: 479.38 Mb
Total RAM usage: 535.51 Mb
----------------------------------------------------------------------------
Floating Point Operations on forward: 30.71 GFLOPs
Multiply-Accumulations on forward: 15.35 GMACs
Direct memory accesses on forward: 15.40 GDMAs
____________________________________________________________________________
codecov[bot] commented 3 years ago

Codecov Report

Merging #33 into master will increase coverage by 0.24%. The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
+ Coverage   90.04%   90.29%   +0.24%     
==========================================
  Files           9        9              
  Lines         603      608       +5     
==========================================
+ Hits          543      549       +6     
+ Misses         60       59       -1     
Impacted Files Coverage Δ
torchscan/utils.py 75.60% <81.25%> (+1.88%) :arrow_up:
torchscan/crawler.py 82.08% <100.00%> (ø)
torchscan/modules/receptive.py 100.00% <100.00%> (ø)