yolov5 training model


1. Data processing

Label with labelImg

Mark the software download address: 链接:https://pan.baidu.com/s/1xYu2fCGgIp-lVO3fUHpdaQ 提取码:6666
1. Open the predefined_classes.txt file in the data directory and change it to the class you need

2. Open Dir import the image folder that needs to be marked

3. The folder where the generated file is located after the Change Save Dir marking is completed

4. Switch the mode to yolo mode as shown in the figure below (the eighth icon on the left side of the stand-alone)

PascalVOC mode generates .xml files and yolo mode generates .txt files

5. Click the'w' key on the keyboard to frame selection
Insert picture description here

2. Training model

1. Create a new folder at the same level as the yolov5 folder
Insert picture description here

2. Create two new folders
Insert picture description here
train folder under the yb folder to store the training data set. The
valid folder is used to store the test data set.
Change the program in data.yaml

train: ..\yb\train\images
val: ..\yb\valid\images

nc: 2
names: ['fishJ', 'fishL']

train and val are the data storage directory
nc: the number of categories you train
names: the name of the training category

3. Create two new folders under the train folder and the valid folder. The
Insert picture description here
images folder is used to store the pictures and the
labels folder is used to store the labels
(labels.cache is generated by running train.py)

4. Change the yolov5l.yaml file in the /yolov5/models folder (I trained the l model)

# parameters
nc: 2  # number of classes
。。。。。。。。。。。。。。。。。(省略一下后面的程序)

Only change the nc line and change 80 to the number of categories you train

**5.** Run the train.py file
python train.py --img 640 --batch 1 --epochs 300 --data ../yb/data.yaml --cfg models/yolov5l.yaml --weights ''

My computer batch can only be adjusted to 1 or an error will be reported.

Three. bugs and solutions

1. Insufficient memory space

OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading "E:\anaconda\anaconda\envs\yolov5_GPU\lib\site-packages\torch\lib\caffe2_detectron_ops_gpu.dll" or one of its dependencies.

Solution Change the batch parameter to 1
and so on, if you have money, buy a better graphics card. . . . .

study-time

2021.3.14


Guess you like

Origin blog.csdn.net/qq_44181970/article/details/114780486