diff options
author | nunzip <np.scarh@gmail.com> | 2019-03-14 13:05:42 +0000 |
---|---|---|
committer | nunzip <np.scarh@gmail.com> | 2019-03-14 13:05:42 +0000 |
commit | a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38 (patch) | |
tree | 040087555e0f1f9b560fea277691df9187918beb | |
parent | a657a5071f6c091461c6d899b5f022d52f96bb43 (diff) | |
download | e4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.tar.gz e4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.tar.bz2 e4-gan-a4ce2edb09f2c8d0b200b9f77f8df3fd89643b38.zip |
Add artificial balancing
-rwxr-xr-x | ncdcgan.py | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -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 |