kazuto1011 / grad-cam-pytorch

PyTorch re-implementation of Grad-CAM (+ vanilla/guided backpropagation, deconvnet, and occlusion sensitivity maps)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: Invalid layer name: layer4.2

bemoregt opened this issue · comments

Hi, @kazuto1011

I changed yourcode lkike this:

def main(image_path, arch, topk, cuda):
CONFIG = {
'resnet18': {
'target_layer': 'layer4.2',
'input_size': 224
},

then I've met this error:
File "/Users/mun/grad-cam-pytorch/grad_cam.py", line 101, in _find
raise ValueError('Invalid layer name: {}'.format(target_layer))
ValueError: Invalid layer name: layer4.2

What's wrong to me?

Thanks in advance.

from @bemoregt.

You can check valid layer names with this command:

print(*list(models.resnet18().named_modules(), sep='\n'))

If you're interested in the output of the last convolution layer, try to specify "layer4.1".