haofanwang / Score-CAM

Official implementation of Score-CAM in PyTorch
MIT License
399 stars 66 forks source link

Visualization Issue #19

Closed Halilibrahimaysel closed 2 years ago

Halilibrahimaysel commented 2 years ago

Hello Haofan, I have simply attached a code example to show what I need on the example for GradCAM given by Keras and added comments on crucial points.

Thanks in advance,

Halil GradCAM1.zip

haofanwang commented 2 years ago

@Halilibrahimaysel

I don't think it is a problem actually, the reason why the background is totally black is that the tiny values are set to zero (np.unit8 matters here, and also different visualization tools may have some variances). Just follow the code below should be fine.

heatmap = cam(original_img)
upsampled_heatmap = upsample_func(heatmap, target_size)
result = upsampled_heatmap * original_img
Halilibrahimaysel commented 2 years ago

Thank you so much for the answer. I think as you mentioned it is not a problem as keeping the background black or gray does not make a substantial difference anyway.

Haofan Wang @.***>, 20 Eyl 2021 Pzt, 04:23 tarihinde şunu yazdı:

@Halilibrahimaysel https://github.com/Halilibrahimaysel

I'm not familiar with Keras, but the problem should be clear.

heatmap = np.uint8(255 * heatmap) should not be used for your purpose. It sets all small values into zeros, and makes the background be completely black rather than gray.

What you need to do is simple, below is my pseudocode

heatmap = cam(original_img) upsampled_heatmap = upsample_func(heatmap, target_size) result = upsampled_heatmap * original_img

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/haofanwang/Score-CAM/issues/19#issuecomment-922613051, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATX3BQNHVSKLOMFDWP3IUIDUC2SKFANCNFSM5EJGZTHA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.