How To: Create Custom YOLO Object Detection Model (Vehicle Badges)

Channel:
Subscribers:
1,000
Published on ● Video Link: https://www.youtube.com/watch?v=bAMcDB5QEv8



Duration: 26:47
146 views
4


In this video I show you how to create a custom object detection model using YOLOv8 that will be trained to detected Mercedes Benz and Volkswagen vehicle badges. At the end of the video I'll do some testing to see how accurate the model is at detecting and predicting these badges.

There are around 30 steps to go through, so for convenience I have made a note of these below. Also, here are some useful links:

Download Miniconda: https://docs.anaconda.com/free/minico...
YOLO Ultralytics Github: https://github.com/ultralytics/ultral...

Step by Step Guide:

Setup Development Environment
----------------------------------------------------------
1. Download and install Miniconda
2. Open Miniconda from Start Menu
3. Create a conda environment: conda create --prefix [path and name of environment] python=3.12.2
4. Activate the environment: conda activate [name of environment]
5. Change directory to where the source images are
6. Install pip: conda install pip

Label images
----------------------------------------------------------
7. Install labelImg: pip install labelImg
8. Open labelImg: labelImg
9. Click OpenDir and point to "images" folder that contains your images
10. Click on SaveDir and point to the "labels" folder that will be used for saving the annotated images
11. Make sure YOLO is selected
12. Draw a rectangle around the object, give it a class name, then click save (if Label Img crashes at this point, see notes below)

Training, validation folders, etc
--------------------------------------------------------------------
13. Once the images have been annotated, create a "train" folder and a "val" folder
14. In "val" create two subfolders: "images" and "labels"
15. Move (cut and paste) approx 20% of the dataset from the "images" folder into "val" , "images"
16. Move the corresponding label text files into "val" , "labels"
17. Move classes.txt to the root folder
18. Move the main "images" folder and "labels" folder into the "train" folder

Create YAML file
------------------------------------------------------------------------
19. Create a YAML file in the root
20. Open the YAML file and enter the details as below

Setup training environment
-----------------------------------------------------------------------------
21. Install YOLO: pip install ultralytics
22. Download and Install PyTorch GPU: https://pytorch.org/get-started/locally/
23. Full command: pip3 install --upgrade torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
24. Verify install with commands below

Train the model
-----------------------------------------------------------------------------
25. Enter the command to train the model: yolo task=detect mode=train epochs=100 data=my_new_model.yaml model=yolov8m.pt imgsz=640 workers=2 (you may also need to update the ultralytics settings.yaml to point to the root directory, see path below)
26. Model will start to build
27. On completion, open the "Runs" , "Detect" , "Train" folder and view the results
28. Go into the "Weights" folder and copy the "Best.pt" file (this is the newly trained model)
29. Paste it into the root

Test the model
-----------------------------------------------------------------------------------
30. To test the model enter the following command: yolo task=detect mode=predict model=best.pt show=True conf=0.5 source=1.jpg (replace 1.jog with your own image or video)
31. Open "Runs" , "Detect", "Predict" to view the result

-----------------------------------------------------------------------------------------

Additional Information:

--------------------------------------------
YAML file:
--------------------------------------------
train: ./train
val: ./val
nc: 2
names: ["class1", "class2"]

----------------------------------------------
Torch confirmation commands:
----------------------------------------------
python
import torch
torch.__version__
torch.cuda.is_available()

------------------------------------------------
Ultralytics YAML settings file location:
------------------------------------------------
C:\XXX\AppData\Roaming\Ultralytics\settings.yaml

---------------------------------------------------
If Label Img Crashes:
-----------------------------------------------------
Find and open for editing the following file:
...\Lib\site-packages\libs\canvas.py

On these lines, copy and paste over the existing line:

526:
p.drawRect(int(left_top.x()), int(left_top.y()), int(rect_width), int(rect_height))

530:
p.drawLine( int(self.prev_point.x()), 0, int(self.prev_point.x()), int(self.pixmap.height()))

531:
p.drawLine( 0, int(self.prev_point.y()), int(self.pixmap.width()), int(self.prev_point.y()))

Find and open for editing the following file:
...\Lib\site-packages\labelImg\labelImg.py

On this line, copy and paste over the existing line:

965:
bar.setValue(int(bar.value() + bar.singleStep() * units))


Then save both files







Tags:
YOLOv8
object detection
YOLOv8 tutorial
custom YOLOv8 model
YOLO object detection
vehicle badge recognition
deep learning
machine learning
AI model training
computer vision
real-time object detection
YOLOv8 model accuracy
Ultralytics YOLOv8
PyTorch object detection
training YOLOv8
artificial intelligence
vehicle detection
automated badge recognition
YOLOv8 custom dataset
neural network training
advanced object detection
YOLOv8 vehicle badge