Model training

yolov5 official tutorial: https://github.com/ultralytics/yolov5/blob/master/tutorial.ipynb

yolov5 official source code: https://github.com/ultralytics/yolov5

yolov5 weights file: https://github.com/ultralytics/yolov5/releases

This tutorial is only applicable to Jetson Orin NX and Jetson Orin Nano boards.

The Jetson Nano board cannot be used for model training due to its limited performance.

1. yolov5 introduction

Yolov5 algorithm performance test chart

image-20220301141838248

Video test official case

2. Folder structure

Note: There are verification images in the runs/exp file.

Check them after training an epoch to verify whether the images are correct. If they are not correct, adjust them immediately. Otherwise, you will have to retrain after all adjustments are made after training.

Label format

The values of x, y, w, and h are the positions where the length and height of the image are [0:1]

3. Environmental requirements

The following contents are already configured in the Yahboom image file and do not need to be installed.

Input following command to install

4. Use step

5. Custom training dataset

5.1 Collecting the dataset

First, go to Baidu to download or use other methods, and fill in more background images in the path [data/garbage/texture]

Open the [Get_garbageData.py] file

Modify the total number of generated data sets and fill it in according to your needs.

More data sets are needed, and too few will lead to incorrect training results.

Run the [Get_garbageData.py] file to obtain the data set

5.2 Make yaml fiel

Eg garbage.yaml:

5.3 Modify train.py

Parameters in other places can be modified according to your needs.

5.4 Modify the model configuration file

Modify the second line of the yaml file of the yolov5 neural network, and use which weight file to modify the corresponding yaml file.

Here we use yolov5s.yaml, so just modify the second line of the models/yolov5s.yaml file

5.5 Modify detect.py

It is similar to the place where the [train.py] file needs to be modified

Parameters in other places can be modified according to your needs.

5.6 Training and prediction

Note: Before training the model, please close the docker container and other programs that occupy a large amount of memory to avoid memory.

Train the model. After the training is completed, the final model will be generated in the [runs/train] folder.

image-20240712111320634

For image prediction, you need to manually modify the model path and input image, predict the image, and the result is in the [runs/detect] folder.

image-20240712112053633

For real-time video monitoring, the model path needs to be modified.