模型简介
模型特点
模型能力
使用案例
🚀 VitPose模型卡片
ViTPose是用于人体姿态估计的简单视觉Transformer基线模型,ViTPose++则是用于通用人体姿态估计的视觉Transformer基础模型。该模型在MS COCO关键点测试开发集上达到了81.1的平均精度(AP)。
🚀 快速开始
使用以下代码开始使用该模型:
import torch
import requests
import numpy as np
from PIL import Image
from transformers import (
AutoProcessor,
RTDetrForObjectDetection,
VitPoseForPoseEstimation,
)
device = "cuda" if torch.cuda.is_available() else "cpu"
url = "http://images.cocodataset.org/val2017/000000000139.jpg"
image = Image.open(requests.get(url, stream=True).raw)
# ------------------------------------------------------------------------
# Stage 1. Detect humans on the image
# ------------------------------------------------------------------------
# You can choose detector by your choice
person_image_processor = AutoProcessor.from_pretrained("PekingU/rtdetr_r50vd_coco_o365")
person_model = RTDetrForObjectDetection.from_pretrained("PekingU/rtdetr_r50vd_coco_o365", device_map=device)
inputs = person_image_processor(images=image, return_tensors="pt").to(device)
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
)
result = results[0] # take first image results
# Human label refers 0 index in COCO dataset
person_boxes = result["boxes"][result["labels"] == 0]
person_boxes = person_boxes.cpu().numpy()
# Convert boxes from VOC (x1, y1, x2, y2) to COCO (x1, y1, w, h) format
person_boxes[:, 2] = person_boxes[:, 2] - person_boxes[:, 0]
person_boxes[:, 3] = person_boxes[:, 3] - person_boxes[:, 1]
# ------------------------------------------------------------------------
# Stage 2. Detect keypoints for each person found
# ------------------------------------------------------------------------
image_processor = AutoProcessor.from_pretrained("usyd-community/vitpose-plus-large")
model = VitPoseForPoseEstimation.from_pretrained("usyd-community/vitpose-plus-large", device_map=device)
inputs = image_processor(image, boxes=[person_boxes], return_tensors="pt").to(device)
with torch.no_grad():
outputs = model(**inputs)
pose_results = image_processor.post_process_pose_estimation(outputs, boxes=[person_boxes], threshold=0.3)
image_pose_result = pose_results[0] # results for first image
for i, person_pose in enumerate(image_pose_result):
print(f"Person #{i}")
for keypoint, label, score in zip(
person_pose["keypoints"], person_pose["labels"], person_pose["scores"]
):
keypoint_name = model.config.id2label[label.item()]
x, y = keypoint
print(f" - {keypoint_name}: x={x.item():.2f}, y={y.item():.2f}, score={score.item():.2f}")
输出:
Person #0
- Nose: x=428.25, y=170.88, score=0.98
- L_Eye: x=428.76, y=168.03, score=0.97
- R_Eye: x=428.09, y=168.15, score=0.82
- L_Ear: x=433.28, y=167.72, score=0.95
- R_Ear: x=440.77, y=166.66, score=0.88
- L_Shoulder: x=440.52, y=177.60, score=0.92
- R_Shoulder: x=444.64, y=178.11, score=0.70
- L_Elbow: x=436.64, y=198.21, score=0.92
- R_Elbow: x=431.42, y=201.19, score=0.76
- L_Wrist: x=430.96, y=218.39, score=0.98
- R_Wrist: x=419.95, y=213.27, score=0.85
- L_Hip: x=445.33, y=222.93, score=0.77
- R_Hip: x=451.91, y=222.52, score=0.75
- L_Knee: x=443.31, y=255.61, score=0.83
- R_Knee: x=451.42, y=255.03, score=0.84
- L_Ankle: x=447.76, y=287.33, score=0.68
- R_Ankle: x=456.78, y=286.08, score=0.83
Person #1
- Nose: x=398.23, y=181.74, score=0.89
- L_Eye: x=398.31, y=179.77, score=0.84
- R_Eye: x=395.99, y=179.46, score=0.91
- R_Ear: x=388.95, y=180.24, score=0.86
- L_Shoulder: x=397.35, y=194.22, score=0.73
- R_Shoulder: x=384.50, y=190.86, score=0.58
✨ 主要特性
- 性能出色:在MS COCO关键点测试开发集上取得了81.1的AP成绩。
- 结构简单:采用简单且非分层的视觉Transformer作为骨干网络。
- 可扩展性强:模型参数可从1亿扩展到10亿。
- 灵活性高:在注意力类型、输入分辨率、预训练和微调策略等方面具有很高的灵活性。
- 知识可迁移:大模型的知识可通过简单的知识令牌轻松迁移到小模型。
📚 详细文档
模型详情
尽管在设计中未考虑特定领域知识,但普通视觉Transformer在视觉识别任务中表现出色。然而,在揭示这种简单结构在姿态估计任务中的潜力方面,人们所做的工作较少。在本文中,作者通过一个名为ViTPose的简单基线模型,从多个方面展示了普通视觉Transformer在姿态估计方面的惊人能力,即模型结构简单、模型大小可扩展、训练范式灵活以及模型间知识可迁移。具体而言,ViTPose采用普通且非分层的视觉Transformer作为骨干网络,为给定的人体实例提取特征,并使用轻量级解码器进行姿态估计。借助Transformer可扩展的模型容量和高并行性,其参数可从1亿扩展到10亿,在吞吐量和性能之间达到了新的帕累托最优。此外,ViTPose在注意力类型、输入分辨率、预训练和微调策略以及处理多姿态任务方面非常灵活。作者还通过实验证明,大型ViTPose模型的知识可通过简单的知识令牌轻松迁移到小型模型。实验结果表明,基本的ViTPose模型在具有挑战性的MS COCO关键点检测基准上优于代表性方法,而最大的模型则创造了新的最优成绩,即在MS COCO测试开发集上达到了80.9的AP。代码和模型可在https://github.com/ViTAE-Transformer/ViTPose 获取。
模型描述
这是一个已推送到Hugging Face Hub的🤗 transformers模型的模型卡片,该模型卡片是自动生成的。
- 开发者:Yufei Xu、Jing Zhang、Qiming Zhang、Dacheng Tao
- 资助方:ARC FL - 170100117和IH - 180100002
- 许可证:Apache - 2.0
- 移植到🤗 Transformers的人员:Sangbum Choi和Niels Rogge
模型来源
- 原始仓库:https://github.com/ViTAE-Transformer/ViTPose
- 论文:https://arxiv.org/pdf/2204.12484
- 演示:https://huggingface.co/spaces?sort=trending&search=vitpose
模型用途
由ViTAE - Transformer团队开发的ViTPose模型主要用于姿态估计任务,以下是该模型的一些直接应用:
- 人体姿态估计:可用于估计图像或视频中人体的姿态,识别头部、肩部、肘部、手腕、臀部、膝盖和脚踝等关键身体关节的位置。
- 动作识别:通过分析一段时间内的姿态,帮助识别各种人类动作和活动。
- 监控:在安全和监控应用中,可用于监控和分析公共场所或私人场所中的人类行为。
- 健康与健身:可用于健身应用程序,跟踪和分析运动姿势,提供关于姿势和技巧的反馈。
- 游戏和动画:可集成到游戏和动画系统中,创建更逼真的角色动作和交互。
偏差、风险和局限性
在本文中,作者提出了一个简单而有效的用于姿态估计的视觉Transformer基线模型ViTPose。尽管在结构上没有精心设计,但ViTPose在MS COCO数据集上取得了最优性能。然而,ViTPose的潜力尚未通过更先进的技术(如复杂解码器或FPN结构)得到充分挖掘,这些技术可能会进一步提高其性能。此外,尽管ViTPose展示了诸如简单性、可扩展性、灵活性和可迁移性等令人兴奋的特性,但仍需进行更多的研究工作,例如探索基于提示的微调,以进一步展示其灵活性。此外,作者认为ViTPose也可应用于其他姿态估计数据集,如动物姿态估计和面部关键点检测。这些将作为未来的工作方向。
训练详情
训练数据
作者使用MS COCO、AI Challenger、MPII和CrowdPose数据集进行训练和评估。OCHuman数据集仅用于评估阶段,以衡量模型在处理遮挡人体时的性能。
- MS COCO数据集:包含118K张图像和150K个人体实例,每个实例最多有17个关键点注释,该数据集遵循CC - BY - 4.0许可证。
- MPII数据集:遵循BSD许可证,包含15K张图像和22K个人体实例,每个实例最多注释16个人体关键点。
- AI Challenger数据集:规模更大,包含超过200K张训练图像和350个人体实例,每个实例最多注释14个关键点。
- OCHuman数据集:包含大量遮挡的人体实例,仅用于验证和测试集,包括4K张图像和8K个实例。
训练超参数
- 训练方案:
速度、大小和时间
评估
OCHuman验证和测试集
为了评估人体姿态估计模型在严重遮挡人体实例上的性能,作者在OCHuman验证和测试集上使用真实边界框对ViTPose变体和代表性模型进行了测试。由于OCHuman数据集中并非所有人体实例都有注释,使用额外的人体检测器会导致大量“误报”边界框,无法反映姿态估计模型的真实能力,因此作者未采用额外的人体检测器。具体而言,使用了对应于MS COCO数据集的ViTPose解码器头,因为MS COCO和OCHuman数据集中的关键点定义相同。
MPII验证集
作者在MPII验证集上使用真实边界框评估了ViTPose和代表性模型的性能。遵循MPII的默认设置,使用PCKh作为性能评估指标。
评估结果
模型架构和目标
硬件
模型基于mmpose代码库在8个A100 GPU上进行训练。
引用
BibTeX:
@article{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}
}
@misc{xu2023vitposevisiontransformergeneric,
title={ViTPose++: Vision Transformer for Generic Body Pose Estimation},
author={Yufei Xu and Jing Zhang and Qiming Zhang and Dacheng Tao},
year={2023},
eprint={2212.04246},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2212.04246},
}
📄 许可证
本项目采用Apache - 2.0许可证。









