How to calculate size of receptive field?

I’d like to calculate the size of the receptive field in various architectures (EfficientNet, ResNext, …) by looking at a PyTorch model and examining the layers. Is there an example of code that already does this? If not, how can this best be done?

(It is relatively easy to look at a simple sequential model. I think basically going from the top down, any time there is a Conv2d, the field expands by kernel size-1, and any time there is a strided conv or pool operation the field is multiplied by the stride. Tracing the size of the field becomes a bit more complicated with more complex connectivity though…)

1 Like