Closed dlin511 closed 3 years ago
@dlin511, Thank you for letting us know!
There are 2 causes for the problem.
penultimate_layer=-1
with MobilenNetV3, the spatial size of the class activation map (CAM) that is visualized by Gradcam++ is 1x1.Gradcam++(, Gradcam and Scorecam) resize the visualized CAM to the same with input image size as follows.
So when the CAM size is 1x1, the whole image generated by Gradcam++ will be one color. To avoid this, we can modify the penultimate_layer option to 'Conv_2' or earlier layer name.
cam = gradcam(..., penultimate_layer='Conv_2')
I don't know why it is. For now, we can get the CAM we expect if we reverse the sign of cam
such below:
cam = gradcam(..., activation_modifier=lambda cam: K.relu(-cam))
Ultimately, you can avoid the problem to modify the code of calling Gradcam++ such below:
cam = gradcam(score, images, penultimate_layer='Conv_2', activation_modifier=lambda cam: K.relu(-cam))
Thanks!
Thank you so much!! I appreciate your quick response, you're amazing.
You're welcome. Please star this repository if you'd like!
@dlin511 Using Conv_2
as the penultimate layer can cause inverted gradcam activations. Instead multiply_18
should be used which is the last subsequent layer with the same output shape as Conv_2
. This applies to TF 2.4. The MobileNetV3 implementation has changed slightly in later versions.
Hi @keisen, first off, thank you all so much for the amazing library.
I was recently using GradCam++ with MobileNetV3 and found that the heatmaps created were entirely blue despite the predictions being accurate. I am currently reading through the relevant literature to figure out whether it is a feature of the MobileNetV3 architecture or some lack of compatibility with the visualization code. I was just wondering if you guys would have any insight to perhaps resolve the issue more quickly.
Here is some code to recreate the issue (adapted mostly from your tutorial):