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.16k stars 1.53k forks source link

ScoreCAM empty cam_per_layer #194

Closed ericotjo001 closed 2 years ago

ericotjo001 commented 2 years ago

In ScoreCAM implementation, if we set target_layers, we get warning "Warning: You are using ScoreCAM with target layers, however ScoreCAM will ignore them". But when we call it with target_layers=[], the resulting cam_per_layer is of course empty, and this raises error with aggregate_multi_layers(cam_per_layer).

jacobgil commented 2 years ago

Thanks for reporting this.

Yes, it's a bug - score cam should work without target layers. Need a PR to fix this. In the meanwhile I think you can pass a dummy value in target_layers.

ericotjo001 commented 2 years ago

Thanks for the response. I will avoid it for now.

pimmie-ya commented 2 years ago

Hi I got this problem too,how can i solve this problem specificly?