Introducing 🤙🏻 Easy YOLOV7 ⚡️| The Best Object Detector in Just 10 Lines of Code
For those who are not familiar with YOLOv7, this object detection algorithm enables us to detect instances of objects of a certain class (such as humans, buildings, or cars) in images and videos.
At Theos AI, our mission is to make AI easy to use and accesible to everyone. That’s why in today’s article we take a look at our new repository, called Easy YOLOv7, which provides an easy way to use the YOLOv7 algorithm for object detection, in just 10 lines of code!
The Easy YOLOv7 repository is a simplified version of the YOLOv7 algorithm. The code has been cleaned up and simplified, so that it's easier to understand and modify.
Also, a simple API has been created so that anyone can use it in just 10 lines of code. The repository is available here. The instructions to use the repository are very straightforward. All you have to do is install the requirements listed in the requirements.txt file.
Object Detection in Images
To detect objects in an image, you just have to run the following command on your terminal.
This will run the image.py script, which in only 12 lines of code will load the model, read the image, detect all the objects present in the image, draw detections onto the image, save the image to disk, and display the detection and JSON results. Actually, without imports, the code is just 6 lines long (belive it or not!).
Object Detection in Videos
To detect objects in a video, you can use the video.py script.
To detect objects in a video, you just have to run the following command on your terminal.
The code to detect objects in a video is a little longer, but it's basically the same as detecting objects in an image.
You load the model, YOLOv7, and then load the video. The code then gets the width and height of the original video, the FPS, and the frame count, so that you can display a progress bar and see the progress of the detected frames.
Object Detection in Live Streams
The Easy YOLOv7 repository also provides the ability to detect objects in multiple live video streams in parallel. To do this, you have to create a stream.txt file inside the repository and put the URL for each stream in a separate line. For example:
Then run the command:
And start detecting objects in all the streams at once!
Optical Character Recognition (OCR)
Detect and OCR the Image
The Easy YOLOv7 can also be used to extract text from images (how amazing is that?). Just run the following command:
and you will be able to use it for various applications, such as reading license plates, converting scanned documents into editable text, and more.
Detect and OCR the Video
In this repository, you will also be able to do OCR on videos!
The script for doing this is the ocr_video.py
The file as it is, uses a license plate recognition model (ANPR / ALPR), so you will have to edit it for it to work with your own model by changing the weights file, classes yaml file and finally the ocr_classes list.
Training the Model with Your Own Dataset
The Easy YOLOv7 repository provides a tutorial on Gun Detection (click on the link to go to a previous blog about it!) that you can follow to train the model with your own dataset.
To download the weights, in training experiment you have to click on the Weights button, on the top right corner.
Download the best or last weights and the classes YAML file and put them inside the repository folder.
You can choose the latest weight or the best weight in the whole training. You also have to download the classes file so that the model knows how to call the classes and their colors. To use the weights, you just have to change the line where you load the model and put the path of the weight file and the path of the classes file. Then you set the device you want to use, either CPU or GPU.
The End
I hope you enjoyed reading this as much as we enjoyed making it!
If you found this cool or helpful please consider sharing it with a friend and smashing the star button for the Github algorithm, it will help us to know if you want us to make more of these!
Also, feel free to fork it and modify it to make it your own.
Consider joining our Discord Server where we can personally help you make your computer vision project successful!
If you have further comments or requests, don’t hesitate to reach out at contact@theos.ai
See you on the next one!