yolo-pose environment construction and training and testing


foreword

 Throw away academic prejudice and embrace engineering Yolo. Since yolo has never been used, this article aims to configure the yolo environment from 0 and train and test.
Thesis address
code address

1. Preparation

  1. First download the coco2017 dataset, how to download this I will not introduce in detail,But note that although the folder name of the original coco dataset is also coco, in order to distinguish it from the one used by yolo, please name the coco dataset coco2017.
  2. Then download the tag in the original coco format and decompress it. After decompression, please be sure to copy the person_keypoints_val2017.json file to coco/annotations/, otherwise the subsequent evaluation will report an error!
  3. Create a new coco_kpts folder, download the key point detection label in yolo format and unzip it into the coco_kpts folder (Google cloud disk, if you don’t have a ladder, think of a way yourself, don’t ask me for it in private chat); create a soft link or Copy the images and annotations folders in coco2017 to coco_kpts. The final coco_kpts/ is as shown below: first ignore train2017.cache, and it will be generated during training later.

insert image description here
 Finally, download the code and unzip it to the same directory as coco_kpts.

 After preparation, the final file tree is:

insert image description here
 So far,You can train yolo-pose.

2. Training model

2.1. Possible errors reported: AttributeError: Cant get attribute SPPF on module models.common

Reference link
 Add the following code to the model/common.py file.

import warnings

class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)

    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

2.2. Training model

python train.py --data coco_kpts.yaml --cfg yolov5s6_kpts.yaml --batch-size 64 --img 640 --kpt-label

 It needs to be trained for 300 epochs, and I will add the results after the training is finished. At present, the effect is really good. In the case of 3 epochs, the oks reached 38.3, which is terrifying. :
After training for 100epoch, the accuracy of oks in the test set is 46. The official report is 57, trained for 300epoch.
insert image description here

2.3. Test model

 First download a trained weight in the readme, as shown in the figure below, click on the Yolo5s6_pose_640, and put the downloaded .pt in the edgeai-yolov5-yolo-pose folder.
insert image description here
 Test command:

python test.py --data coco_kpts.yaml --img 640 --conf 0.001 --iou 0.65 --weights "/path/to/edgeai-yolov5-yolo-pose/last.pt" --kpt-label

 Test result: 59.9 is two points higher than the official report.
insert image description here

visualization

 The test/training visualizations are all in the runs folder, and I put a few test legends here:
insert image description here

Summarize

 If you have any questions, please welcome +vx: wulele2541612007, and the source code interpretation of yolo-pose will be released later, so stay tuned.

Guess you like

Origin blog.csdn.net/wulele2/article/details/126555380