Yolo v7 trains its own data set

That’s right, I’m here for v7, I can’t escape v7, I thought I’d have to use v7 when I made x, sure enough, he’s here for v7 haha

1. Prepare the environment

Download the source code: I downloaded it here, because I downloaded it from the official one. There were a lot of mistakes, and I changed one after another, so I directly downloaded the ones modified by other big guys. It is very fragrant. Address: github:https://github. com/qiaofengsheng/pytorch-yolov7

Installation dependent environment: still the original set, and then I annotate torch and torchvision in requirement.txt, directly

pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

After installing the dependent environment, go to the official website to download the weight of yolov7, put it in the weights directory, and directly run the detect.py file to test whether the installation is successful.

2. Train your own dataset

2.1 Get training set and test set

Add image data to VOCdevkit/VOC2007/JPEGImages

Add the txt tag file corresponding to the image to VOCdevkit/VOC2007/Annotations

Then modify the classes list in voc_to_yolo.py, change it to the category name of your own data set, set the ratio of training and verification sets, I set it to 70, run it directly, and two folders, images and labels, will be automatically generated under VOCdevkit

2.2 Modify the voc.yaml file

Change train and val to the addresses of images/train and images/val just generated, nc to the category number of your own data, and names to the category name of your own data, as shown in the figure

 2.3 Training

Modify the --weights of the train.py file to the pt file downloaded from the official website and --data to the configured voc.yaml. There is a point here, that is, I downloaded the official yolov7.pt at the beginning, and use the training The best.py test was very inaccurate, there was no detection frame, and the threshold was adjusted later, and the results obtained were also very bad, so I downloaded this weight yolov7_training.pt later, and the result was much better. Just run the training directly and get the runs file Next the trained best weights.

3. Run the test.py test

Modify --weights, test with best.py

4. Run the detect.py file to predict

Put the picture to be predicted in the inference/images folder, modify --weights, --source

Ok, with the blessing of the boss, this thing is really fast. I make a wish and hope that the epidemic will pass soon.

Guess you like

Origin blog.csdn.net/Zosse/article/details/126614032