Traffic Sign Recognition with Keras and Deep Learning
In today’s world as the number of vehicles are increasing so are the road accidents and according to reports, India is on 1st spot in most number of accidents in a country. One of the reason is that people don’t recognize or follow traffic sign boards. So we have made a traffic sign recognizer which can inform the driver of the vehicle about the traffic sign coming ahead and to follow it. This can reduce the road accidents.
What is Traffic Signs Recognition?
Traffic signs are an essential part of our day to day lives. They contain critical information that ensures the safety of all the people around us. There are several different types of traffic signs like speed limits, no entry, traffic signals, turn left or right, children crossing, no passing of heavy vehicles, etc. Traffic signs classification is the process of identifying which class a traffic sign belongs to.
Purpose:
The basic purpose of this project is to classify traffic signs present in the image into different categories. With this model, we are able to read and understand traffic signs which are a very important task for all autonomous vehicles.
Importing necessary libraries:
We have used Python language for this. First we will import the neccessary libraries such as keras for building the main model, sklearn for splitting the training and test data, PIL for converting the images into array of numbers and other libraries such as pandas, numpy , matplotlib and tensorflow.
Flow of the project:
First we have take dataset which contains more than 50,000 images of different traffic signs. After that I will train deep learning model based on that dataset. There are total 4 steps to build this project.
- Explore dataset
- Build a CNN model
- Train and validate the model
- Run the model
- Explore dataset
Our ‘train’ folder contains 43 folders each representing a different class. The range of the folder is from 0 to 42. With the help of the OS module, we iterate over all the classes and append images and their respective labels in the data and labels list.
2. Build a CNN model
Convolutional neural networks are a part of deep learning and extensively used in image recognition. These convolutional neural networks consists of several layers. Every layer is made up of a set of neurons, where each layer is fully connected to all neurons in the layer before. Finally, there is a last fully-connected layer — the output layer — that represent the predictions.
3. Train and validate the model
After building the model architecture, we then train the model using model.fit(). we have tried with batch size 32 and 64. Our model performed better with 64 batch size. And after 15 epochs the accuracy was stable. Our model got a 95% accuracy on the training dataset. With matplotlib, we plot the graph for accuracy and the loss.
4. Run the model
Our dataset contains a test folder and in a test.csv file, we have the details related to the image path and their respective class labels. We extract the image path and labels using pandas. Then to predict the model, we have to resize our images to 30×30 pixels and make a numpy array containing all image data. From the sklearn.metrics, we imported the accuracy_score and observed how our model predicted the actual labels. We achieved a 95% accuracy in this model.
Traffic Signs Classifier GUI
Now, I have build a graphical user interface for traffic signs classifier with Tkinter. Tkinter is a GUI toolkit in the standard python library. In this file, we have first loaded the trained model ‘traffic_classifier.h5’ using Keras. And then we build the GUI for uploading the image and a button is used to classify which calls the classify() function. The classify() function is converting the image into the dimension of shape (1, 30, 30, 3). This is because to predict the traffic sign we have to provide the same dimension we have used when building the model.
Conclusion:
So we got to know that how deep learning can be used to classify traffic signs with high accuracy. Our model reached close to close to 98% accuracy on the test set, achieving 99% on the validation set.