AttributeError: 'list' object has no attribute 'cpu'
Author: pawara101Created Nov 1, 2025Updated Apr 29, 2026
I was using YOLOv12 for EigenCAM. Below is my code block.
from pytorch_grad_cam import EigenCAM
target_layer = get_conv_layer(model_1,conv_layer_name = "model.model.4.cv3")
results_1 = model_1([img_path])
cam_1 = EigenCAM(model=model_1, target_layers=target_layer)
grayscale_cam = cam_1(img_tensor)[0, :, :]The erroermessage was
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
[/tmp/ipython-input-342971846.py](https://localhost:8080/#) in <cell line: 0>()
----> 1 grayscale_cam = cam_1(img_tensor)[0, :, :]
1 frames
[/usr/local/lib/python3.12/dist-packages/pytorch_grad_cam/base_cam.py](https://localhost:8080/#) in forward(self, input_tensor, targets, eigen_smooth)
102
103 if targets is None:
--> 104 target_categories = np.argmax(outputs.cpu().data.numpy(), axis=-1)
105 targets = [ClassifierOutputTarget(category) for category in target_categories]
106
AttributeError: 'list' object has no attribute 'cpu'Can you help me to fix this ?
Source: jacobgil/pytorch-grad-cam