def train_gan(wgan, batch_gen, noise_shapes, steps_per_epoch, num_epochs, application="mch"): img_shape = batch_gen.img_shape noise_gen = noise.NoiseGenerator(noise_shapes(img_shape), batch_size=batch_gen.batch_size) for epoch in range(num_epochs): print("Epoch {}/{}".format(epoch + 1, num_epochs)) wgan.train(batch_gen, noise_gen, steps_per_epoch, training_ratio=5) plots.plot_samples( wgan.gen, batch_gen, noise_gen, application=application, out_fn="../figures/progress_{}.pdf".format(application)) return wgan
def train_gan(gan, batch_gen, noise_gen, num_epochs=1, steps_per_epoch=1, plot_fn=None): gan.fit_generator(batch_gen, noise_gen, num_epochs=num_epochs, steps_per_epoch=steps_per_epoch) plots.plot_samples(gan.gen, batch_gen, noise_gen, out_fn=plot_fn)
fs_loss = f_gan.train_generator() # f stacked fd_loss, fd_acc = f_gan.train_discriminator() # f discriminator gs_loss = g_gan.train_generator() # g stacked gd_loss, gd_acc = g_gan.train_discriminator() # g discriminator leftinv_loss = cycle_gan.train_left_inverse() rightinv_loss = cycle_gan.train_right_inverse() if train.log: print(f'{fs_loss:1.5f} {gs_loss:1.5f} {fd_acc:.5f} {gd_acc:.5f}') if train.make_samples: g_sample = f_gan.generate_sample(5) train.append_sample(g_sample, 'samples/sample_{gen:03.0f}_{i:02.0f}.png') train.append_stats(fs_loss, fd_loss, fd_acc, gs_loss, gd_loss, gd_acc, leftinv_loss, rightinv_loss) except KeyboardInterrupt: pass else: train.compile_records() plot_samples(train.samples) plot_stats(train.stats) save_model(f_gan.generator) save_model(g_gan.generator)