Feeding Custom Images to CycleGANs using TensorFlow

Vedant Joshi
2 min readJan 5, 2021

“The coolest idea in deep learning in the last 20 years.” — Yann LeCun on GANs.

This blog expects you to have basic knowledge of CycleGANs and explains how to train it on a set of custom images(it can be web scraped or it can be from a Kaggle dataset or anywhere, unless it stored in a directory).

The basic Example of CycleGAN is horse2zebra which is preloaded in tensorflow_dataset under the name ‘cycle_gan/horse2zebra’ which consists of thousands of horse and zebra images converted to tensors. And when a CycleGAN is trained on those images the generator(the part of Neural Network which generated image) is capable of generating a zebra image when feed on an image of horse or vice-a-versa.

Here we are doing something similar but the conversion is from elephants to zebra (not in geometry, it’s a limitation of CycleGAN). So the GAN is basically going to generate an image of elephant with stripes when feed an elephant image as seen in initial figure.

The dataset we are going to use here is a subset of images downloaded from Kaggle Animals-10 dataset. Once you’ve downloaded the dataset you’re ready to convert elephants to zebras (elephants with stripes).

The data directory considered here is DATA and the path of elephant images would be DATA/raw-img/elefante/

Initially we will have to convert the images to tensors as shown below (you can play with the values here)

As you are done with converting the images to tensors you can now train the model as a simple CycleGAN model.

The entire code for this blog can be found here.

A similar example to convert monet to photos can be found here.

(After training observations and hurdles to be posted soon)

--

--

Vedant Joshi

A Machine learning Research enthusiast trying to serve humanity using Artificial Intelligence in Medical Domain