aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornunzip <np.scarh@gmail.com>2019-03-14 13:05:42 +0000
committernunzip <np.scarh@gmail.com>2019-03-14 13:05:42 +0000
commita4ce2edb09f2c8d0b200b9f77f8df3fd89643b38 (patch)
tree040087555e0f1f9b560fea277691df9187918beb
parenta657a5071f6c091461c6d899b5f022d52f96bb43 (diff)
downloade4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.tar.gz
e4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.tar.bz2
e4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.zip
Add artificial balancing
-rwxr-xr-xncdcgan.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/ncdcgan.py b/ncdcgan.py
index 97b137b..65c5862 100755
--- a/ncdcgan.py
+++ b/ncdcgan.py
@@ -148,7 +148,7 @@ class nCDCGAN():
model.summary()
return model
- def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth_real=1, smooth_fake=0):
+ def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth_real=1, smooth_fake=0, gdbal = 1):
# Load the dataset
(X_train, y_train), (_, _) = mnist.load_data()
@@ -181,9 +181,12 @@ class nCDCGAN():
gen_imgs = self.generator.predict([noise, labels])
# Train the discriminator
- d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*smooth_real)
- d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], valid*smooth_fake)
- d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
+ if epoch % gdbal == 0:
+ d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*smooth_real)
+ d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], valid*smooth_fake)
+ d_loss = 0.5 * np.add(d_loss_real, d_loss_fake)
+ else:
+ dloss = 0
# ---------------------
# Train Generator