Keypoint Detection
Transformers
amorrissette commited on
Commit
26deede
·
verified ·
1 Parent(s): 6570569

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +250 -3
README.md CHANGED
@@ -1,3 +1,250 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: apache-2.0
4
+ pipeline_tag: keypoint-detection
5
+ ---
6
+
7
+ # Model Card for VitPose
8
+
9
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/ZuIwMdomy2_6aJ_JTE1Yd.png" alt="x" width="400"/>
10
+
11
+ ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation and ViTPose++: Vision Transformer Foundation Model for Generic Body Pose Estimation. It obtains 81.1 AP on MS COCO Keypoint test-dev set.
12
+
13
+ ## Model Details
14
+
15
+ Although no specific domain knowledge is considered in the design, plain vision transformers have shown excellent performance in visual recognition tasks. However, little effort has been made to reveal the potential of such simple structures for
16
+ pose estimation tasks. In this paper, we show the surprisingly good capabilities of plain vision transformers for pose estimation from various aspects, namely simplicity in model structure, scalability in model size, flexibility in training paradigm,
17
+ and transferability of knowledge between models, through a simple baseline model called ViTPose. Specifically, ViTPose employs plain and non-hierarchical vision
18
+ transformers as backbones to extract features for a given person instance and a
19
+ lightweight decoder for pose estimation. It can be scaled up from 100M to 1B
20
+ parameters by taking the advantages of the scalable model capacity and high
21
+ parallelism of transformers, setting a new Pareto front between throughput and performance. Besides, ViTPose is very flexible regarding the attention type, input resolution, pre-training and finetuning strategy, as well as dealing with multiple pose
22
+ tasks. We also empirically demonstrate that the knowledge of large ViTPose models
23
+ can be easily transferred to small ones via a simple knowledge token. Experimental
24
+ results show that our basic ViTPose model outperforms representative methods
25
+ on the challenging MS COCO Keypoint Detection benchmark, while the largest
26
+ model sets a new state-of-the-art, i.e., 80.9 AP on the MS COCO test-dev set. The
27
+ code and models are available at https://github.com/ViTAE-Transformer/ViTPose
28
+
29
+ ### Model Description
30
+
31
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
32
+
33
+ - **Developed by:** Yufei Xu, Jing Zhang, Qiming Zhang, Dacheng Tao
34
+ - **Funded by:** ARC FL-170100117 and IH-180100002.
35
+ - **License:** Apache-2.0
36
+ - **Ported to 🤗 Transformers by:** Sangbum Choi and Niels Rogge
37
+
38
+ ### Model Sources
39
+
40
+ - **Original repository:** https://github.com/ViTAE-Transformer/ViTPose
41
+ - **Paper:** https://arxiv.org/pdf/2204.12484
42
+ - **Demo:** https://huggingface.co/spaces?sort=trending&search=vitpose
43
+
44
+ ## Uses
45
+
46
+ The ViTPose model, developed by the ViTAE-Transformer team, is primarily designed for pose estimation tasks. Here are some direct uses of the model:
47
+
48
+ Human Pose Estimation: The model can be used to estimate the poses of humans in images or videos. This involves identifying the locations of key body joints such as the head, shoulders, elbows, wrists, hips, knees, and ankles.
49
+
50
+ Action Recognition: By analyzing the poses over time, the model can help in recognizing various human actions and activities.
51
+
52
+ Surveillance: In security and surveillance applications, ViTPose can be used to monitor and analyze human behavior in public spaces or private premises.
53
+
54
+ Health and Fitness: The model can be utilized in fitness apps to track and analyze exercise poses, providing feedback on form and technique.
55
+
56
+ Gaming and Animation: ViTPose can be integrated into gaming and animation systems to create more realistic character movements and interactions.
57
+
58
+
59
+ ## Bias, Risks, and Limitations
60
+
61
+ In this paper, we propose a simple yet effective vision transformer baseline for pose estimation,
62
+ i.e., ViTPose. Despite no elaborate designs in structure, ViTPose obtains SOTA performance
63
+ on the MS COCO dataset. However, the potential of ViTPose is not fully explored with more
64
+ advanced technologies, such as complex decoders or FPN structures, which may further improve the
65
+ performance. Besides, although the ViTPose demonstrates exciting properties such as simplicity,
66
+ scalability, flexibility, and transferability, more research efforts could be made, e.g., exploring the
67
+ prompt-based tuning to demonstrate the flexibility of ViTPose further. In addition, we believe
68
+ ViTPose can also be applied to other pose estimation datasets, e.g., animal pose estimation [47, 9, 45]
69
+ and face keypoint detection [21, 6]. We leave them as the future work.
70
+
71
+ ## How to Get Started with the Model
72
+
73
+ Use the code below to get started with the model.
74
+
75
+ ```python
76
+ import torch
77
+ import requests
78
+ import numpy as np
79
+
80
+ from PIL import Image
81
+
82
+ from transformers import (
83
+ AutoProcessor,
84
+ RTDetrForObjectDetection,
85
+ VitPoseForPoseEstimation,
86
+ )
87
+
88
+ device = "cuda" if torch.cuda.is_available() else "cpu"
89
+
90
+ url = "http://images.cocodataset.org/val2017/000000000139.jpg"
91
+ image = Image.open(requests.get(url, stream=True).raw)
92
+
93
+ # ------------------------------------------------------------------------
94
+ # Stage 1. Detect humans on the image
95
+ # ------------------------------------------------------------------------
96
+
97
+ # You can choose detector by your choice
98
+ person_image_processor = AutoProcessor.from_pretrained("PekingU/rtdetr_r50vd_coco_o365")
99
+ person_model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd_coco_o365", device_map=device)
100
+
101
+ inputs = person_image_processor(images=image, return_tensors="pt").to(device)
102
+
103
+ with torch.no_grad():
104
+ outputs = person_model(**inputs)
105
+
106
+ results = person_image_processor.post_process_object_detection(
107
+ outputs, target_sizes=torch.tensor([(image.height, image.width)]), threshold=0.3
108
+ )
109
+ result = results[0] # take first image results
110
+
111
+ # Human label refers 0 index in COCO dataset
112
+ person_boxes = result["boxes"][result["labels"] == 0]
113
+ person_boxes = person_boxes.cpu().numpy()
114
+
115
+ # Convert boxes from VOC (x1, y1, x2, y2) to COCO (x1, y1, w, h) format
116
+ person_boxes[:, 2] = person_boxes[:, 2] - person_boxes[:, 0]
117
+ person_boxes[:, 3] = person_boxes[:, 3] - person_boxes[:, 1]
118
+
119
+ # ------------------------------------------------------------------------
120
+ # Stage 2. Detect keypoints for each person found
121
+ # ------------------------------------------------------------------------
122
+
123
+ image_processor = AutoProcessor.from_pretrained("usyd-community/vitpose-plus-large")
124
+ model = VitPoseForPoseEstimation.from_pretrained("usyd-community/vitpose-plus-large", device_map=device)
125
+
126
+ inputs = image_processor(image, boxes=[person_boxes], return_tensors="pt").to(device)
127
+
128
+ with torch.no_grad():
129
+ outputs = model(**inputs)
130
+
131
+ pose_results = image_processor.post_process_pose_estimation(outputs, boxes=[person_boxes], threshold=0.3)
132
+ image_pose_result = pose_results[0] # results for first image
133
+
134
+ for i, person_pose in enumerate(image_pose_result):
135
+ print(f"Person #{i}")
136
+ for keypoint, label, score in zip(
137
+ person_pose["keypoints"], person_pose["labels"], person_pose["scores"]
138
+ ):
139
+ keypoint_name = model.config.id2label[label.item()]
140
+ x, y = keypoint
141
+ print(f" - {keypoint_name}: x={x.item():.2f}, y={y.item():.2f}, score={score.item():.2f}")
142
+
143
+ ```
144
+ Output:
145
+ ```
146
+ Person #0
147
+ - Nose: x=428.25, y=170.88, score=0.98
148
+ - L_Eye: x=428.76, y=168.03, score=0.97
149
+ - R_Eye: x=428.09, y=168.15, score=0.82
150
+ - L_Ear: x=433.28, y=167.72, score=0.95
151
+ - R_Ear: x=440.77, y=166.66, score=0.88
152
+ - L_Shoulder: x=440.52, y=177.60, score=0.92
153
+ - R_Shoulder: x=444.64, y=178.11, score=0.70
154
+ - L_Elbow: x=436.64, y=198.21, score=0.92
155
+ - R_Elbow: x=431.42, y=201.19, score=0.76
156
+ - L_Wrist: x=430.96, y=218.39, score=0.98
157
+ - R_Wrist: x=419.95, y=213.27, score=0.85
158
+ - L_Hip: x=445.33, y=222.93, score=0.77
159
+ - R_Hip: x=451.91, y=222.52, score=0.75
160
+ - L_Knee: x=443.31, y=255.61, score=0.83
161
+ - R_Knee: x=451.42, y=255.03, score=0.84
162
+ - L_Ankle: x=447.76, y=287.33, score=0.68
163
+ - R_Ankle: x=456.78, y=286.08, score=0.83
164
+ Person #1
165
+ - Nose: x=398.23, y=181.74, score=0.89
166
+ - L_Eye: x=398.31, y=179.77, score=0.84
167
+ - R_Eye: x=395.99, y=179.46, score=0.91
168
+ - R_Ear: x=388.95, y=180.24, score=0.86
169
+ - L_Shoulder: x=397.35, y=194.22, score=0.73
170
+ - R_Shoulder: x=384.50, y=190.86, score=0.58
171
+ ```
172
+
173
+ ## Training Details
174
+
175
+ ### Training Data
176
+
177
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
178
+
179
+ Dataset details. We use MS COCO [28], AI Challenger [41], MPII [3], and CrowdPose [22] datasets
180
+ for training and evaluation. OCHuman [54] dataset is only involved in the evaluation stage to measure
181
+ the models’ performance in dealing with occluded people. The MS COCO dataset contains 118K
182
+ images and 150K human instances with at most 17 keypoint annotations each instance for training.
183
+ The dataset is under the CC-BY-4.0 license. MPII dataset is under the BSD license and contains
184
+ 15K images and 22K human instances for training. There are at most 16 human keypoints for each
185
+ instance annotated in this dataset. AI Challenger is much bigger and contains over 200K training
186
+ images and 350 human instances, with at most 14 keypoints for each instance annotated. OCHuman
187
+ contains human instances with heavy occlusion and is just used for val and test set, which includes
188
+ 4K images and 8K instances.
189
+
190
+
191
+ #### Training Hyperparameters
192
+
193
+ - **Training regime:** ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/Gj6gGcIGO3J5HD2MAB_4C.png)
194
+
195
+ #### Speeds, Sizes, Times
196
+
197
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/rsCmn48SAvhi8xwJhX8h5.png)
198
+
199
+ ## Evaluation
200
+
201
+ OCHuman val and test set. To evaluate the performance of human pose estimation models on the
202
+ human instances with heavy occlusion, we test the ViTPose variants and representative models on
203
+ the OCHuman val and test set with ground truth bounding boxes. We do not adopt extra human
204
+ detectors since not all human instances are annotated in the OCHuman datasets, where the human
205
+ detector will cause a lot of “false positive” bounding boxes and can not reflect the true ability of
206
+ pose estimation models. Specifically, the decoder head of ViTPose corresponding to the MS COCO
207
+ dataset is used, as the keypoint definitions are the same in MS COCO and OCHuman datasets.
208
+
209
+ MPII val set. We evaluate the performance of ViTPose and representative models on the MPII val
210
+ set with the ground truth bounding boxes. Following the default settings of MPII, we use PCKh
211
+ as metric for performance evaluation.
212
+
213
+ ### Results
214
+
215
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/FcHVFdUmCuT2m0wzB8QSS.png)
216
+
217
+
218
+ ### Model Architecture and Objective
219
+
220
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/kf3e1ifJkVtOMbISvmMsM.png)
221
+
222
+ #### Hardware
223
+
224
+ The models are trained on 8 A100 GPUs based on the mmpose codebase
225
+
226
+
227
+ ## Citation
228
+
229
+ **BibTeX:**
230
+
231
+ ```bibtex
232
+ @article{xu2022vitposesimplevisiontransformer,
233
+ title={ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation},
234
+ author={Yufei Xu and Jing Zhang and Qiming Zhang and Dacheng Tao},
235
+ year={2022},
236
+ eprint={2204.12484},
237
+ archivePrefix={arXiv},
238
+ primaryClass={cs.CV},
239
+ url={https://arxiv.org/abs/2204.12484}
240
+ }
241
+ @misc{xu2023vitposevisiontransformergeneric,
242
+ title={ViTPose++: Vision Transformer for Generic Body Pose Estimation},
243
+ author={Yufei Xu and Jing Zhang and Qiming Zhang and Dacheng Tao},
244
+ year={2023},
245
+ eprint={2212.04246},
246
+ archivePrefix={arXiv},
247
+ primaryClass={cs.CV},
248
+ url={https://arxiv.org/abs/2212.04246},
249
+ }
250
+ ```