Machine and Deep learning using PyTorch : Accurately predicts the type of clothes in our images


Accurately predicts the type of clothes in our images using Machine Learning, Deep Learning, and Artificial Intelligence

We continue [1] to learn topics such as Machine Learning, Deep learning, neural networks using an end-to-end machine learning framework: PyTorch [2]

We followed the free course named ‘Secure and Private AI’ given by Udacity [3] and reached the “Fashion-MNIST [4]”-related course.

Basically, the Artificial Intelligence will predicts the type of clothes displayed on a picture.

The dataset used by the Machine learning framework

The Fashion-MNIST [5], is a dataset of Zalando’s article images consisting of a training set of 60,000 examples and a test set of 10,000 examples.

Each example is a 28×28 grayscale image, associated with a label from 10 classes:

  • T-shirt/top, Trouser, Pullover, Dress, Coat, Sandal, Shirt, Sneaker, Bag or Ankle boot
Pictures : Fashion MNIST sprites

Fashion-MNIST is a dataset of Zalando’s article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples

 

Come back to reality, mathematics-statistics-training…

It is time to remember the steps to make your list of pictures coupled with their manual recognition:

  • Train the network
    • Define the criterion (Cross Entropy Loss[8] or Negative Log Likelihood Loss [9])
    • Decide the optimizer (Stochastic gradient descent [6] or the Adam algorithm [7])
  • Write the training code
    •  Make a forward pass through the network to get the logits (logits converts real space from [0,1] interval to infinity [-inf, inf])
    •  Use the logits to calculate the loss
    • Perform a backward pass through the network with a loss-backward-function to calculate the gradients
    • Take a step with the optimizer to update the weights
    • Finally, when these steps are executed for a number of epochs[10] with a large number of training examples, the loss is reduced to a minimum value [11]
    • The final weight and bias values are obtained which can then be used to make predictions on the unseen data. [11]

Roll your sleeves up and code!

After a few lines of code, the download of samples you find out that a model without training is useless.

The clothes indicates that they are as many chances that the figure on the left (Angle Boot) is a Bag or a Sneaker or a Shirt.

 

Artificial Intelligence predicts without training-this is NOT accurately recognized

Artificial Intelligence predicts without training-this is NOT accurately recognized

Dozens of minutes later, a few lines of code and training of the model using already-trained data and the prediction on unseen data indicates with a very high level of confidence the class of the clothes.

 

Artificial Intelligence predicts a bag or shirt - this is not accurately recognized

Artificial Intelligence predicts a bag or shirt – this is NOT accurately recognized

 

Artificial Intelligence predicts a sneaker or ankle boot-this is NOT accurately recognized

Artificial Intelligence predicts a sneaker or ankle boot-this is NOT accurately recognized

 

Artificial Intelligence predicts a bag - this is accurately recognized

Artificial Intelligence predicts a bag – this is accurately recognized

 

Artificial Intelligence predicts a pullover - this is accurately recognized

Artificial Intelligence predicts a pullover – this is accurately recognized

 

Artificial Intelligence predicts a shirt - this is accurately recognized

Artificial Intelligence predicts a shirt – this is accurately recognized

 

Wanna look at the execution of the predictions?

 

We store some Jupyter Notebooks (a notebook containing text and source code that can be executed) on Microsoft Azure :

 

Links

[1] Machine and Deep learning using PyTorch : Accurately predicts the digits in our images

[2] PyTorch : https://pytorch.org

[3] Udacity: Secure and Private AI: https://classroom.udacity.com/courses/ud185

[4] MNIST : https://alt-f1-software-architecture.readthedocs.io/en/latest/glossary.html?highlight=mnist

[5] Fashion-MNIST of Zalando : https://github.com/zalandoresearch/fashion-mnist

[6] https://pytorch.org/docs/stable/optim.html?highlight=sgd#torch.optim.SGD

[7] https://pytorch.org/docs/stable/optim.html#torch.optim.Adam

[8] https://pytorch.org/docs/stable/nn.html?highlight=cross%20entropy%20los#torch.nn.CrossEntropyLoss

[9] https://pytorch.org/docs/stable/nn.html?highlight=nllloss#torch.nn.NLLLoss

[10] Epoch: https://alt-f1-software-architecture.readthedocs.io/en/latest/glossary.html?highlight=epoch#term-epoch

[11] Get Started with PyTorch – Learn How to Build Quick & Accurate Neural Networks (with 4 Case Studies!) : https://www.analyticsvidhya.com/blog/2019/01/guide-pytorch-neural-networks-case-studies

HR curriculum: Secure and Private Artificial Intelligence: https://alt-f1-software-architecture.readthedocs.io/en/latest/02-03.HR_management.html#secure-and-private-artificial-intelligence

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: