how to compute the gradient of an image in pytorch.
I need to compute the gradient(dx, dy) of an image, so how to do it in pytroch?
here is a reference code (I am not sure can it be for computing the gradient of an image  )
import torch
from torch.autograd import Variable
w1 = Variable(torch.Tensor([1.0,2.0,3.0]),requires_grad=True)
w2 = Variable(torch.Tensor([1.0,2.0,3.0]),requires_grad=True)
print(w1.grad)
print(w2.grad)
d = torch.mean(w1)
d.backward()
w1.grad
( here is 0.3333  0.3333 0.3333)
d.backward()
w1.grad
(here is 0.6667 0.6667 0.6667)
why the grad is changed, what the backward function do?
maybe this question is a little stupid, any help appreciated!