AI, But Simple

Neural Networks in Pytorch

In past issues, we’ve gone over the theory of neural networks, we’ve talked about the concepts of them, but we haven’t discussed how to implement them in real life.

So today, we’re going to make a ANN without any convolutional layers (used in CNNs) to classify some images.

Convolutional layers are shown above

  • Now, if you know anything about CNNs, you’ll know that they work great for image processing related tasks.

  • To demonstrate the power of simple neural networks, we’ll take on the challenge of making an ANN image classifier with acceptable accuracy.

We’re going to implement the ANN in Python using Pytorch, along with some helper libraries like Numpy and Matplotlib.

Disclaimer: This issue will require some knowledge of Python. If you have no knowledge but still want to follow along, please consult a beginner Python tutorial before continuing.

But why choose PyTorch for ANNs?

Pytorch’s intuitive syntax and flexibility make it a favorite among researchers and developers. It’s backed by a large community and lots of support, which is one of the reasons it’s so popular.

We’re going to be training our model on the infamous Fashion-MNIST dataset, as it’s much more robust than the MNIST dataset.

  • The Fashion-MNIST Dataset consists of 60,000 training images and 10,000 testing images

  • Each image in the dataset is a 28x28 pixel image

  • Every image in the dataset belongs to one of ten classes of items:

Label

Description

0

T-shirt/top

1

Pants

2

Pullover

3

Dress

4

Coat

5

Sandal

6

Shirt

7

Sneaker

8

Bag

9

Ankle boot

The idea is to construct a neural network using a decent architecture and enough layers to learn patterns, hoping it will be able to classify images effectively.

By pairing fully connected layers with the ReLU activation function and gradually decreasing the number of neurons, we hope to achieve good performance on this image classification dataset.

  • Keep in mind that the model we will be creating won’t be state-of-the-art or too complicated, so its performance won’t be the absolute best.

We want to go for an architecture like shown above

Let’s start with the imports and download the dataset.

Subscribe free to read the rest.

A new issue every Monday.

More in Foundation

Foundation 18
  1. #125 Foundation PRO edition

    Nanbeige4.3-33B, Simply Explained

  2. #124 Foundation PRO edition

    Decision Models, World Action Models, Egocentric Video

  3. #80 Foundation PRO edition

    Boosting Models in Machine Learning, Simply Explained