Part One: Image Classification with Tensorflow & Python.

Brief walk through how a Neural Network Classifies Various Items of Clothing.πŸ‘—πŸ‘–πŸ‘žπŸ‘’

Job Collins
4 min readMar 13, 2019
Photo by NordWood Themes on Unsplash

The Dataset

In order for us to be able to train a model to identify different items of clothing we need a comprehensive dataset.

Enter the Fashion-MNIST dataset!

The Fashion-MNIST dataset contains 70,000 images of clothing β€” 60,000 of those as training examples and 10,000 as testing examples. Each example is a 28 by 28 grayscale images.

Sample of The Fashion-MNIST dataset.

Each image is associated with a label from the 10 different items in the dataset. Given an image as an input, these labels are the possible outputs.

The different labels in the Fashion-MNIST dataset.

We aim to feed a 28 x 28 image (784 bytes) as an input to a neural network, so that the neural network can classify the image as one of the item labels (hopefully the right label).

Overview: A rough sketch of the classification process.

So, How does the Neural Network do this?

How does the Neural Network learn to classify the different images? Our Neural Network takes a vector as input, therefore, the 28x28 image is converted into a one dimensional array of length 28x28 (784). The process of converting a 2-dimensional image into a vector is called flattening. And the code for flattening is as follows:

tf.keras.layers.Flatten (input_shape=(28,28,1))

The input will be connected to a dense layer of 128 units as follows

tf.keras.layers.Dense(128, activation=tf.nn.relu)

The code

activation=tf.nn.relu

represents the mathematical Rectified Linear Unit function. It is an extension to our dense layer to help the dense layer solve more complex problem. More on Rectified Linear Unit (ReLU) can be found here.

The last layer will be the output layer consisting of 10 units which are the 10 labels in our dataset and their probabilities β€” the confidence the model has that the input is a certain label. Adding up these probabilities should be equal to 1.
To create these probabilities we use the following code

tf.keras.layers.Dense(10, activation=tf.nn.softmax)
  • Softmax is a function that provides probabilities for each possible output class
Visual Rep. of how the Neural Network Works.

Training and Testing.

In the Fashion-MNIST dataset we have a total of 70,000 examples. We divide the dataset into training set (60,000 examples) and testing set (10,000 examples). So why do we really need to do this?

The whole reason behind this can be alluded to the scenario of a learner in school. Through the semester/term a learner works through a number of exercises in order to understand a concept. At the end of the semester an exam is set, which consist of totally different problems as compared to the exercises done throughout the semester. The exam is different just to make sure the concepts learnt during the semester are understood by the learner.

Same thing happens with a Neural Network in Deep Learning (our learner). It is fed as much examples (exercises) to train on (60,000). Then to make sure it has understood the differences in our input (learnt) and not merely memorized them, we give it unseen (10,000) examples (exam questions) to test on. This is how we test the Neural Network’s performance.

For Now…

This is as far as this part goes. Next part will include a step by step of the code that creates the above discussed Neural Network. Till next time, Happy Machine Learning!πŸ˜‰

PS: Comments and feedback appreciated.

--

--