Skip to content

[BUG] Captum tutorial fails when visualize_image_attr() receives None for original_image #3963

Description

@Dr-LazyMazy

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 !

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions