So what I need is to calculate the derivative the the NN with respect to the input, something like: dx = torch.augograd.grad(NN(x),x) and then add this derivative to the loss and backpropagate. For example loss = (NN(x)-x)**2+abs(dx) and then loss.backward(). Won’t the value of x itself be changed if I have x.requires_grad? For example if x represent the pixels of an image, won’t the value of the pixels themselves be affected i.e. the image will change?