d444fdae4b30d35f3cfba98c9fa9e3169cc2cf69,discogan/discogan.py,DiscoGAN,train,#DiscoGAN#,169
Before Change
// ------------------
// Sample a batch of images from both domains
imgs_A, imgs_B = self.data_loader.load_data(batch_size=batch_size)
// The generators want the discriminators to label the translated images as real
valid = np.ones((batch_size,) + self.disc_patch)
After Change
for epoch in range(epochs):
for batch_i, (imgs_A, imgs_B) in enumerate(self.data_loader.load_batch(batch_size)):
// ----------------------
// Train Discriminators
// ----------------------
// Translate images to opposite domain
fake_B = self.g_AB.predict(imgs_A)
fake_A = self.g_BA.predict(imgs_B)
valid = np.ones((batch_size,) + self.disc_patch)
fake = np.zeros((batch_size,) + self.disc_patch)
// Train the discriminators (original images = real / translated = Fake)
dA_loss_real = self.d_A.train_on_batch(imgs_A, valid)
dA_loss_fake = self.d_A.train_on_batch(fake_A, fake)
dA_loss = 0.5 * np.add(dA_loss_real, dA_loss_fake)
dB_loss_real = self.d_B.train_on_batch(imgs_B, valid)
dB_loss_fake = self.d_B.train_on_batch(fake_B, fake)
dB_loss = 0.5 * np.add(dB_loss_real, dB_loss_fake)
// Total disciminator loss
d_loss = 0.5 * np.add(dA_loss, dB_loss)
// ------------------
// Train Generators
// ------------------
// The generators want the discriminators to label the translated images as real
valid = np.ones((batch_size,) + self.disc_patch)
// Train the generators
g_loss = self.combined.train_on_batch([imgs_A, imgs_B], [valid, valid, \
imgs_B, imgs_A, \
imgs_A, imgs_B])
elapsed_time = datetime.datetime.now() - start_time
// Plot the progress
print ("[%d] [%d/%d] time: %s, [d_loss: %f, g_loss: %f]" % (epoch, batch_i,
self.data_loader.n_batches,
elapsed_time,
d_loss[0], g_loss[0]))
// If at save interval => save generated image samples
if batch_i % save_interval == 0:
self.save_imgs(epoch, batch_i)
def save_imgs(self, epoch, batch_i):
os.makedirs("images/%s" % self.dataset_name, exist_ok=True)
r, c = 2, 3
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 7
Instances Project Name: eriklindernoren/Keras-GAN
Commit Name: d444fdae4b30d35f3cfba98c9fa9e3169cc2cf69
Time: 2018-03-15
Author: eriklindernoren@gmail.com
File Name: discogan/discogan.py
Class Name: DiscoGAN
Method Name: train
Project Name: eriklindernoren/Keras-GAN
Commit Name: 64a2763f3e0ff21c6de3bbbe6cbddab1857fc080
Time: 2018-04-16
Author: eriklindernoren@gmail.com
File Name: cyclegan/cyclegan.py
Class Name: CycleGAN
Method Name: train
Project Name: eriklindernoren/Keras-GAN
Commit Name: 5c18953a3da18402d3fcc9ff96d1e983d48c98cb
Time: 2018-04-16
Author: eriklindernoren@gmail.com
File Name: pix2pix/pix2pix.py
Class Name: Pix2Pix
Method Name: train