一、基于YOLOV5的姿态估计与实现
相关论文:
YOLO-Pose: Enhancing YOLO for Multi Person Pose Estimation Using Object Keypoint Similarity Loss
相关源码
edgeai-yolov5-yolo-pose
二、数据集
The dataset needs to be prepared in YOLO format so that the dataloader can be enhanced to read the keypoints along with the bounding box informations. This repository was used with required changes to generate the dataset in the required format. Please download the processed labels from here . It is advised to create a new directory coco_kpts and create softlink of the directory images and annotations from coco to this directory. Keep the downloaded labels and the files train2017.txt and val2017.txt inside this folder coco_kpts.
1、数据格式
edgeai-yolov5-yolo-pose
│ README.md
│ ...
│
coco_kpts
│ images
| └─────train2017
| │ └───000000000009.jpg
| | └───
| | '
| | .
| └─val2017
| └───000000000139.jpg
| └───
| .
| .
│ annotations
| └───instances_train2017.json
| └───instances_val2017.json
| └───person_keypoints_train2017.json
| └───person_keypoints_val2017.json
| labels
│ └─────train2017
│ │ └───000000000009.txt
| | └───
| | '
| | .
│ └─val2017
| └───000000000139.txt
| └───
| .
| .
| train2017.txt
| val2017.txt
2、train2017.txt和val2017.txt格式
Train: ./images/train2017/000000054301.jpg
val: ./images/val2017/000000345356.jpg
3、labels中train2017和val2017
0 0.671279 0.617945 0.645759 0.726859 0.519751 0.381250 2.000000 0.550936 0.348438 2.000000 0.488565 0.367188 2.000000 0.642412 0.354687 2.000000 0.488565 0.395313 2.000000 0.738046 0.526563 2.000000 0.446985 0.534375 2.000000 0.846154 0.771875 2.000000 0.442827 0.812500 2.000000 0.925156 0.964063 2.000000 0.507277 0.698438 2.000000 0.702703 0.942187 2.000000 0.555094 0.950000 2.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
三、预训练模型
四、训练Training: YOLO-Pose
Train a suitable model by running the following command using a suitable pretrained ckpt from the previous section.
python train.py --data coco_kpts.yaml --cfg yolov5s6_kpts.yaml --weights 'path to the pre-trained ckpts' --batch-size 64 --img 960 --kpt-label
五、测试Model Testing
Run the following command to replicate the accuracy number on the pretrained checkpoints:
python test.py --data coco_kpts.yaml --img 960 --conf 0.001 --iou 0.65 --weights "path to the pre-trained ckpt" --kpt-label
六、训练结果
0/299 4.42G 0.07628 0.04749 0 0.3525 0.01376 0.49 124 640 0.2834 0.2275 0.1675 0.04359 0.06725 0.02535 0
1/299 5.83G 0.04818 0.037 0 0.2862 0.01223 0.3836 67 640 0.7399 0.6585 0.7117 0.3266 0.0398 0.01992 0
2/299 5.83G 0.04229 0.03425 0 0.2438 0.0111 0.3314 132 640 0.7966 0.679 0.7668 0.3904 0.03674 0.01867 0
3/299 5.83G 0.0387 0.03338 0 0.2209 0.01014 0.3031 106 640 0.8247 0.7165 0.8094 0.4492 0.03348 0.01764 0
4/299 5.83G 0.03639 0.03221 0 0.2056 0.009376 0.2836 99 640 0.8163 0.7525 0.8294 0.4775 0.03161 0.01706 0
5/299 5.83G 0.03505 0.0316 0 0.1957 0.008931 0.2713 92 640 0.8312 0.7633 0.8447 0.4982 0.03057 0.01662 0
6/299 5.83G 0.03418 0.03107 0 0.188 0.008644 0.2619 82 640 0.8289 0.7764 0.8542 0.5166 0.02961 0.01634 0
7/299 5.83G 0.03343 0.03072 0 0.1821 0.008456 0.2547 111 640 0.8431 0.7687 0.8586 0.5291 0.02874 0.01607 0
8/299 5.83G 0.03283 0.03041 0 0.1769 0.0083 0.2485 116 640 0.863 0.7628 0.866 0.54 0.02813 0.01578 0
9/299 5.83G 0.03248 0.03021 0 0.1734 0.008208 0.2443 102 640 0.8569 0.7752 0.8697 0.5489 0.02765 0.01562 0
10/299 5.83G 0.03212 0.03003 0 0.1705 0.008114 0.2408 102 640 0.8483 0.7873 0.8735 0.5558 0.02724 0.01551 0
11/299 5.83G 0.03178 0.03004 0 0.1674 0.008038 0.2372 85 640 0.8535 0.786 0.8745 0.561 0.02693 0.0154 0
12/299 5.83G 0.03151 0.02972 0 0.1643 0.00798 0.2335 86 640 0.8682 0.7749 0.876 0.5651 0.02669 0.0153 0
13/299 5.83G 0.03149 0.02995 0 0.1639 0.007939 0.2333 107 640 0.839 0.7948 0.8742 0.5656 0.02669 0.01534 0
14/299 5.83G 0.03109 0.02958 0 0.161 0.00788 0.2295 125 640 0.8428 0.792 0.8753 0.5677 0.02656 0.01529 0
15/299 5.83G 0.03071 0.02941 0 0.1575 0.007818 0.2254 129 640 0.8539 0.7884 0.8771 0.5729 0.02631 0.01518 0
16/299 5.83G 0.03064 0.02945 0 0.1566 0.007787 0.2245 90 640 0.8676 0.7798 0.8786 0.5748 0.02621 0.01512 0
17/299 5.83G 0.03068 0.02946 0 0.1563 0.007777 0.2242 93 640 0.8678 0.7823 0.8801 0.5771 0.02614 0.01509 0
18/299 5.83G 0.03039 0.02924 0 0.1541 0.007732 0.2214 110 640 0.8712 0.7816 0.881 0.5776 0.0261 0.01507 0
19/299 5.83G 0.03034 0.0292 0 0.1523 0.007722 0.2196 89 640 0.8731 0.7824 0.8823 0.5779 0.0261 0.01506 0
20/299 5.83G 0.03033 0.02917 0 0.1498 0.007695 0.217 137 640 0.8727 0.7826 0.8828 0.5783 0.02612 0.01505 0
21/299 5.83G 0.03024 0.02923 0 0.1493 0.007669 0.2164 90 640 0.8751 0.7807 0.8835 0.5788 0.02613 0.01506 0
22/299 5.83G 0.02996 0.02912 0 0.147 0.00763 0.2137 71 640 0.8741 0.7838 0.8863 0.5801 0.02615 0.01506 0
23/299 5.83G 0.02991 0.02897 0 0.1467 0.007619 0.2132 100 640 0.8903 0.7711 0.8866 0.5811 0.0262 0.01508 0
24/299 5.83G 0.02973 0.0288 0 0.1445 0.007574 0.2106 84 640 0.8921 0.7717 0.8873 0.5825 0.02625 0.0151 0
25/299 5.83G 0.02974 0.02887 0 0.1446 0.007568 0.2108 105 640 0.889 0.7744 0.8875 0.5836 0.02631 0.01513 0
26/299 5.83G 0.02966 0.02881 0 0.1438 0.007543 0.2098 93 640 0.8581 0.8004 0.888 0.5844 0.02638 0.01517 0
27/299 5.83G 0.02979 0.02904 0 0.1452 0.007569 0.2115 80 640 0.8457 0.8119 0.8883 0.5853 0.02645 0.01522 0
28/299 5.83G 0.02963 0.02891 0 0.1432 0.007529 0.2093 105 640 0.8412 0.8158 0.8878 0.5862 0.02652 0.01527 0
29/299 5.83G 0.02948 0.02872 0 0.142 0.007504 0.2077 72 640 0.8504 0.8074 0.888 0.587 0.02658 0.01531 0
30/299 5.83G 0.02943 0.02876 0 0.1415 0.00748 0.2072 86 640 0.8587 0.8002 0.8884 0.5875 0.02663 0.01534 0
31/299 5.83G 0.02942 0.02867 0 0.141 0.007485 0.2066 91 640 0.8549 0.8043 0.8887 0.5878 0.02669 0.01539 0
32/299 5.83G 0.02952 0.02881 0 0.141 0.007461 0.2068 98 640 0.858 0.8028 0.8891 0.5873 0.02674 0.01545 0
33/299 5.83G 0.02933 0.02885 0 0.1409 0.007456 0.2065 99 640 0.8561 0.8056 0.8895 0.5883 0.02678 0.0155 0
34/299 5.83G 0.0292 0.02851 0 0.1397 0.00744 0.2048 110 640 0.8533 0.8094 0.8896 0.588 0.02678 0.01554 0
35/299 5.83G 0.02912 0.02848 0 0.1383 0.007409 0.2034 100 640 0.8474 0.8166 0.8901 0.5889 0.02676 0.01556 0
36/299 5.83G 0.0292 0.02859 0 0.139 0.007416 0.2042 80 640 0.8611 0.8037 0.8899 0.589 0.02675 0.01557 0
37/299 5.83G 0.02911 0.02853 0 0.1388 0.007408 0.2038 67 640 0.8801 0.7878 0.8902 0.5895 0.02672 0.01558 0
38/299 5.83G 0.02905 0.02852 0 0.1377 0.007371 0.2026 78 640 0.8779 0.79 0.8901 0.5901 0.02667 0.01559 0
39/299 5.83G 0.02898 0.02854 0 0.1376 0.00739 0.2025 95 640 0.8504 0.8144 0.8905 0.5913 0.02661 0.01559 0
40/299 5.83G 0.02899 0.02846 0 0.1374 0.00736 0.2022 121 640 0.8713 0.7961 0.8908 0.5922 0.02655 0.01558 0
41/299 5.83G 0.02902 0.02854 0 0.1371 0.007363 0.202 114 640 0.8793 0.789 0.8907 0.5936 0.02648 0.01556 0
42/299 5.83G 0.02896 0.02868 0 0.1371 0.007361 0.2021 96 640 0.8839 0.7853 0.8913 0.5946 0.02641 0.01554 0
43/299 5.83G 0.02887 0.02848 0 0.136 0.007331 0.2006 83 640 0.8814 0.7886 0.8921 0.5945 0.02633 0.01551 0
44/299 5.83G 0.02893 0.02852 0 0.1366 0.007333 0.2014 99 640 0.874 0.7952 0.8919 0.5959 0.02623 0.01547 0
45/299 5.83G 0.02883 0.02847 0 0.1353 0.007304 0.1999 86 640 0.8675 0.802 0.8921 0.5967 0.02615 0.01543 0
46/299 5.83G 0.02854 0.02825 0 0.1337 0.007291 0.1978 90 640 0.8652 0.8055 0.8926 0.5978 0.02604 0.01538 0
47/299 5.83G 0.02871 0.02844 0 0.1349 0.007289 0.1994 120 640 0.8693 0.8009 0.8926 0.5989 0.02592 0.01534 0
48/299 5.83G 0.02871 0.02842 0 0.1348 0.007288 0.1992 92 640 0.8555 0.8118 0.8928 0.5997 0.0258 0.0153 0
49/299 5.83G 0.02868 0.02845 0 0.1344 0.007278 0.1988 75 640 0.8784 0.7936 0.8933 0.6005 0.02569 0.01525 0
50/299 5.83G 0.02863 0.02841 0 0.1341 0.007263 0.1984 108 640 0.8813 0.7923 0.8934 0.6013 0.02557 0.01519 0
51/299 5.83G 0.02854 0.02826 0 0.1338 0.007257 0.1978 80 640 0.8852 0.789 0.8933 0.602 0.02545 0.01513 0
52/299 5.83G 0.02874 0.02845 0 0.1346 0.007259 0.1991 111 640 0.8577 0.8108 0.8938 0.6025 0.02533 0.01508 0
53/299 5.83G 0.02859 0.02832 0 0.1331 0.00724 0.1973 108 640 0.8612 0.8098 0.894 0.6039 0.0252 0.01503 0
54/299 5.83G 0.0285 0.02832 0 0.1332 0.007225 0.1972 80 640 0.8597 0.8112 0.8943 0.6045 0.02509 0.01497 0
55/299 5.83G 0.02846 0.02824 0 0.1324 0.007212 0.1963 80 640 0.8604 0.8105 0.894 0.6054 0.02497 0.01492 0
56/299 5.83G 0.02861 0.02828 0 0.1335 0.007236 0.1976 79 640 0.8672 0.8051 0.8941 0.6059 0.02487 0.01488 0
57/299 5.83G 0.02846 0.02822 0 0.1321 0.007217 0.196 106 640 0.8698 0.8038 0.8949 0.6067 0.02477 0.01484 0
58/299 5.83G 0.02849 0.02828 0 0.1324 0.007208 0.1964 101 640 0.8657 0.8067 0.8949 0.6081 0.02469 0.0148 0
59/299 5.83G 0.02846 0.02837 0 0.1328 0.007218 0.1969 87 640 0.8717 0.8024 0.8952 0.6083 0.02461 0.01475 0
60/299 5.83G 0.02843 0.02834 0 0.1318 0.007189 0.1958 94 640 0.8696 0.804 0.895 0.609 0.02453 0.01471 0
61/299 5.83G 0.02837 0.02816 0 0.132 0.007192 0.1957 77 640 0.8731 0.8002 0.8959 0.6094 0.02444 0.01467 0
62/299 5.83G 0.02827 0.02823 0 0.1313 0.007169 0.1949 94 640 0.8765 0.7968 0.8955 0.6111 0.02436 0.01463 0
63/299 5.83G 0.0285 0.02835 0 0.1319 0.00718 0.196 99 640 0.8705 0.8019 0.8962 0.6115 0.02429 0.0146 0
64/299 5.83G 0.02835 0.02821 0 0.1318 0.00716 0.1955 87 640 0.8857 0.7895 0.896 0.6118 0.02423 0.01458 0
65/299 5.83G 0.02826 0.02809 0 0.1309 0.007151 0.1944 88 640 0.8824 0.7917 0.896 0.6124 0.02417 0.01454 0
66/299 5.83G 0.0283 0.02826 0 0.1315 0.007174 0.1953 125 640 0.8759 0.7977 0.8958 0.6132 0.0241 0.01452 0
67/299 5.83G 0.02833 0.02823 0 0.1316 0.007162 0.1953 83 640 0.8839 0.792 0.8966 0.6131 0.02404 0.01449 0
68/299 5.83G 0.02804 0.028 0 0.1297 0.007135 0.1928 92 640 0.8818 0.7947 0.897 0.6142 0.02398 0.01446 0
69/299 5.83G 0.02823 0.02815 0 0.1307 0.007125 0.1942 99 640 0.8839 0.7914 0.8968 0.6142 0.02393 0.01442 0
七、可能存在的错误
AttributeError: Cant get attribute SPPF on module models.common
修改方法:
在model/common.py文件中加上如下代码即可。
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))
八、结果测试
yolov5-pose
九、总结
训练时发现,改模型会迅速收敛,但是最高达到89.6左右。后面将详细研究相关代码和论文算法