On running the following line of code in main.py, i am getting RuntimeError:
gradients, label_index = calculate_outputs_and_gradients([img], model, None, args.cuda)
Error trace:
RuntimeError Traceback (most recent call last)
in ()
5 img = img[:, :, (2, 1, 0)]
6 # calculate the gradient and the label index
----> 7 gradients, label_index = calculate_outputs_and_gradients([img], model, None, args.cuda)
/dccstor/cssblr/anirban/integrated-gradient-pytorch/utils.pyc in calculate_outputs_and_gradients(inputs, model, target_label_idx, cuda)
21 # clear grad
22 model.zero_grad()
---> 23 output.backward()
24 gradient = input.grad.detach().cpu().numpy()[0]
25 gradients.append(gradient)
/dccstor/anirlaha1/deep/apr2018/lib/python2.7/site-packages/torch/tensor.pyc in backward(self, gradient, retain_graph, create_graph)
100 products. Defaults to ``False``.
101 """
--> 102 torch.autograd.backward(self, gradient, retain_graph, create_graph)
103
104 def register_hook(self, hook):
/dccstor/anirlaha1/deep/apr2018/lib/python2.7/site-packages/torch/autograd/__init__.pyc in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
88 Variable._execution_engine.run_backward(
89 tensors, grad_tensors, retain_graph, create_graph,
---> 90 allow_unreachable=True) # allow_unreachable flag
91
92
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
Please help. Thanks.
On running the following line of code in main.py, i am getting RuntimeError: gradients, label_index = calculate_outputs_and_gradients([img], model, None, args.cuda)
Error trace:
RuntimeError Traceback (most recent call last)