Skip to content

Compute receptive fields as input masks for single neurons in any CNN written in PyTorch.

Notifications You must be signed in to change notification settings

leonardopetrini/cnn-receptive-fields

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CNN Receptive Fields

Receptive field computation for any CNN in PyTorch.

The receptive field of a neuron is defined as the region of the input that can change the output of such a neuron.

The contribution to the value of neuron n of pixel (i, j) in an input image x is computed by

  • setting all the weights in the network to constant values
  • replacing Max-Pooling by Average Pooling
  • switching off batch norm
  • switching on pixels in the input one at a time to check responding neurons.
  • contributions are then rescaled to be in [0, 1]

The resulting receptive fields are a set of images R^l = [R_n^l | n is a neuron in layer l] that have the same size of the input.

The value of R^l_n[i, j] \in [0, 1] corresponds to how much pixel (i, j), in an input image - i.e. x[:, i, j] - would contribute to the output of neuron n, which lives in layer l, if the network had constant weights.

Install

(this is for the receptivefield functions only)

python -m pip install git+https://github.com/leonardopetrini/cnn-receptive-fields.git

Usage

Examples of how to use the code are reported examples.ipynb.

Dependencies

  • torch
  • torch.fx

For the example

  • torchvision
  • matplotlib

cf. requirements.txt for versions.

About

Compute receptive fields as input masks for single neurons in any CNN written in PyTorch.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published