4 yolov5 model training

4.1 yolov5 introduction

In February 2020, Joseph Redmon, the father of YOLO, announced his withdrawal from the field of computer vision research, YOLOv4 was released on April 23, 2020, and YOLOv5 was released on June 10, 2020. The developers of YOLOv5 claim that YOLOv5 can achieve fast detection at 140 FPS on Tesla P100; while the detection speed of YOLOv4 is 50 FPS. Not only that, but the size of YOLOv5 is only 27 MB. And YOLOv4 is 244 MB. YOLOv5 is nearly 90% smaller than YOLOv4. In terms of accuracy, YOLOv5 is comparable to YOLOv4.

As a result, YOLOv5 is very fast, has a very lightweight model size, and is comparable in accuracy to the YOLOv4 benchmark.

The algorithm performance test chart of the author of Yolov5:

image-20220301141838248

Video test official case

4.2 folder structure

Note: There are verification pictures in the runs/exp file. After training an eTOCh, go and see to verify whether the pictures are correct. If they are not correct, adjust them quickly. Otherwise, you have to retrain after training all the adjustments.

label format

The value of x, y, w, h is the position where the image length and height are pressed [0:1]

4.3 Environmental requirements

The factory image is already configured, no need to install

Installation example

4.4 Use process

4.5 Custom training data set

4.5.1 Collecting datasets

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

Open the [Get_garbageData.py] file

Modify the total number of generated datasets and fill in as required. [More], too few datasets will lead to suboptimal training results.

Run the [Get_garbageData.py] file to get the dataset

4.5.2 make yaml file

For example garbage.yaml:

4.5.3 Modify train.py

Other places according to your needs.

4.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 are using yolov5s.yaml, so just modify the second line of the models/yolov5s.yaml file

4.5.5 Modify detect.py

Similar to the place where the [train.py] file needs to be modified

Other places according to your needs.

4.5.6 Train and predict

After training the model, the final model will be produced in the [runs/train] folder after training.

Image prediction, modify the model path and input image, predict the image, and the result is in the [runs/detect] folder.

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