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

feat: Switched RF computation basis to input #31

Closed frgfm closed 3 years ago

frgfm commented 3 years ago

This PR switches the relative layer of receptive field computation to input rather than output to close #27

Running the following snippet:

from torch import nn
from torchscan import summary

mod = nn.Sequential(nn.Conv2d(3, 8, 5), nn.ReLU(), nn.Conv2d(8, 16, 3))
summary(mod.eval(), (3, 32, 32), receptive_field=True)

yields:

__________________________________________________________________________
Layer         Type          Output Shape        Param #    Receptive field
==========================================================================

sequential    Sequential    (-1, 16, 26, 26)    0          1              
├─0           Conv2d        (-1, 8, 28, 28)     608        5              
├─1           ReLU          (-1, 8, 28, 28)     0          5              
├─2           Conv2d        (-1, 16, 26, 26)    1,168      7              
==========================================================================

Trainable params: 1,776
Non-trainable params: 0
Total params: 1,776
--------------------------------------------------------------------------

Model size (params + buffers): 0.01 Mb
Framework & CUDA overhead: 427.00 Mb
Total RAM usage: 427.01 Mb
--------------------------------------------------------------------------

Floating Point Operations on forward: 2.50 MFLOPs
Multiply-Accumulations on forward: 1.25 MMACs
Direct memory accesses on forward: 1.28 MDMAs
__________________________________________________________________________
codecov[bot] commented 3 years ago

Codecov Report

Merging #31 into master will decrease coverage by 0.15%. The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #31      +/-   ##
==========================================
- Coverage   89.77%   89.61%   -0.16%     
==========================================
  Files           9        9              
  Lines         577      578       +1     
==========================================
  Hits          518      518              
- Misses         59       60       +1     
Impacted Files Coverage Δ
torchscan/utils.py 66.66% <0.00%> (-0.73%) :arrow_down:
torchscan/crawler.py 82.08% <100.00%> (ø)