utkuozbulak / pytorch-cnn-visualizations

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

a question on "cam = np.ones(target.shape[1:], dtype=np.float32)" in gradcam.py #103

Closed captainst closed 2 years ago

captainst commented 2 years ago

Hi there,

Many thanks for the demo. It is very helpful. I have a question here: Line 81 in gradcam.py:

# Create empty numpy array for cam
cam = np.ones(target.shape[1:], dtype=np.float32)

I am wondering if np.zeros should be used, in order to create an empty array, instead of np.ones. Using np.ones to initialize cam could bias cam towards positive values. So the effects by cam = np.maximum(cam, 0)would be reduced.

I am wondering if I understood the algo correctly. Thank you again !

utkuozbulak commented 2 years ago

You can have a look at #11. It is funny that I said I should add a comment to the code to avoid confusion and still did not do it for about 3 years. I added that comment now. Thanks.

captainst commented 2 years ago

Many thanks! Issue closed