yxlao / reverse-gan.pytorch

Precise Recovery of Latent Vectors from Generative Adversarial Networks in PyTorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyTorch-ReverseGAN

PyTorch implementation of "Precise Recovery of Latent Vectors from Generative Adversarial Networks" https://arxiv.org/abs/1702.04782.

Given the generated image G(z) with z unknown, the goal of ReverseGAN is to find z_approx that approximates z. To achieve this, one can find z_approx that minimizes MSE(G(z_approx), G(z)) through gradient descent.

Setups

Dataset

Download the "Align&Cropped Images" from http://mmlab.ie.cuhk.edu.hk/projects/CelebA.html and unzip.

Training

python dcgan.py --dataset=folder --dataroot=/path/to/dataset --cuda

By default, the generated images and saved models will be saved in dcgan_out directory.

Reverse

After training, run

python dcgan_reverse.py --clip=stochastic --netG=pre_trained/netG_epoch_10.pth --cuda

where --netG points to the model saved during training.

Example results

The following example uses the pre-trained model pre_trained/netG_epoch_10.pth on CelebA aligned dataset.

G(z): the generated image with z

result

G(z_approx): the generated image with the estimated z_approx

result

References

About

Precise Recovery of Latent Vectors from Generative Adversarial Networks in PyTorch

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Python 100.0%