16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Autoencoders

As shown in Figure 3.4.1, if we are given a grayscale photo of a rice field on the

foreground, a volcano in the background and sky on top, we're able to add the

appropriate colors.

Figure 3.4.1: Adding color to a grayscale photo of the Mayon Volcano. A colorization network should replicate

human abilities by adding color to a grayscale photo. Left photo is grayscale. The right photo is color. Original

color photo can be found on the book GitHub repository, https://github.com/PacktPublishing/Advanced-

Deep-Learning-with-Keras/blob/master/chapter3-autoencoders/README.md.

A simple automatic colorization algorithm seems like a suitable problem for

autoencoders. If we can train the autoencoder with a sufficient number of grayscale

photos as input and the corresponding colored photos as output, it could possibly

discover the hidden structure on properly applying colors. Roughly, it is the reverse

process of denoising. The question is, can an autoencoder add color (good noise)

to the original grayscale image?

Listing 3.4.1 shows the colorization autoencoder network. The colorization

autoencoder network is a modified version of denoising autoencoder that we

used for the MNIST dataset. Firstly, we need a dataset of grayscale to colored

photos. The CIFAR10 database, which we have used before, has 50,000 training

and 10,000 testing 32 × 32 RGB photos that can be converted to grayscale. As shown

in the following listing, we're able to use the rgb2gray() function to apply weights

on R, G, and B components to convert from color to grayscale.

Listing 3.4.1, colorization-autoencoder-cifar10-3.4.1.py, shows us

a colorization autoencoder using the CIFAR10 dataset:

from keras.layers import Dense, Input

from keras.layers import Conv2D, Flatten

[ 90 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!