MLearning.ai
Published in

MLearning.ai

Realtime Number Plate Detection using Yolov7 — Easiest Explanation

Hey guys, in this blog we will see how to perform Number Plate Detection using YOLOv7 by training the YOLOv7 on our custom number plate data.

Read the full blog here — https://machinelearningprojects.net/number-plate-detection-using-yolov7/

Checkout the video here — https://youtu.be/beV0nWFlYGc

YOLOv7 is the new state-of-the-art real-time object detection model.

You can use it for different industrial applications. Also, you can optimize the model, that is, converting the model to ONNX, TensorRT, etc, which will increase the throughput and run the edge devices.

In this blog, we will see the step-by-step guide to Train YOLOv7 on our custom dataset.

So without any further due, let’s do it…

Sneak at our Number Plate Detection using Yolov7

Step 1 — Collect Number Plate Dataset

  • After installing the package, open the terminal and run the ‘labelImg’ command.
  • It will open up a GUI.
  • Select the Image directory in it. The image Directory is where all Images are stored that you want to annotate.
  • Change Save dir in it. Save Director is where it will store the annotations.
  • Finally, make sure the format is set to YOLO and not to PascalVOC.

Step 2 — Let’s Train YOLOv7 on our custom Dataset

  • Till this step you should have 2 folders; images and labels.
  • The images folder should have all the Images and the labels folder should have all the Annotations in the txt format.
  • If you have not seen my previous blog on custom training a YOLOv7, do please check it out.

Easiest way to Train YOLOv7 on the custom dataset

  • When you will train YOLOv7 on the number plate dataset, you will get a PyTorch weight file in “.pt” format.
  • That is the most important file we need for the inference.

Step 3 — Inference on Images and Videos

Inference on Image File

  • Following is the code for Inference on an Image file.
  • In Line 15 we have loaded the PyTorch weight file.
  • In Line 20 we have given the Video File path.

Result

  • Our model is performing well on this Image.
  • Both the number plates of the car and truck are detected successfully.
  • Although it is detecting some noise also, to avoid this we can train it on even more data and on more epochs.

Inference on Video File

  • Following is the code for Inference on a video file.
  • In Line 15 we have loaded the PyTorch weight file.
  • In Line 20 we have given the Video File path.

Result

NOTE — If you want to run these inference files, save these files in the cloned yolo folder because these files use some util functions that are present in the yolo folder.

Clone the yolo repo using the command below:

So in this way you can Train YOLOv7 on the custom dataset in the easiest way possible.

In this blog, I have explained everything step-by-step on how you can Train a number plate detector using YOLOv7 and by simply following these steps you can do it.

For source code visit my blog — https://machinelearningprojects.net/number-plate-detection-using-yolov7/

Check out my other machine learning projects, deep learning projects, computer vision projects, NLP projects, and Flask projects at machinelearningprojects.net

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store