You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from PIL import Image
import paddle
import interpretdl as it
from interpretdl.data_processor.readers import read_image
# load from paddle.vision
from paddle.vision.models import resnet50
paddle_model = resnet50(pretrained=True)
gradcam = it.GradCAMInterpreter(paddle_model, device='cpu')
img_path = 'dog_and_cat.png'
x = Image.fromarray(read_image(img_path)[0])
x
layers_name = []
for n, v in paddle_model.named_sublayers():
layers_name.append(n)
print(layers_name)
heatmap = gradcam.interpret(
img_path,
'layer4.2.conv3',
label=None,
visual=True,
save_path=None)
(optional) Briefly introduce yourself.
---我按照gradcam的example代码运行如下
随后,出现了报错
🐛 Bug
AxisError Traceback (most recent call last)
Cell In[6], line 1
----> 1 heatmap = gradcam.interpret(
2 img_path,
3 'layer4.2.conv3',
4 label=None,
5 visual=True,
6 save_path=None)
File d:\Anaconda\envs\pyside_app\lib\site-packages\interpretdl\interpreter\gradient_cam.py:101, in GradCAMInterpreter.interpret(self, inputs, target_layer_name, label, resize_to, crop_to, visual, save_path)
96 g = gradients
98 # print(f.shape, g.shape) # [bsz, channels, w, h]
99
100 # the core algorithm
--> 101 cam_weights = np.mean(g, (2, 3), keepdims=True)
102 heatmap = cam_weights * f
103 heatmap = heatmap.mean(1)
File <array_function internals>:200, in mean(*args, **kwargs)
File d:\Anaconda\envs\pyside_app\lib\site-packages\numpy\core\fromnumeric.py:3464, in mean(a, axis, dtype, out, keepdims, where)
3461 else:
3462 return mean(axis=axis, dtype=dtype, out=out, **kwargs)
-> 3464 return _methods._mean(a, axis=axis, dtype=dtype,
...
81 # axis and full sum is more excessive than needed.
82
83 # guarded to protect circular imports
AxisError: axis 2 is out of bounds for array of dimension 0
Briefly describe the bug.
To Reproduce
Steps to reproduce the behavior:
If you were running a command, please post the exact command that you were running.
If you have a code sample, error messages, stack traces, please provide it here as well.
(optional) Enviroment
If you know well the environment of your machine, please put the information below:
The text was updated successfully, but these errors were encountered: