YOLOV5 You can use YOLOV5 to run projects without knowing the code

[YOLOV5] : You can use YOLOV5 to run projects without knowing the code: 2021-09-12

Article directory

1. Introduction to the folder structure

File structure:

master folder structure:

yolov5-master is yolo [source code]

Each weight is placed in yolov5-master\weights

The .yaml files in yolov5-master\models are [yolo] structure files of different versions

In the runs folder is each training log,

In yolov5-master\runs\exp**\weights, the best time and the latest time are saved

[Dataset] file structure:

Dataset requirements:

The directory structure cannot be changed because the corresponding source code

The names of the images and the names of the labels should be in one-to-one correspondence

The labels file must be in txt format

(label type xywh) five values

data.yaml: configuration file

To write in the configuration file: where to read the data, the number of nc categories
 train: ../MaskDataSet/train/images 
val: ../MaskDataSet/valid/images

nc: 2
names: ['mask', 'no-mask']

2. Practical training and testing

  1. Get the standard dataset and put it in the same folder as the model

  2. Train.py in the yolo-master model file for training

train configuration parameters:

--data
C:/Users/zhaohaobing/PycharmProjects/python-yolov5-project/YOLO5/NEU-DET/data.yaml
--cfg
C:/Users/zhaohaobing/PycharmProjects/python-yolov5-project/YOLO5/yolov5-master/models/yolov5s.yaml
--batch-size

Configure project parameters:

Each result is saved in the yolov5-master\runs folder, and the .pt file in exp**\weights is the training model

  1. In the above configuration file, the number of epoch cycles can be changed, and 20 cycles are executed by default.
    Example:
    –epoch
    100
  2. detect does recognition, loads the .pt file, and gets the output in the outout folder

detect configuration parameters:

--source C:\Users\zhaohaobing\PycharmProjects\python-yolov5-project\YOLO5\NEU-DET\valid\images\crazing_1.jpg
--weights C:\Users\zhaohaobing\PycharmProjects\python-yolov5-project\YOLO5\yolov5-master\runs\exp50\weights\best.pt
--output C:\Users\zhaohaobing\PycharmProjects\python-yolov5-project\YOLO5\NEU-DET\output
--conf 0.4

–conf is the confidence threshold. If it is greater than this value, it will be detected, and if it is less than this value, it will not be used.

  1. To open the camera directly

3. Model transformation

The .pt model actually ran out of yolov5, and in order to realize inference on each development board, the model must be converted: .py->.onnx
(onnx is the intermediate model, model->onnx->model)
yolov5 folder There is a conversion function in
…/YOLO5\yolov5-master\models\export.py

But first install onnx
pip install onnx
error:
there may be:
Onnx export failure: No module named ‘onnx’

This is because the downloaded onnx file is in C:\ProgramData\Anaconda3\Lib\site-packages. Go to the file and copy the onnx folder to the same directory as the export.py program file.

Leave a Comment

Your email address will not be published. Required fields are marked *