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

Explainability heatmaps for multi output look very similar #163

Closed mhashas closed 2 years ago

mhashas commented 2 years ago

338

I have used the trick that you mentioned of creating multiple SingleOutput models by returning x[task].

My network looks like this: Resnet18 -> tasks x linear layers

Do you have any advice on what I could try to do?

wbygit commented 2 years ago

Yes, I find the same problem too. I modified the code from Grad-CAM++ to adapt 1D ECG signal. I use the output of Grad-CAM to visualize my ECG data.

My model is 1D-ResNet34 with CBAM module and target_layers is model.layer4[-1]. It's similar to the original ResNet34 model. And my task is a multi-label classification task.

There are results for two different target_categories. It's more than similar. I calculate the difference of all results of different target_categories, the max difference is like 1e-6. T改变 窦性心动过速

jacobgil commented 2 years ago

I think we need to distinguish between two possibilities:

I think if we can try this, it will help debug:

wbygit commented 2 years ago

Yes, I find the same problem too. I modified the code from Grad-CAM++ to adapt 1D ECG signal. I use the output of Grad-CAM to visualize my ECG data.

My model is 1D-ResNet34 with CBAM module and target_layers is model.layer4[-1]. It's similar to the original ResNet34 model. And my task is a multi-label classification task.

There are results for two different target_categories. It's more than similar. I calculate the difference of all results of different target_categories, the max difference is like 1e-6.

I have solved this problem because I find that my modification for 1D data is wrong. After correcting mistakes, it works well. Here are the current results for two different target_categories. Hope @mhashas you can find some code bugs too.

resnet34_cbam  layer4 -1  在 1661089 xml 数据上对 室性早搏(TP) 类别的注意力热力图 Grad-CAMpp-V1 resnet34_cbam  layer4 -1  在 1661089 xml 数据上对 T改变(低平,双向 倒置 深倒置,浅倒置,切迹)(TP) 类别的注意力热力图 Grad-CAMpp-V1

jacobgil commented 2 years ago

Great. Closing for now, please re-open if still relevant.

mhashas commented 2 years ago

@jacobgil

The problem for me was setting eigen_smooth to True. Setting it to False solves the issue

philippkiesling commented 2 years ago

@mhashas It is the same for me. I also noted that the smoothed areas are not similar to the originally found areas as illustrated in the images.

eigen_smooth = True (First Image Class 1, Second Image Class 2): smoothed

eigen_smooth = False (First Image Class 1, Second Image Class 2): unsmoothed