pytorch-grad-cam icon indicating copy to clipboard operation
pytorch-grad-cam copied to clipboard

set required_grad=True when init basecam class

Open KKQanT opened this issue 1 year ago • 1 comments

I encountered the error AxisError: axis 2 is out of bounds for array of dimension 0, which was caused by the value of grads(the input of the function get_cam_weights in every CAM class) being None. This occurred because no gradient was able to compute, due to the fact that model.required_grad was set to false during the training process by the user.

KKQanT avatar Jul 20 '23 14:07 KKQanT

Hi and sorry for the late reply.

Maybe it makes sense to return the requires_grad to the initial state it was, when finishing?

Because this would alter the state of the model, and could affect training.

jacobgil avatar Oct 06 '23 16:10 jacobgil