One-line Effective Receptive Field (ERF) extraction for pretrained timm vision models.
import openerf
import timm
model_name = "resnet50.a1_in1k"
model = timm.create_model(model_name, pretrained=True)
openerf.save_erf(model, model_name=model_name)
# -> ./results/OpenERF_resnet50.a1_in1k.pngAll images below are ERF maps generated from the ImageNet validation subset (./imagenet_val_1000/).
The full set is available in ./results/.
- Features
- Installation
- Quick Start
- CLI Options
- API Reference
- Supported Models
- Dataset
- Repository Layout
- Output Structure
- Distribution Package
- Citing
- License
- One-line API —
openerf.save_erffor end-to-end ERF extraction - Automatic preprocessing —
mean/std, interpolation,crop_pct, input size fromtimmdata config - Unified workflow — CNN and Transformer families through the same interface
- Publication-ready output — ERF heatmaps (
plasmaby default) - Optional exports — Gaussian fitting (
lmfit),.npyarrays,.jsonmetrics
pip install openerfOr install from source:
conda activate OpenERF
pip install -r requirements.txt
pip install -e .
# Optional: Gaussian fitting extras
pip install -e ".[gaussian]"import openerf
import timm
model_name = "resnet50.a1_in1k"
model = timm.create_model(model_name, pretrained=True)
result = openerf.save_erf(
model=model,
model_name=model_name,
image_dir="./imagenet_val_1000",
max_images=1000,
colormap="plasma",
save_numpy=True,
save_metrics=True,
)
print(result["save_path"])
print(result.get("npy_path"))
print(result.get("metrics_path"))Legacy top-level import is still supported: import OpenERF.
from openerf import compute_erf, save_erfopenerf --help
openerf --image-dir ./imagenet_val_1000 --max-images 1000# Show all preset models
openerf --list-models
# Resume long runs
openerf --image-dir ./imagenet_val_1000 --max-images 1000 --skip-existing
# Run selected families
openerf --families vit deit cait xcit beit swin swinv2 \
--image-dir ./imagenet_val_1000 --max-images 1000# Module form
python -m openerf.cli --list-modelsopenerf (or python -m openerf.cli) supports:
| Option | Description | Default |
|---|---|---|
--families |
Model families to run (when --model-names is not set) |
all preset families |
--model-names |
Explicit timm model names (must include pretrained tag) |
None |
--image-dir |
Input image directory | ./imagenet_val_1000 |
--save-dir |
PNG output directory | ./results |
--npy-dir |
NumPy output directory | ./results_npy |
--metrics-dir |
Metrics output directory | ./results_metrics |
--max-images |
Maximum images to process | 1000 |
--target-layer |
Override feature source layer | auto (family preset) |
--fit-gaussian |
Enable 2D Gaussian fit (sigma_x, sigma_y) |
disabled |
--skip-existing |
Skip if output PNG already exists | disabled |
--no-save-numpy |
Disable .npy export |
enabled |
--no-save-metrics |
Disable .json export |
enabled |
--stop-on-error |
Stop immediately on model failure | disabled |
Computes ERF in memory and returns ERFResult:
| Field | Description |
|---|---|
erf_map |
2D ERF array |
num_images |
Number of images processed |
data_config |
timm data config used |
resolved_target_layer |
Actual target layer name |
gaussian_fit |
(optional) Gaussian fit parameters |
Computes ERF, saves PNG, and optionally exports .npy / .json.
Default values: save_numpy=False, save_metrics=False, colormap="plasma"
| Return key | Description |
|---|---|
model_name |
Model identifier |
source_model_name |
Original timm model name |
save_path |
Path to saved PNG |
num_images |
Number of images processed |
target_layer |
Target layer name |
family |
Model family |
data_config |
timm data config used |
gaussian_fit |
(optional) Gaussian fit result |
npy_path |
(optional) Path to .npy file |
metrics_path |
(optional) Path to .json file |
11 families × 3 variants = 33 preset models
| Family | Models |
|---|---|
resnet |
resnet18.a1_in1k, resnet34.a1_in1k, resnet50.a1_in1k |
resnext |
resnext50_32x4d.a1_in1k, resnext50_32x4d.ra_in1k, resnext101_32x8d.tv_in1k |
densenet |
densenet121.ra_in1k, densenet169.tv_in1k, densenet201.tv_in1k |
efficientnet |
efficientnet_b0.ra_in1k, efficientnet_b2.ra_in1k, tf_efficientnet_b4.ns_jft_in1k |
vit |
vit_small_patch16_224.augreg_in1k, vit_base_patch16_224.augreg_in1k, vit_base_patch32_224.augreg_in1k |
deit |
deit_tiny_patch16_224.fb_in1k, deit_small_patch16_224.fb_in1k, deit_base_patch16_224.fb_in1k |
cait |
cait_xxs24_224.fb_dist_in1k, cait_xxs36_224.fb_dist_in1k, cait_s24_224.fb_dist_in1k |
xcit |
xcit_tiny_12_p16_224.fb_in1k, xcit_small_12_p16_224.fb_in1k, xcit_medium_24_p16_224.fb_in1k |
beit |
beit_base_patch16_224.in22k_ft_in22k, beit_base_patch16_224.in22k_ft_in22k_in1k, beit_base_patch16_384.in22k_ft_in22k_in1k |
swin |
swin_tiny_patch4_window7_224.ms_in1k, swin_small_patch4_window7_224.ms_in1k, swin_base_patch4_window7_224.ms_in1k |
swinv2 |
swinv2_cr_tiny_ns_224.sw_in1k, swinv2_cr_small_224.sw_in1k, swinv2_cr_small_ns_224.sw_in1k |
OpenERF uses the ImageNet validation set (or a subset).
- Default subset index:
./imagenet_val_1000.txt - Image folder:
./imagenet_val_1000/ - Default scope:
--image-dir ./imagenet_val_1000 --max-images 1000
OpenERF/
src/
openerf/
__init__.py
api.py
cli.py
data.py
erf.py
feature_ops.py
fit.py
metrics.py
model_zoo.py
visualization.py
py.typed
tests/
test_smoke.py
examples/
example.py
README.md
LICENSE
pyproject.toml
requirements.txt
./results/ OpenERF_<model_name>.png # ERF heatmap
./results_npy/ OpenERF_<model_name>.npy # ERF array
./results_metrics/ OpenERF_<model_name>_metrics.json # ERF metrics
./results_debug/ (smoke/check/intermediate artifacts)
Source distributions include package source and core metadata while excluding large experiment artifacts.
- Included:
src/,README.md,LICENSE,pyproject.toml - Excluded:
results*/,reference/,examples/,tests/,OpenERF.egg-info/
If OpenERF is useful in your research, please cite:
@inproceedings{KimCJK23,
author = {Bum Jun Kim and
Hyeyeon Choi and
Hyeonah Jang and
Sang Woo Kim},
title = {Understanding Gaussian Attention Bias of Vision Transformers Using
Effective Receptive Fields},
booktitle = {{BMVC}},
pages = {214},
publisher = {{BMVA} Press},
year = {2023}
}
@article{KimCJLJK23,
author = {Bum Jun Kim and
Hyeyeon Choi and
Hyeonah Jang and
Dong Gu Lee and
Wonseok Jeong and
Sang Woo Kim},
title = {Dead pixel test using effective receptive field},
journal = {Pattern Recognit. Lett.},
volume = {167},
pages = {149--156},
year = {2023}
}This project is released under the MIT License.









