Use yolov5 to train your own data set (suitable for Xiaobai's first training data set)

yolov5 is a classic algorithm of the yolo series, so I want to run the code of yolov5. This is the first code I run. I don’t understand anything. After downloading the code of yolov5, I am very at a loss. I don’t know where to start. . This article records it.

1.yolov5 download

Click on the YOLOv5 official address
insert image description here
and click on the code, download it as a zip file, or copy the https link, and download it through git (this method requires git, and it is not very convenient to install git on your computer, so the first method is recommended) After downloading, unzip and
insert image description here
import into pycharm.

2. pycharm environment configuration

You can refer to this pytorch installation (including the solution of anoconda and pytorch and torch.cuda.is_available() returning false)

3. Test whether the imported project is available

3.1 Install the necessary packages

First, you need to install the necessary packages, all required packages have been written in requirements.txt. Open the terminal, enter the annoconda environment of this project
insert image description here
and use the command to install all packages


pip install -r requirements.txt

insert image description here

4. Modify the code

There is such a large piece of code in train.py, which is related to configuration
insert image description here

5. Start training (the data set is the coco128 that comes with it)

5.1 Training with weight files

This is the most commonly used method. Through weight file training, you can run train.py training directly. However, due to the slow connection speed of github, an error may be reported, so you can also download the weight file manually.

5.2 Training without weight files

It is not recommended not to use the weight file sequence, and it takes a long time to train to converge.

6. Train with your own dataset

The code of yolo uses its own data set format, and the common data set format is the coco data set format. Therefore, if you use the coco data set, you need to convert the coco data set format to the yolo format. You can refer to this blog post.
Coco data set to yolo data set (simple and easy to understand)

6.1 Modify the code

First place: Put the personal data set in the same directory as the data set that comes with the code
insert image description here
Second place: Create a yml file
Create a yml file under the data folder to save
insert image description here
the fields that need to be written in the configuration information yml
( Special attention: yml is a configuration file. I am familiar with writing springboot. Here, each field must be written in the top grid. In addition, the data must satisfy the field colon space field), do not delete the space)
insert image description here

Modify the code in train.py, the red box in the figure needs to be changed to the file name just configured
insert image description here

Guess you like

Origin blog.csdn.net/qq_43471945/article/details/128163455