Hi,
to expand a bit on smth’s explanation:



 adrianalbert:

img_output.backward(gradient=torch.ones(img_input.size(), retain_variables=True)


this is (mathematically) equivalent to
img_output_sum = img_output.sum()
img_output.backward()

only that you computed the gradient of the sum (which is all ones) manually.
If you wanted the complete derivative, you would have many backwards (with keep_variables/keep_graph).
Best regards
Thomas