Using Forward-Pass in a Deep Network
In this project, I make inference using a pre-trained deep
network, namely a Multi-layer Perceptron (MLP). To be specific, we look at the problem of
image classification where we assign a label y (e.g. ‘car’, ‘house’, ‘smiling’, ‘digit 0’) to an image
x provided as input. For example, the image can be the image of a digit (as shown in the picture below, namely Figure 1),
and the estimated label can be digit 4. To provide our input to an MLP, we first transform
the image into a 1D vector, as illustrated in Figure 1. For this, the image is scanned row by row
and the concatenation of all the rows is taken as the vector representation of the image. Then,
the network will provide us prediction score for each class. Finally, our estimated label, y-pred,
will be the class with the highest score.
The deep network shema:
– mnist.pkl: A file containing 1000 digit images and their labels.
– network_3layer.pkl: A file for a pre-trained MLP with 3 linear layers.
– network_2layer.pkl: A file for a pre-trained MLP with 2 linear layers.
– utils.py: A Python module with a set of utilities load_dataset, load_network, display_image, display_network, calculate_accuracy.
To get the result, run main.py. The order of the output will be in the following:
- Visualising the image using ASCII chars.
- The correct label for the image above.
3-4. An array displaying a total of 10 float numbers. The index of the highest number is the correct label for the image.
5-6. The accuracy percent of networks by using calculate_accuracy function in utility for network1 and network2.
In example 1, 6. index of both of the arrays is the highest value, this shows that the number displaying above is six. Additionally, in example 2 index with one of both of the arrays is the highest value, so it shows that the number displaying above is 1.
For the other images, we can change the second index of dataset["X_test"][] and dataset["y_test"][] from 0to 784 and examine the resulting arrays.