How it works...

In step 1, we initialized variables to set model parameters. The latent_dim variable sets the dimensionality of the encoded features. Then, we created an input layer of the autoencoder. In step 2, we built an encoder model. We first created convolutional layers of the encoder and then extracted the output shape of the last convolutional layer. Next, we added a flattened layer and then connected a dense layer with units equal to the latent_dim variable. In the next step, we built the decoder model. We defined an input layer for the decoder, which receives an input of a shape equal to latent_dim.

Next, we added layers in the decoder such that we reverse the operations of an encoder. In step 4, we combined encoder and decoder and built an autoencoder. In the next step, we compiled and trained the autoencoder for 20 epochs. We used mean squared error as the loss function and adam as the optimizer. In the last step, we input black and white images and colorized them.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset