Hi,
I’m developing a model that takes a 3-channel input image, and outputs a 3-channel output image of the same size (256 x 256). I’m trying to get the gradient of the output image with respect to the input image. My code looks like below:
img_input = torch.autograd.Variable(img_input_tensor, requires_gradient=True)
img_output = model.forward(img_input)
img_output.backward(gradient=torch.ones(img_input.size(), retain_variables=True)
grad_img_input = img_input.grad
The output gradient shape is 3 x 256 x 256.
I’m having an understanding difficulty here: isn’t the gradient of a (3x256x256)-element vector with respect to (3x256x256) variables of shape (3x256x256, 3x256x256)? Or what gradient is being returned in img_input.grad?