Image reconstruction

After fitting the model, we can reconstruct images using the following code:

# Reconstructing images - train data
rc <- ae_model %>% keras::predict_on_batch(x = trainn)

# Plot par(mfrow = c(8,8), mar = rep(0, 4)) for (i in 1:64) plot(as.raster(rc[i,,,]))

In the preceding code, we have used ae_model to reconstruct the images by providing images with noise contained in trainn. As shown in the following image, we have plotted the first 64 reconstructed images to see if the noisy images become clearer:

From the preceding plot, we can observe that the autoencoder network has successfully removed noise. We can also reconstruct the images for the test data with the help of ae_model using the following code:

# Reconstructing images - test data
rc <- ae_model %>% keras::predict_on_batch(x = testn)
par(mfrow = c(8,8), mar = rep(0, 4))
for (i in 1:64) plot(as.raster(rc[i,,,]))

The resulting images for the first 64 handwritten digits in the test data are as follows:

Here, we can observe that the denoising autoencoder does a decent job of removing noise from the images of 0 to 9 digits. To look more closely at the model's performance, we can plot the first image in the test data, the corresponding image with noise, and the reconstructed image after noise removal, like so:

In the preceding screenshot, the first image is the original image, while the second image is the one that's obtained after adding noise. The autoencoder was provided the second image as input and the results that were obtained from the model (third image) were made to match the first image. Here, we can see that the denoising autoencoder network helps remove noise. Note that the third image is unable to retain some of the finer details of the original image that we can see in the first image. For example, in the original image, seven appears to be slightly thicker at the beginning and toward the lower part compared to the third image. However, it does successfully extract the overall pattern of seven from the image containing digit seven with noise.

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

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