concept MNIST dataset in category deep learning

appears as: MNIST dataset, The MNIST dataset, MNIST dataset, MNIST datasets
Deep Learning for Vision Systems

This is an excerpt from Manning's book Deep Learning for Vision Systems.

If you train the above MLP on the MNIST dataset you will get pretty good results (close to 96% accuracy compared to 99% with CNNs). But MLPs and CNNs do not usually yield comparable results. The MNIST dataset is very special because it is very clean and perfectly preprocessed. For example, all images have the same size and are centered in a 28x28 pixel grid. Also, the MNIST dataset contains only grayscale images. It would be a much harder task if the images are colored or digits were skewed a little or not centered.

We saw how LeNet performed very well on the MNIST dataset. But it turns out that the MNIST dataset is very simple because it contains gray scale images (1 channel) and classified into only 10 classes which makes it a simpler challenge. The main motivation behind AlexNet was to build a deeper network that can learn more complex functions.

Figure 6.12: a sample image of the MNIST dataset.
def generator_model():
# instantiate a sequential model and name it generator
       generator = Sequential()
# add the Dense layer that has a number of neurons = 128x7x7
       generator.add(Dense(128 * 7 * 7, activation="relu", input_dim=100))
# reshape the image dimensions to 7 x 7 x 128
       generator.add(Reshape((7, 7, 128)))
# upsampling layer to double the size of the image dimensions to 14 x 14
       generator.add(UpSampling2D(size=(2,2)))
 
# add a convolutional layer to run the convolutional process + batchNorm
       generator.add(Conv2D(128, kernel_size=3, padding="same", activation="relu"))
       generator.add(BatchNormalization(momentum=0.8))
# upsample the image dimensions to 28 x 28
       generator.add(UpSampling2D(size=(2,2)))
 
# conv + batchNorm layers
# notice that we didn’t add upsampling here because we have the image size of 28 x 28 which is equal to the image size in the MNIST dataset. You can adjust this for your own problem.
       generator.add(Conv2D(64, kernel_size=3, padding="same", activation="relu"))
       generator.add(BatchNormalization(momentum=0.8))
 
# convolutional layer with filters = 1
       generator.add(Conv2D(1, kernel_size=3, padding="same", activation="relu"))
 
# print the model summary
       generator.summary()
 
# generate the input noise vector of length = 100
# we chose 100 here to create a simple network
       noise = Input(shape=(100,))
# run the generator model to create the fake image
       fake_image = generator(noise)
# return a model that takes the noise vector as an input and outputs the fake image
       return Model(noise, fake_image)
Grokking Deep Learning

This is an excerpt from Manning's book Grokking Deep Learning.

In the MNISTPreprocessor notebook is a script to preprocess the MNIST dataset and load the first 1,000 images and labels into two NumPy matrices called images and labels. You may be wondering, “Images are two-dimensional. How do I load the (28 × 28) pixels into a flat neural network?” For now, the answer is simple: flatten the images into a vector of 1 × 784. You’ll take the first row of pixels and concatenate them with the second row, and the third row, and so on, until you have one list of pixels per image (784 pixels long).

Here’s a non-obvious question: how well will the neural network do on an image it hasn’t seen before? In other words, how well will it do on an image that wasn’t part of the 1,000 images it was trained on? The MNIST dataset has many more images than just the 1,000 you trained on; let’s try it.