百度AI攻略:Paddlehub实现关键点检测

非 Y 不嫁゛ 提交于 2020-01-10 10:49:23

【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>

PaddleHub可以便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,可以基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。

模型概述

人体骨骼关键点检测(Pose Estimation) 是计算机视觉的基础性算法之一,在诸多计算机视觉任务起到了基础性的作用,如行为识别、人物跟踪、步态识别等相关领域。具体应用主要集中在智能视频监控,病人监护系统,人机交互,虚拟现实,人体动画,智能家居,智能安防,运动员辅助训练等等。 该模型的论文《Simple Baselines for Human Pose Estimation and Tracking》由 MSRA 发表于 ECCV18,使用 MPII 数据集训练完成。

代码及效果示例:

import paddlehub as hub

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

#pose_resnet50_mpii

module = hub.Module(name="pose_resnet50_mpii")

test_img_path = "./body2.jpg"

# 预测结果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = module.keypoint_detection(data=input_dict)

for result in results:

    print(result)

test_img_path = "./output_pose/rendered_body2.jpg"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-05 12:20:51,492] [    INFO] - Installing pose_resnet50_mpii module

2020-01-05 12:20:51,492-INFO: Installing pose_resnet50_mpii module

[2020-01-05 12:20:51,508] [    INFO] - Module pose_resnet50_mpii already installed in /home/aistudio/.paddlehub/modules/pose_resnet50_mpii

2020-01-05 12:20:51,508-INFO: Module pose_resnet50_mpii already installed in /home/aistudio/.paddlehub/modules/pose_resnet50_mpii

[2020-01-05 12:20:51,958] [    INFO] - 282 pretrained paramaters loaded by PaddleHub

2020-01-05 12:20:51,958-INFO: 282 pretrained paramaters loaded by PaddleHub

{'path': 'output_pose/rendered_body2.jpg', 'data': {'left_ankle': [178, 250], 'left_knee': [220, 224], 'left_hip': [201, 215], 'right_hip': [243, 215], 'right_knee': [243, 224], 'right_ankle': [234, 247], 'pelvis': [225, 215], 'thorax': [220, 123], 'upper neck': [220, 98], 'head top': [220, 57], 'right_wrist': [112, 212], 'right_elbow': [168, 180], 'right_shoulder': [182, 126], 'left_shoulder': [257, 120], 'left_elbow': [276, 180], 'left_wrist': [309, 218]}}

module = hub.Module(name="pose_resnet50_mpii")

test_img_path = "./body10.jpg"

# 预测结果展示

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

# set input dict

input_dict = {"image": [test_img_path]}

# execute predict and print the result

results = module.keypoint_detection(data=input_dict)

for result in results:

    print(result)

test_img_path = "./output_pose/rendered_body10.jpg"

img = mpimg.imread(test_img_path)

plt.imshow(img)

plt.axis('off')

plt.show()

[2020-01-05 12:22:10,407] [    INFO] - Installing pose_resnet50_mpii module

2020-01-05 12:22:10,407-INFO: Installing pose_resnet50_mpii module

[2020-01-05 12:22:10,422] [    INFO] - Module pose_resnet50_mpii already installed in /home/aistudio/.paddlehub/modules/pose_resnet50_mpii

2020-01-05 12:22:10,422-INFO: Module pose_resnet50_mpii already installed in /home/aistudio/.paddlehub/modules/pose_resnet50_mpii

[2020-01-05 12:22:10,919] [    INFO] - 282 pretrained paramaters loaded by PaddleHub

2020-01-05 12:22:10,919-INFO: 282 pretrained paramaters loaded by PaddleHub

{'path': 'output_pose/rendered_body10.jpg', 'data': {'left_ankle': [335, 870], 'left_knee': [306, 642], 'left_hip': [313, 555], 'right_hip': [335, 533], 'right_knee': [298, 653], 'right_ankle': [408, 761], 'pelvis': [328, 533], 'thorax': [298, 435], 'upper neck': [306, 413], 'head top': [364, 337], 'right_wrist': [320, 348], 'right_elbow': [298, 391], 'right_shoulder': [291, 424], 'left_shoulder': [313, 457], 'left_elbow': [408, 500], 'left_wrist': [495, 533]}}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!