[BUG] Captum tutorial fails when visualize_image_attr() receives None for original_image
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9.3k
- Forks
- 4.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 4
Description
There is the following issue on this page: https://docs.pytorch.org/tutorials/beginner/introyt/captumyt.html
Hi PyTorch Team,
I got an an error when following the tutorial Model Understanding with Captum part. The issue is within Feature Attribution with Integrated Gradients section. The tutorial uses :
"""
_ = viz.visualize_image_attr(
None,
np.transpose(
transformed_img.squeeze().cpu().detach().numpy(),
(1, 2, 0)
),
method="original_image",
title="Original Image"
)
"""
When running that cell, I'm getting this error :
"""
AttributeError: 'NoneType' object has no attribute 'shape'
"""
The traceback points to captum/attr/_utils/visualization.py, where visualize_image_attr() attempts to access attr.shape. Since the tutorial passes None as attr, this fails before the "original_image" visualization is produced.
======================================================
My utilised env:
"""
PyTorch version: 2.10.0
TorchVision version: 0.25.0
Python version: 3.14.7
OS: macOS 26.6.2 arm64
CPU: Apple M4 Pro
NumPy: 2.4.2
Captum: <0.9.0>
"""
and python3 -m torch.utils.collect_env output:
"""
Collecting environment information...
PyTorch version: 2.10.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 26.6.2 (arm64)
Clang version: 17.0.0
Python version: 3.14.7
Python platform: macOS-26.6.2-arm64-arm-64bit-Mach-O
Is CUDA available: False
Is XPU available: False
Is XNNPACK available: True
CPU:
Apple M4 Pro
Versions of relevant libraries:
numpy==2.4.2
torch==2.10.0
torchvision==0.25.0
"""
Since, the page current verfied date is Nov 05, 2024, it might be an update/compatibility issue.
Best !
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Captum tutorial page at docs.pytorch.org/tutorials/beginner/introyt/captumyt.html, specifically the Feature Attribution with Integrated Gradients section and its visualize_image_attr() cell. Reproduce the AttributeError, then inspect Captum's attr/_utils/visualization.py behavior for a None input. Done means the tutorial cell runs successfully and produces the intended original-image visualization.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 70/100