I am trying to run the code below but I get the error
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
I don’t see where the inplace operation is because I am able to run the first loop. I am trying to get the output of backprop repeatedly after a forward pass.
model_output = self.model(input_image)[0][0].squeeze() for box in boxes_0: self.model.zero_grad() roi = model_output.clone() roi = torch.cuda.FloatTensor(model_output.size()).zero_() roi[0,box[1]:box[3],box[0]:box[2]] = 1 roi = roi.unsqueeze(0) model_output.backward(gradient=roi,retain_graph=True) gradients_as_arr0 = self.gradients.data.cpu().numpy()[0] gradients_as_arr0 = np.transpose(gradients_as_arr0, [1,2,0]) grads.append(gradients_as_arr0)
Traceback (most recent call last):
File “/usr/lib/python3.6/runpy.py”, line 193, in _run_module_as_main
“main”, mod_spec)
File “/usr/lib/python3.6/runpy.py”, line 85, in _run_code
exec(code, run_globals)
File “/home/haziq/openpifpaf_crm_pose/openpifpaf/backprop.py”, line 347, in
main()
File “/home/haziq/openpifpaf_crm_pose/openpifpaf/backprop.py”, line 279, in main
guided_grads0 = GBP.generate_gradients_new(data)
File “/home/haziq/openpifpaf_crm_pose/openpifpaf/backprop.py”, line 190, in generate_gradients_new
model_output.backward(gradient=roi,retain_graph=True)
File “/home/haziq/env_crm/lib/python3.6/site-packages/torch/tensor.py”, line 102, in backward
torch.autograd.backward(self, gradient, retain_graph, create_graph)
File “/home/haziq/env_crm/lib/python3.6/site-packages/torch/autograd/init.py”, line 90, in backward
allow_unreachable=True) # allow_unreachable flag
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation