--- library_name: transformers license: apache-2.0 language: - en pipeline_tag: keypoint-detection --- # Model Card for Model ID ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/ZuIwMdomy2_6aJ_JTE1Yd.png) 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. ## Model Details 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 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, and transferability of knowledge between models, through a simple baseline model called ViTPose. Specifically, ViTPose employs plain and non-hierarchical vision transformers as backbones to extract features for a given person instance and a lightweight decoder for pose estimation. It can be scaled up from 100M to 1B parameters by taking the advantages of the scalable model capacity and high 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 tasks. We also empirically demonstrate that the knowledge of large ViTPose models can be easily transferred to small ones via a simple knowledge token. Experimental results show that our basic ViTPose model outperforms representative methods on the challenging MS COCO Keypoint Detection benchmark, while the largest model sets a new state-of-the-art, i.e., 80.9 AP on the MS COCO test-dev set. The code and models are available at https://github.com/ViTAE-Transformer/ViTPose ### Model Description This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated. - **Developed by:** Sangbum Choi and Niels Rogge - **Funded by [optional]:** ARC FL-170100117 and IH-180100002. - **Shared by [optional]:** [More Information Needed] - **Model type:** [More Information Needed] - **Language(s) (NLP):** [More Information Needed] - **License:** apache-2.0 - **Finetuned from model [optional]:** [More Information Needed] ### Model Sources [optional] - **Repository:** https://github.com/ViTAE-Transformer/ViTPose - **Paper [optional]:** https://arxiv.org/pdf/2204.12484 - **Demo [optional]:** [More Information Needed] ## Uses ### Direct Use [More Information Needed] ### Downstream Use [optional] [More Information Needed] ### Out-of-Scope Use [More Information Needed] ## Bias, Risks, and Limitations In this paper, we propose a simple yet effective vision transformer baseline for pose estimation, i.e., ViTPose. Despite no elaborate designs in structure, ViTPose obtains SOTA performance on the MS COCO dataset. However, the potential of ViTPose is not fully explored with more advanced technologies, such as complex decoders or FPN structures, which may further improve the performance. Besides, although the ViTPose demonstrates exciting properties such as simplicity, scalability, flexibility, and transferability, more research efforts could be made, e.g., exploring the prompt-based tuning to demonstrate the flexibility of ViTPose further. In addition, we believe ViTPose can also be applied to other pose estimation datasets, e.g., animal pose estimation [47, 9, 45] and face keypoint detection [21, 6]. We leave them as the future work. ### Recommendations Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations. ## How to Get Started with the Model Use the code below to get started with the model. ``` import numpy as np import requests import torch from PIL import Image from transformers import ( RTDetrForObjectDetection, RTDetrImageProcessor, VitPoseConfig, VitPoseForPoseEstimation, VitPoseImageProcessor, ) url = "http://images.cocodataset.org/val2017/000000000139.jpg" image = Image.open(requests.get(url, stream=True).raw) # Stage 1. Run Object Detector (User can replace this object_detector part) person_image_processor = RTDetrImageProcessor.from_pretrained("PekingU/rtdetr_r50vd_coco_o365") person_model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd_coco_o365") inputs = person_image_processor(images=image, return_tensors="pt") with torch.no_grad(): outputs = person_model(**inputs) results = person_image_processor.post_process_object_detection( outputs, target_sizes=torch.tensor([(image.height, image.width)]), threshold=0.3 ) def pascal_voc_to_coco(bboxes: np.ndarray) -> np.ndarray: """ Converts bounding boxes from the Pascal VOC format to the COCO format. In other words, converts from (top_left_x, top_left_y, bottom_right_x, bottom_right_y) format to (top_left_x, top_left_y, width, height). Args: bboxes (`np.ndarray` of shape `(batch_size, 4)): Bounding boxes in Pascal VOC format. Returns: `np.ndarray` of shape `(batch_size, 4) in COCO format. """ bboxes[:, 2] = bboxes[:, 2] - bboxes[:, 0] bboxes[:, 3] = bboxes[:, 3] - bboxes[:, 1] return bboxes # Human label refers 0 index in COCO dataset boxes = results[0]["boxes"][results[0]["labels"] == 0] boxes = [pascal_voc_to_coco(boxes.cpu().numpy())] # Stage 2. Run ViTPose config = VitPoseConfig() image_processor = VitPoseImageProcessor.from_pretrained("nielsr/vitpose-base-simple") model = VitPoseForPoseEstimation.from_pretrained("nielsr/vitpose-base-simple") pixel_values = image_processor(image, boxes=boxes, return_tensors="pt").pixel_values with torch.no_grad(): outputs = model(pixel_values) pose_results = image_processor.post_process_pose_estimation(outputs, boxes=boxes)[0] for pose_result in pose_results: print(pose_result) ``` ## Training Details ### Training Data [More Information Needed] ### Training Procedure #### Preprocessing [optional] [More Information Needed] #### Training Hyperparameters - **Training regime:** ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/Gj6gGcIGO3J5HD2MAB_4C.png) #### Speeds, Sizes, Times [optional] ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/rsCmn48SAvhi8xwJhX8h5.png) ## Evaluation ### Testing Data, Factors & Metrics #### Testing Data [More Information Needed] #### Factors [More Information Needed] #### Metrics [More Information Needed] ### Results ![image/png](https://cdn-uploads.huggingface.co/production/uploads/6579e0eaa9e58aec614e9d97/FcHVFdUmCuT2m0wzB8QSS.png) #### Summary ## Model Examination [optional] [More Information Needed] ## Environmental Impact Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). - **Hardware Type:** [More Information Needed] - **Hours used:** [More Information Needed] - **Cloud Provider:** [More Information Needed] - **Compute Region:** [More Information Needed] - **Carbon Emitted:** [More Information Needed] ## Technical Specifications [optional] ### Model Architecture and Objective [More Information Needed] ### Compute Infrastructure [More Information Needed] #### Hardware The models are trained on 8 A100 GPUs based on the mmpose codebase [11] #### Software [More Information Needed] ## Citation [optional] **BibTeX:** @misc{xu2022vitposesimplevisiontransformer, title={ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation}, author={Yufei Xu and Jing Zhang and Qiming Zhang and Dacheng Tao}, year={2022}, eprint={2204.12484}, archivePrefix={arXiv}, primaryClass={cs.CV}, url={https://arxiv.org/abs/2204.12484}, } **APA:** [More Information Needed] ## Glossary [optional] [More Information Needed] ## More Information [optional] [More Information Needed] ## Model Card Authors [optional] [More Information Needed] ## Model Card Contact [More Information Needed]