utkuozbulak / pytorch-cnn-visualizations

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

Extract gradient without model_output #112

Closed Rui-Zhou-2 closed 1 year ago

Rui-Zhou-2 commented 2 years ago

Hi, thanks for your project,

I wonder how to extract the gradient that is being updated in the layers, without being measured on the model_output, is there any method for this?

Best regards

utkuozbulak commented 2 years ago

When .backward() is called, any module within model (and the input) that has its required_grad=True will receive gradient. Then, you can simply extract it by calling .grad for that particular module.

Rui-Zhou-2 commented 2 years ago

Yes, but that only return true or false value.

is there any method to visualize the updating gradient on the feature map?

utkuozbulak commented 2 years ago

.requires_grad returns True or False. .grad returns the gradient.