In this resource https://github.com/seangal/dcgan_vae_pytorch/blob/master/main.py
it shows how to train a VaE+GAN architecture, by training the discriminator on noise and real data, and the generator on reconstructed data (which have to fool the discriminator).
My problem is that when I run the code on a face dataset, although the discriminator can tell between noise-generated and real examples, it completely fails to detect the reconstructed examples as fake. If I stop training the generator, the discriminator can tell the difference. However it seems with the generator being trained, it may be creating adversarial examples against the discriminator which still look like random noise.
Would it theoretically be a mistake to train the discriminator on both noise generated examples and reconstructed examples?
I had to follow the training procedures of the paper more closely and base my code on DCGAN. Eventually I made it work, and you can take a look at my repo (it also contains code for swapping latent encodings between images but you can turn it off). the repo is at https://github.com/DimTrigkakis/TrueRelations
Hello my friends. I just find a possible solution to share with you.
If we just use a.backward(), it will perform the simplest form of back propagation.
>>> a = torch.autograd.Variable(torch.Tensor([1]), requires_grad=True)
>>> b = a * 2
>>> b.backward()
>>> a.grad.data
tensor([2.])
However, if we input the parameter of .backward() like -1 (which I find should be a tensor.autograd.Variable ), we can back propagate in a reverse direction.
>>> a = torch.autograd.Variable(torch.Tensor([1]), requires_grad=True)
>>> b = a * 2
>>> z = torch.autograd.Variable(torch.Tensor([-1]), requires_grad=True)
>>> b.backward(z)
>>> a.grad.data
tensor([-2.])
However, if we input just 1 (which is also a tensor.autograd.Variable), it is the same as the default situation.
>>> a = torch.autograd.Variable(torch.Tensor([1]), requires_grad=True)
>>> z = torch.autograd.Variable(torch.Tensor([1]), requires_grad=True)
>>> b = a * 2
>>> b.backward(z)
>>> a.grad.data
tensor([2.])