RuntimeError: Output 0 of BackwardHookFunctionBackward is a view and is being modified inplace. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.
使用grad_cam 时报错了
参考如下:
https://discuss.pytorch.org/t/getting-this-warning-output-0-of-backwardhookfunctionbackward-is-a-view-and-is-being-modified-inplace/122766
激活函数的问题。
将self.relu1 = nn.ReLU(inplace=True) 改为: self.relu1 = nn.ReLU()
即可