Number Plate Detection with Python

Machine Learning Project on Number Plate Detection with Python

In recent years, automatic number plate detection or license plate recognition has been one of the useful approaches for vehicle surveillance. In this article, I will introduce you to a machine learning project on Number Plate Detection with Python.

Machine Learning Project on Number Plate Detection

Traffic control and the identification of vehicle owners have become a major problem in all countries. Sometimes it becomes difficult to identify a vehicle owner who is breaking the rules of the road and driving too fast.

Also, Read – 100+ Machine Learning Projects Solved and Explained.

Therefore, it is not possible to catch and punish such kind of people because the traffic personnel might not be able to retrieve the vehicle number of the moving vehicle due to the speed of the vehicle. So to solve these types of problems we need to create a Number Plate Detection System. There are many Number Plate Recognition systems available today.

These systems are based on different methodologies, but it is always a very difficult task as some of the factors like high vehicle speed, non-uniform vehicle number plate, vehicle number language and different lighting conditions can affect a lot of overall recognition rate. Most systems operate under these limitations. In the section below, I will introduce you to a machine learning project on Number plate detection with Python.

Number Plate Detection with Python

Now, In this section, I will take you through how to create a Machine Learning model for the task of Number Plate Detection with Python. I will start this task by importing the necessary Python libraries and the dataset:

The dataset I am using here is in JSON format with multiline records. The two main elements are content and annotation. The content contains links to images and an annotation contains information about the respected image.

I wrote a simple script to download and save all images to a directory while saving their respected annotation information in a dictionary. At first, I thought all images were in JPEG format. However, a quick inspection of the uploaded images showed this assumption to be wrong. Some images are in GIF format. So before saving the images, I converted them to JPEG images with three channels (RGB) using the PIL library in Python:

Downloaded 237 car images.
df = pd.DataFrame(dataset)
df.to_csv("indian_license_plates.csv", index=False)
df = pd.read_csv("indian_license_plates.csv")
df["image_name"] = df["image_name"] + ".jpeg"
df.drop(["image_width", "image_height"], axis=1, inplace=True)
df.head()
image_nametop_xtop_ybottom_xbottom_y
0licensed_car0.jpeg0.7220840.5879830.8684860.688841
1licensed_car1.jpeg0.1619430.8507800.5829961.000000
2licensed_car2.jpeg0.0820000.6974520.2300000.828025
3licensed_car3.jpeg0.4340000.6673770.7180000.765458
4licensed_car4.jpeg0.2087910.3907640.8651350.984014

In the code below I have chosen five random records from the dataset for later visual inspection of the predictions. I deleted these records from the original dataframe to prevent the model from being trained on them:

Creating a Convolutional Neural Network

To train a machine learning model for Number Plate Detection, I’ll first create an ImageDataGenerator object from Keras to load batches of images into memory. This process is necessary because we do not have infinite memory in RAM and GPU RAM.

Then I will split the data in half with a batch size of 32 images. One for training (80% of data) and one for validation (20% of data) during training. Validation is important to see if the model overfits the training data:

Now I will create a convolutional neural network. It will have 8 convolutional layers with a maximum of 4 pool layers and a fully connected network with 2 hidden layers:

To find the minimum number of steps to cover all lots, the following equations are needed:

Train step size: 7
Validation step size: 1

Training Model for Number Plate Detection

Now, let’s train our model for the task of the Number plate detection system:

Now let’s have a look at the results given by our CNN for Number plate detection:

I hope you liked this article on how to train a Machine Learning model for Number Plate Detection with Python. Feel free to ask your valuable questions in the comments section below.

Default image
Aman Kharwal

I am a programmer from India, and I am here to guide you with Data Science, Machine Learning, Python, and C++ for free. I hope you will learn a lot in your journey towards Coding, Machine Learning and Artificial Intelligence with me.

2 Comments

  1. Hi Aman,
    Your code is simply clear and very useful for the beginner. I don’t see why these peoples are not recognized u r such hard work.

    I am enjoying a lot of learnings by reading your article.

    Thx

Leave a Reply

Data Science | Machine Learning | Python | C++ | Coding | Programming | JavaScript