Practical overview
When it fits
Use it when inspecting how a PyTorch CNN’s layers and units relate to input regions, including in workflows that need receptive-field measurements for either 2D or 3D models.
Who it is for
- PyTorch developers analyzing CNN architecture and feature-map behavior.
- Teams adding receptive-field calculations or 2D visualizations to model-inspection workflows.
Documented uses
- Calculate receptive-field measurements across CNN layers.
- Query the receptive field for a particular layer and unit position.
- Create a 2D GIF visualization using model results and an image.
Requirements & limits
The source repository is public and specifies the Apache-2.0 license. The README documents installation from Git using pip.
- The library supports calculations for both 2D and 3D CNNs, while the documented visualization function is 2D.
- The calculation takes a model and input dimensions; querying an individual unit uses the returned result data.
- The README’s worked example refers to PyTorch v0.4.0 and does not provide a broader compatibility statement.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Calculate receptive fields for a PyTorch CNN
Install the library and request receptive-field results for a 2D model.
Before you start
- A PyTorch model
- An input size expressed as channels, height and width
- Python with pip
Steps
Install from the Git repository with the command below.
pip install git+https://github.com/Fangyh09/pytorch-receptive-field.gitImport
receptive_fieldfromtorch_receptive_field.Call
receptive_field(model, input_size=(channels, H, W))with the model and its input dimensions.Use the returned data with
receptive_field_for_unitto query a layer and unit position.
Expected outcome
A dictionary of receptive-field results that can be queried for a specified layer and unit.
Guide limitations
- The documented input-size form is for 2D models; the README gives a separate 3D example using channels, depth, height and width.
- The README's example mentions PyTorch v0.4.0; it does not establish compatibility with other versions.
Create a 2D receptive-field visualization GIF
Generate the documented 2D visualization using model results and an input image.
Before you start
- A PyTorch model and its 2D input dimensions
- A receptive-field result dictionary
- An image file path
- The installed
torch_receptive_fieldlibrary
Steps
Install the library from the Git repository with pip.
Import
receptive_fieldandreceptive_field_visualization_2dfromtorch_receptive_field.Calculate the model results with
receptive_field(model, (channels, H, W)).Call
receptive_field_visualization_2dwith the result dictionary, image path and output path without an extension.
Expected outcome
A 2D receptive-field visualization GIF at the specified output path.
Guide limitations
- The documented visualization function is for 2D models.
- The README demonstrates a GIF but does not specify further output-format options.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 16 November 2026
- Original website title
- Fangyh09/pytorch-receptive-field · Official homepage title · retained in its source language

