当前位置: 首页 > news >正文

姿态分析开源工具箱MMPose安装及使用示例(2d face landmark detection)

      MMPose是一个基于PyTorch的姿态分析的开源工具箱,是OpenMMLab项目的一部分,源码在https://github.com/open-mmlab/mmpose,最新发布版本为v0.28.1,License为Apache-2.0。它支持在Windows、Linux和Mac上运行。
      1.安装:使用conda安装
      (1).创建openmmlab虚拟环境:

conda create -n openmmlab python=3.8
conda activate openmmlab

      (2).安装PyTorch:这里PyTorch使用1.11.0版本,CUDA使用10.2版本,此CUDA版本对PyTorch各版本都支持 

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=10.2 -c pytorch

      (3).安装MMCV:MMCV有两个版本,这里安装带CUDA的mmcv-full
      1).mmcv-full: 完整版,包含所有的特性以及丰富的开箱即用的CUDA算子,安装此版本需要较长时间。
      2).mmcv:精简版,不包含CUDA算子但包含其余所有特性和功能,类似MMCV 1.0之前的版本。
      不要在同一个环境中安装两个版本,否则可能会遇到类似ModuleNotFound的错误。在安装一个版本之前,需要先卸载另一个:

pip uninstall mmcv-full
pip uninstall mmcv

      注意:这里mmcv-full使用1.5.3版本。CUDA版本和PyTorch版本与安装PyTorch时保持一致

pip install mmcv-full==1.5.3 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.11.0/index.html

      (4).安装MMPose:没有通过源码安装

pip install mmpose==0.28.1

      (5).安装MMDetection:MMPose中个别模块会需要

pip install mmdet==2.25.1

      (6).安装face_recognition:MMPose中个别模块会需要,face_recognition依赖dlib,因此安装face_recognition之前需要先安装dlib

conda install -c conda-forge dlib
pip3 install face_recognition

      2.测试:论文:《Deep High-Resolution Representation Learning for Visual Recognition》,19点

      (1).准备测试图像:原始图像来自网络

image_path = "../../data/image/"
image_name = "2.jpg"

       (2).通过开源模块face_recognition检测人脸框:

data = face_recognition.load_image_file(image)
face_det_results = face_recognition.face_locations(data) # a list of tuples of found face locations in css (top, right, bottom, left) order
print("face detect results:", face_det_results)

face_bbox_results = []

mat = cv2.imread(image)
for rect in face_det_results:
    cv2.rectangle(mat, (rect[3], rect[0]), (rect[1], rect[2]), (0, 255, 0), 1)
    person = {}
    person["bbox"] = [rect[3], rect[0], rect[1], rect[2]]
    face_bbox_results.append(person)

cv2.imwrite("../../data/result_mmpose_face_location.png", mat)
cv2.imshow("show", mat)
cv2.waitKey(0)

print("face bbox results:", face_bbox_results)
return face_bbox_results

      (3).下载模型:

def download_checkpoint(path, name, url):
	if os.path.isfile(path+name) == False:
		print("checkpoint(model) file does not exist, now download ...")
		subprocess.run(["wget", "-P", path, url])

path = "../../data/model/"
checkpoint = "hrnetv2_w18_aflw_256x256-f2bbc62b_20210125.pth"
url = "https://download.openmmlab.com/mmpose/face/hrnetv2/hrnetv2_w18_aflw_256x256-f2bbc62b_20210125.pth"
download_checkpoint(path, checkpoint, url)

       (4).根据配置文件和checkpoint文件构建模型:

config = "../../src/mmpose/configs/face/2d_kpt_sview_rgb_img/topdown_heatmap/aflw/hrnetv2_w18_aflw_256x256.py"
model = init_pose_model(config, path+checkpoint, device)

      (5).进行推理,输入包括之前的人脸检测框结果:

pose_results, returned_outputs = inference_top_down_pose_model(model, image, face_bbox_results, bbox_thr=None, format='xyxy')
# print(pose_results)

      (6).由推理输出画圆和框并保存结果图像:

# vis_pose_result(model, image, pose_results, radius=1, thickness=1, show=True, out_file="../../data/result_mmpose_2d_face_landmark.png")

mat = cv2.imread(image)
for result in pose_results:
    # print(f"bbox: {result['bbox']}, keypoints: {result['keypoints']}")
    cv2.rectangle(mat, (result['bbox'][0], result['bbox'][1]), (result['bbox'][2], result['bbox'][3]), (255, 0, 0), 1)

    for keypoints in result['keypoints']:
        cv2.circle(mat, (int(keypoints[0]), int(keypoints[1])), 1, (0, 0, 255), 1)

cv2.imwrite("../../data/result_mmpose_face_landmark.png", mat)
cv2.imshow("show", mat)
cv2.waitKey(0)

      demo命令行输出结果如下:

 

      GitHub: https://github.com/fengbingchun/PyTorch_Test

相关文章:

  • Java8中anyMatch()、allMatch()、noneMatch()用法详解
  • 【SpringMVC】SpringMVC实现转发和重定向
  • 离散化模板
  • 一种加权变异的粒子群算法-附代码
  • 带符号整数的除法与余数
  • Spring Cloud集成Dubbo实现RPC调用
  • 怎么开发自己的NFT平台
  • Android Context
  • 架构师的 36 项修炼第10讲:架构实战案例分析
  • 力扣每日一题-第63天-867. 转置矩阵
  • java基于ssm+vue的考研信息查询系统 elementui
  • 北大肖臻老师《区块链技术与应用》系列课程学习笔记[29]总结
  • C++设计模式之工厂模式(创建型模式)
  • 姿态分析开源工具箱MMPose使用示例:2d手势估计
  • MySQL分页查询
  • 【MySQL经典案例分析】 Waiting for table metadata lock
  • 【干货分享】SpringCloud微服务架构分布式组件如何共享session对象
  • 5、React组件事件详解
  • Angular Elements 及其运作原理
  • angular2 简述
  • co模块的前端实现
  • github从入门到放弃(1)
  • laravel with 查询列表限制条数
  • MySQL数据库运维之数据恢复
  • Mysql优化
  • quasar-framework cnodejs社区
  • 安装python包到指定虚拟环境
  • 程序员该如何有效的找工作?
  • 大数据与云计算学习:数据分析(二)
  • 工作手记之html2canvas使用概述
  • 职业生涯 一个六年开发经验的女程序员的心声。
  • No resource identifier found for attribute,RxJava之zip操作符
  • scrapy中间件源码分析及常用中间件大全
  • Spring第一个helloWorld
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • # Swust 12th acm 邀请赛# [ K ] 三角形判定 [题解]
  • #Linux(权限管理)
  • (2020)Java后端开发----(面试题和笔试题)
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (cos^2 X)的定积分,求积分 ∫sin^2(x) dx
  • (HAL)STM32F103C6T8——软件模拟I2C驱动0.96寸OLED屏幕
  • (阿里云万网)-域名注册购买实名流程
  • (原)本想说脏话,奈何已放下
  • (转)ABI是什么
  • (转)一些感悟
  • .bat批处理(五):遍历指定目录下资源文件并更新
  • .desktop 桌面快捷_Linux桌面环境那么多,这几款优秀的任你选
  • .NET CF命令行调试器MDbg入门(一)
  • .net程序集学习心得
  • /proc/stat文件详解(翻译)
  • @GlobalLock注解作用与原理解析
  • @WebServiceClient注解,wsdlLocation 可配置
  • @WebService和@WebMethod注解的用法
  • @德人合科技——天锐绿盾 | 图纸加密软件有哪些功能呢?
  • @四年级家长,这条香港优才计划+华侨生联考捷径,一定要看!