YOLOv5 uses the command line to train its own txt data set under linux

1. Download the YOLOv5 model and weight file

git clone https://github.com/ultralytics/yolov5

And put the weight file in the weights folder under YOLOv5

2. Install the required libraries

pip install -r requirements.txt

3. Check whether it can run

python3 detect.py

4. Put pictures and labels

Compress the pictures and txt tags under Windows into zip, and transfer them to the server through rz.

pass under the server

unzip 文件名 -d 解压路径

Unzip the transferred image tag to the server. And create three folders (mkdir) images, labels, and ImageSets under the data of YOLOv5

Then pass the command

mv 移动的图片/标签 移动到的路径

Put the decompressed pictures and labels under images and labels under data

Then cd to the YOLOv5 directory, and transfer makeTxt_for_txt.py and voc_label_for_txt.py to the server through rz

#先运行makeTxt_for_txt.py

python3 makeTxt_for_txt.py

#再运行voc_label_for_txt.py

python3 voc_label_for_txt.py

Created four new txt files under ImagesSets;

Created three new txt files under data: data/train.txt, data/train.txt, and data/val.txt;

5. Pass the modified configuration file to the server through rz and move it to data

 6. Change the nc in yolov5s.pt under models to the number of your own species

7. Start training

python3 train.py  --img-size 640 --batch-size 16 --epochs 80 --data data/food.yaml --cfg models/yolov5s.yaml --weights weights/yolov5s.pt 

 You can start training by specifying various parameters to train.py through --variable parameters

Get best.py and last.py after training

8. Speculation

After training, put the obtained best.py into the first line of detect.py, and then specify the picture or video in the second line 

via the command line

python3 detect.py --weights weights/best.pt --source 图片或视频路径

Make a guess and get the result, then cd to the path where the result is located, and transfer the picture to Windows through the sz picture name to view the guessing effect.

Guess you like

Origin blog.csdn.net/weixin_52950958/article/details/125677686