Stop! No Entry, Or Checkpoint, let me Torch it and have a (Torch) vision!! ;)

Original article was published on Artificial Intelligence on Medium


Stop! No Entry, Or Checkpoint, let me Torch it and have a (Torch) vision!! 😉

Yes! you got me right here I am denoting PyTorch framework to classify Traffic signs such as No Parking, Give away, School Ahead, Uneven road, Stop, hump, Speed Limit, and many more. Here we talk about Recognition of Traffic lights by PyTorch machine learning Library and its advantages. Let’s Begin:

Have you at any point thought about how Facebook deals with the abusive and improper pictures shared by few users? Or then again how Facebook’s labeling highlights on Pictures? Or then again how Google Lens perceives items through pictures?

The entirety of the above are instances of image classification. Image classification is a typical undertaking in Computer Vision (CV), where we classify a picture by learning from the picture itself.

Likewise, Automatic recognition of the traffic signs (TS) by intelligent vehicles can support safety and multiply the comfort of driving. We can use these systems for highway maintenance activities as well.

Architecture of the Traffic-Sign Recognition System consists of the four modules: Image Acquisition, Classifier & Image Augmentation, Model Building with Transfer learning & Evaluation.

Image Acquisition: It’s a data collection part, Initially we explored the German Traffic Sign Recognition Benchmark (GTSRB) dataset, Loaded the images with resizing it, and then show images/ Show grid images from all the folders with the help of OpenCV & Torchvision libraries.

Classifier & Image Augmentation: Then we defined 4 classifiers names: Stop, Give way, Priority road and No entry with class_indices. Also reserved 80% dataset for training 10% for validation, and 10% test for each class. Then, we applied some random resizing, rotation, and horizontal flips. Finally, we normalize the tensors using preset values for each channel. After applying transformations, we also need to reverse the normalization and reorder the color channels to get correct image data.

Model Building with Transfer learning: We will use Transfer learning to copy the architecture of the very popular ResNet model. We reuse almost everything from transfer learning except the change of the output layer because the number of classes in our dataset is different i.e. 4: Stop, Give way, Priority road and No entry. Then we encapsulate the training dataset with functions including data loader, optimizer, loss function. We start by turning our model into train mode and go over the data. After getting the predictions, we get the class with maximum probability along with the loss, so we can calculate the epoch loss and accuracy. Here we have used no. of epochs=3, Learning rate= 0.001 and Optimizer: SGD. We do a lot of string formatting and recording of the training history. The hard stuff gets delegated to the previous helper functions. We also want the best model, so the weights of the most accurate model(s) get stored during the training. Then we used some plots for Visualization.

Evaluation: Then we see some predictions on traffic signs from the test set, which gave a very good result. Then we use a classification report to calculate precision, recall and F1score. The Magic comes, the score is 1. This shows our model is perfect, not something you see every day! Right? We also validate our model with unseen images where output was pretty good.

Advantages: Here I also want to talk about Why I used PyTorch framework specially and not other popular framework because PyTorch is a best in class AI system, supported particularly in research because of its usability and dynamic chart structure. This makes PyTorch simpler to investigate than other popular framework, which is enormous when you’re a specialist making complex model designs. PyTorch is likewise simpler to learn for apprentices in AI, for the previously mentioned reasons.