foreword
Recorded the whole process of training coco128
Teach you how to build the YOLOV5 environment and train the COCO128 dataset. The relevant configuration files are in Baidu Netdisk.
If you are lazy, you can directly use all my data
1. Preparation
1.1 Create environment
Open the anaconda power shell (it is best to run as an administrator, so as not to get the relevant file permissions later)
conda create -n yolov5coco python=3.8
1.2 Activate the environment
conda activate yolov5coco
1.3 Download basic requirements such as pytorch
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
2. Configuration environment
2.1 Download source code
2.1.1 Direct git to local (many people may not have configured Git )
git clone https://github.com/ultralytics/yolov5
2.1.2 Download the zip and extract it to the current environment
2.2 Install various dependencies
cd to the yolov5 folder
pip install -U -r requirements.txt
3. Related file download
3.1 Download weight
I mainly use relatively small model weights v5s and v5x. Baidu network disk link (which contains coco128):
https://pan.baidu.com/s/11c49TfGtqAzHAEX3WdEBwA?pwd=3rzb
Extraction code: 3rzb
Place the downloaded yolov5s.pt in the current folder as shown in the figure
3.2 Simple test
Create iference/images in the current directory, and randomly place a few photos to test bus and zidame.
python detect.py --source inference/images/ --weights ./yolov5s.pt
3.3 coco128 dataset download
The coco128 data set has been placed in the above Baidu network disk file. The download link is attached: https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip . After downloading and decompressing, we place the folder in the same directory as /yolov5, as shown in Section 3.1.
4. Training coco128 dataset
4.1 Training
直接在终端中输入:
python train.py --img 640 --batch 16 --epochs 5 --data ./data/coco128.yaml --cfg ./models/yolov5s.yaml --weights ./yolov5s.pt
Among them: img is the size of the image, and the batch can be set according to the size of your computer memory
The training results will be displayed under the runs/train file:
4.2 Small test
Pay attention to the storage path of your own weight
python detect.py --source ./inference/images/ --weights ./runs/train/exp3/weights/best.pt