CycleGAN in TensorFlow 2.0
In the last section of this chapter we will implement a CycleGAN in TensorFlow 2.0. The CycleGAN requires a special dataset, a paired dataset, from one domain of images to another domain. So, besides the necessary modules, we will use tensorflow_datasets
as well:
import tensorflow as tf
from tensorflow.keras import Model
from tensorflow.keras.losses import mean_squared_error, mean_absolute_error
import os
import time
import matplotlib.pyplot as plt
import numpy as np
import tensorflow_datasets as tfds
TensorFlow's Dataset
API contains a list of datasets. It has many paired datasets for CycleGANs, such as horse to zebra, apples to oranges, and so on. You can access the complete list here: https://www.tensorflow.org/datasets/catalog/cycle_gan. For our code we will be using summer2winter_yosemite
, which contains images of Yosemite (USA) in summer (Dataset A) and winter (Dataset B). We will train the CycleGAN to convert...