I’m trying to visualize the feature maps of my network through guided backpropagation. I’m running this through model.eval()
.
My first error, upon the final stages, is RuntimeError: invalid gradient at index 0 - got [1, 6] but expected shape compatible with [1, 10647, 6]
. It seems this stems from:
onehot_out = torch.FloatTensor(1, model_out.size()[-1]).zero_()
so I fix it with:
onehot_out = torch.FloatTensor(1, model_out.size()[1], model_out.size()[-1]).zero_()
This then seems to work, however when I then do the backward pass:
onehot_out[0][target_class] = 1
model_out.backward(gradient = onehot_out)
I get the error present in the title:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [1, 3, 52, 52, 2]], which is output 0 of SigmoidBackward, is a
t version 6; expected version 5 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True)
I’m unsure what this means or where to start looking. Would appreciate any help.