jacobgil / pytorch-grad-cam

Advanced AI Explainability for computer vision. Support for CNNs, Vision Transformers, Classification, Object detection, Segmentation, Image similarity and more.
https://jacobgil.github.io/pytorch-gradcam-book
MIT License
10.52k stars 1.56k forks source link

What's the meaning of "35" in your code? #8

Closed bemoregt closed 6 years ago

bemoregt commented 6 years ago

Hi, @mingloo @jacobgil @flyingpot

In your code:

grad_cam = GradCam(model = models.resnet50(pretrained=True), \ target_layer_names = ["35"], use_cuda=args.use_cuda)

What's the meaning of "35" ?

I've got an error when using above code: AttributeError: 'ResNet' object has no attribute 'features'

What's wrong with me?

Thanks in advance ~

from Gromit Park.

jacobgil commented 6 years ago

35 is the index of the targeted layer in resnet50.

If you use a different network, you will need to replace it with another name.

jiashenC commented 4 years ago

You set 35 for VGG19 as well, which seems to work fine still. So does it matter which layer to choose?