Skip to content

Commit

Permalink
Stash before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
eriklindernoren committed Apr 23, 2018
1 parent 309205e commit e4dedd1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 46 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ See also: [Keras-GAN](https://github.com/eriklindernoren/Keras-GAN)

## Installation
$ git clone https://github.com/eriklindernoren/PyTorch-GAN
$ cd implementations/PyTorch-GAN/
$ cd PyTorch-GAN/
$ sudo pip3 install -r requirements.txt

## Implementations
### AC-GAN
Implementation of _Auxiliary Classifier Generative Adversarial Network_.

[Code](acgan/acgan.py)
[Code](implementations/acgan/acgan.py)

Paper: https://arxiv.org/abs/1610.09585

Expand All @@ -46,7 +46,7 @@ $ python3 acgan.py
### Adversarial Autoencoder
Implementation of _Adversarial Autoencoder_.

[Code](aae/adversarial_autoencoder.py)
[Code](implementations/aae/adversarial_autoencoder.py)

Paper: https://arxiv.org/abs/1511.05644

Expand All @@ -60,7 +60,7 @@ $ python3 aae.py
### CC-GAN
Implementation of _Semi-Supervised Learning with Context-Conditional Generative Adversarial Networks_.

[Code](ccgan/ccgan.py)
[Code](implementations/ccgan/ccgan.py)

Paper: https://arxiv.org/abs/1611.06430

Expand All @@ -73,7 +73,7 @@ $ python3 ccgan.py
### CGAN
Implementation of _Conditional Generative Adversarial Nets_.

[Code](cgan/cgan.py)
[Code](implementations/cgan/cgan.py)

Paper:https://arxiv.org/abs/1411.1784

Expand All @@ -87,7 +87,7 @@ $ python3 cgan.py
### CycleGAN
Implementation of _Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks_.

[Code](cyclegan/cyclegan.py)
[Code](implementations/cyclegan/cyclegan.py)

Paper: https://arxiv.org/abs/1703.10593

Expand All @@ -106,7 +106,7 @@ $ python3 cyclegan.py
### DCGAN
Implementation of _Deep Convolutional Generative Adversarial Network_.

[Code](dcgan/dcgan.py)
[Code](implementations/dcgan/dcgan.py)

Paper: https://arxiv.org/abs/1511.06434

Expand All @@ -119,7 +119,7 @@ $ python3 dcgan.py
### GAN
Implementation of _Generative Adversarial Network_ with a MLP generator and discriminator.

[Code](gan/gan.py)
[Code](implementations/gan/gan.py)

Paper: https://arxiv.org/abs/1406.2661

Expand All @@ -132,7 +132,7 @@ $ python3 gan.py
### LSGAN
Implementation of _Least Squares Generative Adversarial Networks_.

[Code](lsgan/lsgan.py)
[Code](implementations/lsgan/lsgan.py)

Paper: https://arxiv.org/abs/1611.04076

Expand All @@ -145,7 +145,7 @@ $ python3 lsgan.py
### Pix2Pix
Implementation of _Unpaired Image-to-Image Translation with Conditional Adversarial Networks_.

[Code](pix2pix/pix2pix.py)
[Code](implementations/pix2pix/pix2pix.py)

Paper: https://arxiv.org/abs/1611.07004

Expand All @@ -164,7 +164,7 @@ $ python3 pix2pix.py
### SGAN
Implementation of _Semi-Supervised Generative Adversarial Network_.

[Code](sgan/sgan.py)
[Code](implementations/sgan/sgan.py)

Paper: https://arxiv.org/abs/1606.01583

Expand All @@ -177,7 +177,7 @@ $ python3 sgan.py
### SRGAN
Implementation of _Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network_.

[Code](srgan/srgan.py)
[Code](implementations/srgan/srgan.py)

Paper: https://arxiv.org/abs/1609.04802

Expand All @@ -195,7 +195,7 @@ $ python3 srgan.py
### WGAN
Implementation of _Wasserstein GAN_ (with DCGAN generator and discriminator).

[Code](wgan/wgan.py)
[Code](implementations/wgan/wgan.py)

Paper: https://arxiv.org/abs/1701.07875

Expand Down
34 changes: 17 additions & 17 deletions implementations/aae/aae.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class Encoder(nn.Module):
def __init__(self):
super(Encoder, self).__init__()

layers = [ nn.Linear(opt.img_size**2, 512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, opt.latent_dim)]

self.model = nn.Sequential(*layers)
self.model = nn.Sequential(
nn.Linear(opt.img_size**2, 512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, opt.latent_dim)
)

def forward(self, img):
img_flat = img.view(img.shape[0], -1)
Expand All @@ -63,15 +63,15 @@ class Decoder(nn.Module):
def __init__(self):
super(Decoder, self).__init__()

layers = [ nn.Linear(opt.latent_dim, 512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, opt.img_size**2),
nn.Tanh()]

self.model = nn.Sequential(*layers)
self.model = nn.Sequential(
nn.Linear(opt.latent_dim, 512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, 512),
nn.BatchNorm1d(512),
nn.LeakyReLU(0.2, inplace=True),
nn.Linear(512, opt.img_size**2),
nn.Tanh()
)

def forward(self, noise):
img_flat = self.model(noise)
Expand Down
26 changes: 13 additions & 13 deletions implementations/acgan/acgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ def __init__(self):
self.init_size = opt.img_size // 4 # Initial size before upsampling
self.l1 = nn.Sequential(nn.Linear(opt.latent_dim, 128*self.init_size**2))

cnn_layers = [ nn.BatchNorm2d(128),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 128, 3, stride=1, padding=1),
nn.BatchNorm2d(128, 0.8),
nn.LeakyReLU(0.2, inplace=True),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 64, 3, stride=1, padding=1),
nn.BatchNorm2d(64, 0.8),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(64, opt.channels, 3, stride=1, padding=1),
nn.Tanh() ]

self.conv_blocks = nn.Sequential(*cnn_layers)
self.conv_blocks = nn.Sequential(
nn.BatchNorm2d(128),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 128, 3, stride=1, padding=1),
nn.BatchNorm2d(128, 0.8),
nn.LeakyReLU(0.2, inplace=True),
nn.Upsample(scale_factor=2),
nn.Conv2d(128, 64, 3, stride=1, padding=1),
nn.BatchNorm2d(64, 0.8),
nn.LeakyReLU(0.2, inplace=True),
nn.Conv2d(64, opt.channels, 3, stride=1, padding=1),
nn.Tanh()
)

def forward(self, noise, labels):
gen_input = torch.mul(self.label_emb(labels), noise)
Expand Down
7 changes: 4 additions & 3 deletions implementations/ccgan/ccgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
parser.add_argument('--img_size', type=int, default=32, help='size of each image dimension')
parser.add_argument('--mask_size', type=int, default=8, help='size of random mask')
parser.add_argument('--channels', type=int, default=1, help='number of image channels')
parser.add_argument('--sample_interval', type=int, default=1000, help='interval between image sampling')
parser.add_argument('--sample_interval', type=int, default=500, help='interval between image sampling')
opt = parser.parse_args()
print(opt)

Expand Down Expand Up @@ -141,5 +141,6 @@ def apply_random_mask(imgs):
print ("[Epoch %d/%d] [Batch %d/%d] [D loss: %f] [G loss: %f]" % (epoch, opt.n_epochs, i, len(cifar_loader),
d_loss.data.cpu().numpy()[0], g_loss.data.cpu().numpy()[0]))

save_image(torch.cat((real_imgs.data, gen_imgs.data) -2),
'images/%d.png' % epoch, nrow=int(math.sqrt(opt.batch_size)), normalize=True)
if i % opt.sample_interval == 0:
save_image(torch.cat((masked_imgs.data[:5], gen_imgs.data[:5], real_imgs.data[:5]), -2),
'images/%d.png' % epoch, nrow=int(math.sqrt(opt.batch_size)), normalize=True)

0 comments on commit e4dedd1

Please sign in to comment.