From f00bc97bcb820d30d73fed37eb5c0d5ffddcd9ca Mon Sep 17 00:00:00 2001 From: nunzip Date: Mon, 4 Mar 2019 21:06:27 +0000 Subject: Add One-sided smoothing --- cgan.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cgan.py') diff --git a/cgan.py b/cgan.py index 5ab0c10..880a8b8 100755 --- a/cgan.py +++ b/cgan.py @@ -107,7 +107,7 @@ class CGAN(): return Model([img, label], validity) - def train(self, epochs, batch_size=128, sample_interval=50, graph=False): + def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth=False): # Load the dataset (X_train, y_train), (_, _) = mnist.load_data() @@ -140,7 +140,10 @@ class CGAN(): gen_imgs = self.generator.predict([noise, labels]) # Train the discriminator - d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid) + if smooth == True: + d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*0.9) + else: + d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid) d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake) d_loss = 0.5 * np.add(d_loss_real, d_loss_fake) -- cgit v1.2.3-54-g00ecf From 6529cc095c57e375f34d69fb6bfb36d058dd2192 Mon Sep 17 00:00:00 2001 From: nunzip Date: Mon, 4 Mar 2019 21:38:17 +0000 Subject: Improve one sided smoothing --- cgan.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cgan.py') diff --git a/cgan.py b/cgan.py index 880a8b8..ebdfab2 100755 --- a/cgan.py +++ b/cgan.py @@ -142,9 +142,10 @@ class CGAN(): # Train the discriminator if smooth == True: d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*0.9) + d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], valid*0.1) else: d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid) - d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake) + d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake) d_loss = 0.5 * np.add(d_loss_real, d_loss_fake) # --------------------- -- cgit v1.2.3-54-g00ecf From 34057507d6b7ae5cafd2b7b8cb2b69c20780ffd5 Mon Sep 17 00:00:00 2001 From: nunzip Date: Mon, 4 Mar 2019 21:53:18 +0000 Subject: Make single sided smoothing parameters accessible --- cgan.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'cgan.py') diff --git a/cgan.py b/cgan.py index ebdfab2..6406244 100755 --- a/cgan.py +++ b/cgan.py @@ -107,7 +107,7 @@ class CGAN(): return Model([img, label], validity) - def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth=False): + def train(self, epochs, batch_size=128, sample_interval=50, graph=False, smooth_real=1, smooth_fake=0): # Load the dataset (X_train, y_train), (_, _) = mnist.load_data() @@ -140,12 +140,8 @@ class CGAN(): gen_imgs = self.generator.predict([noise, labels]) # Train the discriminator - if smooth == True: - d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid*0.9) - d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], valid*0.1) - else: - d_loss_real = self.discriminator.train_on_batch([imgs, labels], valid) - d_loss_fake = self.discriminator.train_on_batch([gen_imgs, labels], fake) + 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) # --------------------- -- cgit v1.2.3-54-g00ecf