From 03f2c41ac69084cde7a61eb04303078e3c4785a7 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Wed, 13 Mar 2019 20:03:09 +0000 Subject: Update cdcgan with *better* one --- cdcgan.py | 20 +++++++------------- dcgan.py | 5 ++--- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/cdcgan.py b/cdcgan.py index 7b517ca..01368ac 100755 --- a/cdcgan.py +++ b/cdcgan.py @@ -65,22 +65,16 @@ class CDCGAN(): model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim)) model.add(Reshape((7, 7, 128))) - model.add(UpSampling2D()) - for i in range(self.conv_layers): - model.add(Conv2D(128, kernel_size=3, padding="same")) - model.add(BatchNormalization()) - model.add(Activation("relu")) - - model.add(UpSampling2D()) - - for i in range(self.conv_layers): - model.add(Conv2D(64, kernel_size=3, padding="same")) - model.add(BatchNormalization()) + model.add(Conv2DTranspose(256, kernel_size=3, padding="same", strides=(2,2))) + model.add(BatchNormalization()) + model.add(Activation("relu")) - model.add(Activation("relu")) + model.add(Conv2DTranspose(128, kernel_size=3, padding="same", strides=(2,2))) + model.add(BatchNormalization()) + model.add(Activation("relu")) - model.add(Conv2D(self.channels, kernel_size=3, padding="same")) + model.add(Conv2DTranspose(64, kernel_size=3, padding="same")) model.add(Activation("tanh")) #model.summary() diff --git a/dcgan.py b/dcgan.py index 347f61e..719e096 100644 --- a/dcgan.py +++ b/dcgan.py @@ -1,4 +1,5 @@ from __future__ import print_function, division +import tensorflow.keras as keras from keras.datasets import mnist from keras.layers import Input, Dense, Reshape, Flatten, Dropout from keras.layers import BatchNormalization, Activation, ZeroPadding2D @@ -75,7 +76,7 @@ class DCGAN(): model.add(Conv2D(self.channels, kernel_size=3, padding="same")) model.add(Activation("tanh")) - #model.summary() + model.summary() noise = Input(shape=(self.latent_dim,)) img = model(noise) @@ -187,8 +188,6 @@ class DCGAN(): fig.savefig("images/mnist_%d.png" % epoch) plt.close() -''' if __name__ == '__main__': dcgan = DCGAN() dcgan.train(epochs=4000, batch_size=32, save_interval=50) -''' -- cgit v1.2.3-54-g00ecf