Building a Basic Convolutional Neural Network.

Angad
3 min readApr 28, 2020

--

In 2019, 38,000 people died because of car accidents. Out of these 38,000, 50 people died in Tesla Cars. Now, you may begin to think that I’m vouching for Tesla, but that’s not it. Tesla is not only a car company, but uses groundbreaking software as well. Tesla has achieved autopilot, automatic parking, breaking, and other functions that Tesla driving families(mine included) don’t even realize. Tesla, through utilizing Convolutional Nueral Networks, has managed to account for only 50 deaths out of 38000, meaning that they accound for 0.131% of all deaths on the road in 2019. Now, it may seem that I’m just promoting Tesla, and you’d be right. Tesla, has taken steps to improve the auto industry for the better. They do this through Artificial Intelligence, more specifically, Convolutional Neural Networks.

So, what exactly are Convolutional Neural Networks(CNN’s), and why are they so successful. In essence, CNN’s are the entire optic system of a computer, providing the visuals to everything that’s going on around it. It can identify, classify, and recognize objects surrounding the main object which is what the CNN is working for. In Tesla’s, a system of 8 camera’s feed information directly to the CNN, displaying visual information about the surrouding area, such as different cars, bikes, people, even the streetlights and crosswalks can be identified. So, let’s dive down deep into the world of CNN’s, and to do that, we’re going to dissect the name itself. Convolutional, meaning sight and Neural Network, a machine learning system that replicates itself after the human brain. So in order to understand how the Neural Network works, we must dive into the deep world of machine learning, and see how this specific instrument works

The CNN, just like any other Neural Network, contains the Input and Output layer, along with multiple hidden layers. The Input would be the image that it’s classifying, while the Output is the computer classifying the image. These are the easier parts. The deeper part of understanding in a Neural Network is learning about the hidden layers.

Now, we move into programming our Neural Network. How exactly do we do this. First, we want to import a ML database, so we download tensorflow and import that. Within Tensorflow, there is a database called the fasion MNIST. the fasion MNIST database. The fasion MNIST database is essentially a large database of different kinds of clothing articles, all of which are able to be recognized by a computer model. This computer model has a few different components to it.

The first component is where we set the restrictions to our model, this means that we have some code, which may look like this

fasion_mnist = keras.datasets.fashion_mnist

(train_images, train_labels), (test_images, test_labels) = fasion_mnist.load_data()

class_names = [‘T-shirt/top’, ‘Trouser’, ‘Pullover’, ‘Dress’, ‘Coat’, ‘Sandal’, ‘Shirt’, ‘Sneaker’, ‘Bag’, ‘Ankle Boot’]

the first line will say what we want, which is the fasion_mnist database,

The next 4 lines will say what we’re looking for, and begin working on what our model will look like.

After this, we set up some more code which looks like this.

model = keras.Sequential([

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

keras.layers.Dense(128, activation=’relu’),

keras.layers.Dense(10)

])

this code will make sure that we are activating this model, and set some restrictions.

and finally, we work on our optimizer, and state the epochs, which say how many times we want to run this code for training.

model.compile(optimizer = ‘adam’, loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits = True), metrics = ([‘accuracy’]))

model.fit(train_images, train_labels, epochs = 30)

Now we are ready to run. You will likely see a window open up, depending on which editor you are using to run this Python code. It will begin to train, and after some time, it will state your accuracy, which just shows how accurate this program is at differentiating clothing.

And this is how you build a simple Neural Network.

--

--

Angad
Angad

Written by Angad

Hi! I'm Angad, a Grade 9 student from the University of Toronto Schools who loves learning anything and everything!

No responses yet