utkuozbulak / pytorch-cnn-visualizations

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

added requires_grad = True for vanilla and guided backprop #43

Closed mlaves closed 5 years ago

mlaves commented 5 years ago

I had problems with your code using my own CNN and data, because the gradients where not computed up to the input image. Therefore, grad_in[0] in hook_function was None. Manually setting requires_grad = True for the input data solved the issue for me.

utkuozbulak commented 5 years ago

Hey, thanks for the PR.

For the examples given in the repository, this operation is done at image pre-processing level (once).

https://github.com/utkuozbulak/pytorch-cnn-visualizations/blob/fc730d48882ed92b77995d7418ac9730841142e9/src/misc_functions.py#L165

If it is not done there, requires_grad = True must be added to each operation, meaning more unnecessary LOC added to each file.

mlaves commented 5 years ago

I must have overseen this. Thanks for pointing that out.