def process(self): images_A = get_image_paths(self.arguments.input_A) images_B = get_image_paths(self.arguments.input_B) images_A = load_images(images_A) / 255.0 images_B = load_images(images_B) / 255.0 images_A += images_B.mean(axis=(0, 1, 2)) - \ images_A.mean(axis=(0, 1, 2)) print('press "q" to stop training and save model') BATCH_SIZE = 64 for epoch in range(1000000): warped_A, target_A = get_training_data(images_A, BATCH_SIZE) warped_B, target_B = get_training_data(images_B, BATCH_SIZE) loss_A = autoencoder_A.train_on_batch(warped_A, target_A) loss_B = autoencoder_B.train_on_batch(warped_B, target_B) print(loss_A, loss_B) if epoch % 100 == 0: self.save_model_weights() self.show_sample(target_A[0:14], target_B[0:14]) key = cv2.waitKey(1) if key == ord('q'): self.save_model_weights() exit()
def process(self): print('Starting, this may take a while...') images_A = get_image_paths(self.arguments.input_A) images_B = get_image_paths(self.arguments.input_B) images_A = load_images(images_A) / 255.0 images_B = load_images(images_B) / 255.0 images_A += images_B.mean(axis=(0, 1, 2)) - images_A.mean(axis=(0, 1, 2)) print('press "q" to stop training and save model') BATCH_SIZE = 64 for epoch in range(1000000): if self.arguments.verbose: print("Iteration number {}".format(epoch + 1)) start_time = time.time() warped_A, target_A = get_training_data(images_A, BATCH_SIZE) warped_B, target_B = get_training_data(images_B, BATCH_SIZE) loss_A = autoencoder_A.train_on_batch(warped_A, target_A) loss_B = autoencoder_B.train_on_batch(warped_B, target_B) print(loss_A, loss_B) if epoch % self.arguments.save_interval == 0: self.save_model_weights() self.show_sample(target_A[0:14], target_B[0:14]) key = cv2.waitKey(1) if key == ord('q'): self.save_model_weights() exit() if self.arguments.verbose: end_time = time.time() time_elapsed = int(round((end_time - start_time))) m, s = divmod(time_elapsed, 60) h, m = divmod(m, 60) print("Iteration done in {:02d}h{:02d}m{:02d}s".format( h, m, s))
cv2.imwrite( '_sample.jpg', figure ) images_A = get_image_paths( 'data/trump' ) images_B = get_image_paths( 'data/cage' ) images_A = load_images( images_A ) / 255.0 images_B = load_images( images_B ) / 255.0 images_A += images_B.mean( axis=(0,1,2) ) - images_A.mean( axis=(0,1,2) ) print( 'press "q" to stop training and save model' ) BATCH_SIZE = 64 for epoch in range(1000000): warped_A, target_A = get_training_data( images_A, BATCH_SIZE ) warped_B, target_B = get_training_data( images_B, BATCH_SIZE ) loss_A = autoencoder_A.train_on_batch( warped_A, target_A ) loss_B = autoencoder_B.train_on_batch( warped_B, target_B ) print( loss_A, loss_B ) if epoch % 100 == 0: save_model_weights() show_sample(target_A[0:14], target_B[0:14]) key = cv2.waitKey(1) if key == ord('q'): save_model_weights() exit()