YOLOv5 Series 2. Use yolov5 to identify your own data

YOLOv5 Series 1. Make your own data set
YOLOv5 Series 2. Use yolov5 to identify your own data



Preface

I previously recorded how to create my own data set in my previous blog . This article mainly uses yolov5 to run through and train my own data set. The environment is window10, pytorch1.7, cuda10.1.


1. Download yolov5 source code

First, you need to download the source code file of yolov5 from GitHub . After downloading, you can directly extract it to the place where you want to install it. There is also no weight file of yolov5 in this source code, and the weight file needs to be downloaded separately .
Insert image description here
After opening the download webpage, select the weight you need

2. Test download model

After decompressing the source code and downloading the weight file, place the downloaded weight file in the decompressed folder:
Insert image description here
Use pycharm to open the yolov5 folder, click on the detect.py file, and configure parameters before running. In fact, this is Add weight file:
Insert image description here

--weights yolov5s.pt #看自己下的是什么权重文件,写上相应的文件名即可

Then run it directly, and it will appear:
Insert image description here
At this time, it means that the prediction has ended, and the detection results are saved under runs\detect\exp :
Insert image description here
Insert image description here
This means that there are no problems with the downloaded source code and weight files, and you can then train your own data set. .

3. Train and test your own data set

First, I placed the source code and my own data set in the same directory:

--MaskDataSet
--yolov5源码文件

Then open the train.py file configuration parameters:
Insert image description here

--data ../MaskDataSet/data.yaml --weights yolov5s.pt --batch-size 8
#	--data 		:表示数据集放的位置,不需要改变
#	--weights 	:表示需要加载的权重文件
#	--batch-size:表示一个批次加载几张图片,如果显存小的话,可以适当调低一些

Run train.py, and the relevant indicators generated during training will be stored in the runs\train folder, including: mAp, confusion matrix, PR map, preprocessed input image, etc. The most important thing is that your trained weight files are also here. There will be two files under your runs\train\exp\weights folder, as shown in the figure below. As the name suggests, one is the best result during the training process. The weights, one is the last weight, are simply thoughtful for you.
Insert image description here
Finally, you can use detect.py . This file tests the effect of training. In this step, remember to replace yolov5s.pt in detect.py with your own best.pt. The things made by the blogger belong to the project, and it is not convenient to make them public for the time being, so I won’t include the final test result picture. Generally speaking, it is similar to the pedestrian result picture above.


Summarize

  1. Many parameters, such as: number of iterations, learning rate, confidence, batch_size, whether to use cpu or gpu training, etc., can be found in train.py and modified to suit your own data set characteristics.
  2. If you want to deploy it elsewhere later, export.py in yolov5 can help convert the .pt files generated by training into .onnx files and .torchscript files to facilitate later deployment.
  3. Yolov5 may not have too many academic improvements, but it is indeed suitable for engineering and is not too convenient.

Guess you like

Origin blog.csdn.net/fjlaym/article/details/124036920