MNIST data

We will make use of MNIST data that's available in the Keras package to illustrate the steps that are involved in creating a denoising autoencoder network. MNIST data can be read using the following code:

# MNIST data
mnist <- dataset_mnist() str(mnist)
List of 2 $ train:List of 2 ..$ x: int [1:60000, 1:28, 1:28] 0 0 0 0 0 0 0 0 0 0 ... ..$ y: int [1:60000(1d)] 5 0 4 1 9 2 1 3 1 4 ... $ test :List of 2 ..$ x: int [1:10000, 1:28, 1:28] 0 0 0 0 0 0 0 0 0 0 ... ..$ y: int [1:10000(1d)] 7 2 1 0 4 1 4 9 5 9 ...

The structure of the MNIST data indicates that it contains train and test data, along with the respective labels. The training data has 60,000 images of digits from 0 to 9. Similarly, the test data has 10,000 images of digits from 0 to 9. Although each image has a corresponding label identifying the image, in this example, the data for labels isn't required and so we will ignore this information.

We will be storing training images in trainx and the test images in testx. To do this, we will use the following code:

# Train and test data
trainx <- mnist$train$x testx <- mnist$test$x

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

The following image shows a plot of 64 images in 8 rows and 8 columns based on images of digits between 0 and 9 from MNIST:

The preceding plot shows handwritten digits in various writing styles. We will reshape this image data in the required format and add random noise to it.

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

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