utkuozbulak / pytorch-cnn-visualizations

Pytorch implementation of convolutional neural network visualization techniques
MIT License
7.86k stars 1.49k forks source link

why use np.ones instead of np.zeros, since you want to create some empty arrays #11

Closed zhenni closed 6 years ago

zhenni commented 6 years ago

https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/93d112c563e5e601eebab0eb7bf58bf9df30c008/src/gradcam.py#L81

utkuozbulak commented 6 years ago

Hello, sorry for the late response. It doesn't really matter too much in the end because of the normalization that comes afterwards. You can change ones to zeros and obtain the same cam map most of the time.

However, there are times when the output may look different, for example, for cat and dog it looks like this:

Ones: cat_dog_cam_on_image

Zeros: cat_dog_cam_on_image

It actually highlights the same part but the choice of color looks way more appealing on the first one (because too much red is kind of irritating). I think I made the choice of using ones because of that reason and I agree that naturally, it makes more sense to have it zeros. I will put this note on the code as a comment so that people can see why.

Thanks for highlighting, I hope this clears things up.

zhenni commented 6 years ago

@utkuozbulak Thanks! I think it is clear. I think the colormap JET is much better for visualization of heatmaps, instead of HSV. (HSV has red color for the smallest values and largest values as well.) If you choose JET, the color should not have the irritating red things.

utkuozbulak commented 6 years ago

Thanks for the advice! I will have a look at it!