I’m trying to implement the WGAN using PyTorch.
I’ve found there is a way to do that:
        prob =self.D(input_image)
        # calculate ∂D(input_image) / ∂input_image
        grad = torch.autograd.grad(outputs=prob , inputs=input_image,
                                               grad_outputs=torch.ones(prob .size()).cuda(),
                                               create_graph=True, retain_graph=True)[0]

But the code version is very old and I’m not sure if it’s the correct way to do it. Anyone knows how to implement the GP elegantly using latest version? Thanks in advance.