A PROJECT ON TRAFFIC SIGN CLASSIFICATION USING CONVOLUTIONAL NEURAL NETWORK
Tags: datascience, machinelearning, ai
Published: 2024-03-14 17:45:43

In this project, we used a convolutional neural network to build train, and test a traffic sign classification model. We built this model using tensorflow and keras. It is a multiclass classification problem. This model can be used to make smarter cars.
After this project, one can be able to build multiclass classification model using deep learning.

STEPS TAKEN TO SOLVE THE PROBLEMS
1) Finding data on kaggle and loading it into google colab.
2) Preprocessing the image and visualizing them.
3) Finding out the mean of the dimension and resizing all images accordingly.
4) Converting the images into a numpy array and normalize them.
5) Checking class imbalance.
6) Splitting the data and performing one hot encoding.
7) Creating the model architecture, compiling the model and then fitting it.
8) Plotting the accuracy and loss against each Epoch.
9) Preprocessing the test data and make predictions on it.
10) Visualize the original and predicted labels for the test images.

First, we start by connecting to kaggle using kaggle API which can be downloaded from your kaggle account settings and uploading it on your notebook.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m72kbfna31qwt1quubqo.png)

Next we would store the data by making a directory and making it as a current directory.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/886jvlhbk6zmmqmd9h2y.png)

We download the data into colab notebook using using references found in search options.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3s51dj8prwyjk3of6ce.png)

Also unzip the data which is downloaded and remove irrelevant files.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qyub4rrunla6tqdbav3k.png)

We plot 12 images to check dataset.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pokgb2t9lfnvmbs1zlec.png)

For further processing we will require the images of same dimension. So, we will start storing the dimension of all images from training dataset from all 43 classes.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fak1mvk1hzkii4tf97no.png)

Now, we will reshape the images into (50,50) and also store their label ids.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/haa6nwt3p6fwuhzld3v7.png)

We also check the shape of the images. Here we can see below that there are 39209 images with a shape of (50,50,3).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vubojwryc1c6nb2cw2e8.png)

The next step was splitting the data into training and validation with 80% of training data and 20% of validation data. Also converting the classes column into categorical using to_categorical() function.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yxa2jij8b386xt8ligqa.png)

Next we compile the model using metrics, optimizer and loss as required and printing out the summary of the model.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7vh18298l96evp3og51f.png)

Now we fit the model and observe how they are getting trained on each epoch.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7dszko6lz0zowtnakzn.png)

Next we visualize the accuracy and loss per epoch. For this we will store the model history in the pandas dataframe and plot them.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vg6ro85zf5mw9w5rw6yz.png)

We create a function to resize the test images converting them into a numpy array and normalize them.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m2etg2da39wfogjutmpu.png)

Now we will use the model to make predictions on our test images and save them in y_pred.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7d6cc77lutojmw0seab7.png)

Next we store the labels according to the image classes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z8myjtbugl8us8b02amu.png)

Finding out the predicted label for the images above.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/457vdmijhp479rfklbld.png)