赞
踩
本项目通过AI Studio(基于百度深度学习平台飞桨的人工智能学习与实训社区,提供在线编程环境、免费GPU算力、海量开源算法和开放数据,帮助开发者快速创建和部署模型)运行。
感兴趣的小伙伴欢迎访问Fork:https://aistudio.baidu.com/aistudio/projectdetail/750941
随着拍照技术的进步,人们对照片的要求越来越高。慢慢的也出现了一些搞怪照片。本项目实现通过输入一张人像图片,输出该人像的黑板简笔画
主要技术就是人脸关键点检测。通过PaddleHub已经开源了的人脸关键点检测模型face_landmark_localization。人脸关键点检测是人脸识别和分析领域中的关键一步,它是诸如自动人脸识别、表情分析、三维人脸重建及三维动画等其它人脸相关问题的前提和突破口。该模型转换自 https://github.com/lsy17096535/face-landmark ,支持同一张图中的多个人脸检测。它可以识别人脸中的68个关键点。 本项目先通过PaddleHub已经开源了的人脸关键点检测模型获取人脸的关键点数据,再通过这些数据对图像进行加工,得到人脸黑板简笔画。
效果图:
PaddleHub是飞桨生态的预训练模型应用工具,开发者可以便捷地使用高质量的预训练模型结合Fine-tune API快速完成模型迁移到部署的全流程工作。PaddleHub提供的预训练模型涵盖了图像分类、目标检测、词法分析、语义模型、情感分析、视频分类、图像生成、图像分割、文本审核、关键点检测等主流模型。更多详情可查看PaddleHub官网:https://www.paddlepaddle.org.cn/hub
PaddleHub以预训练模型应用为核心具备以下特点:
1.模型即软件: 通过Python API或命令行实现模型调用,可快速体验或集成飞桨特色预训练模型。
2.易用的迁移学习: 通过Fine-tune API,内置多种优化策略,只需少量代码即可完成预训练模型的Fine-tuning。
3.一键模型转服务: 简单一行命令即可搭建属于自己的深度学习模型API服务完成部署。
4.自动超参优化: 内置AutoDL Finetuner能力,一键启动自动化超参搜索。
#第一步当然是先安装paddlehub
!pip install paddlehub==1.6.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
import cv2
import paddlehub as hub
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
import math
#读取图片
src_img = cv2.imread('./test_sample.jpg')
#加载paddlehub模型并通过API一键检测
module = hub.Module(name="face_landmark_localization")
result = module.keypoint_detection(images=[src_img])
print(result)
[{'data': [[[159.30455017089844, 161.5406951904297], [155.98448181152344, 184.37612915039062], [154.5143280029297, 208.08456420898438], [154.6251678466797, 230.1551513671875], [159.8415069580078, 251.63644409179688], [170.23049926757812, 269.10223388671875], [183.05865478515625, 284.2024230957031], [197.1408233642578, 297.01708984375], [212.1311798095703, 304.223876953125], [230.02288818359375, 304.36151123046875], [245.18296813964844, 294.80810546875], [261.17095947265625, 285.1965637207031], [275.7255859375, 272.9986572265625], [285.30010986328125, 255.3640899658203], [292.5657958984375, 237.26429748535156], [299.53167724609375, 218.2264404296875], [303.8143005371094, 197.93377685546875], [177.11863708496094, 159.6382598876953], [189.80667114257812, 152.68289184570312], [204.3644256591797, 153.25462341308594], [218.6627197265625, 159.93360900878906], [231.54922485351562, 168.79400634765625], [255.30337524414062, 174.5740966796875], [267.5892028808594, 172.73550415039062], [279.8527526855469, 172.29034423828125], [291.8857727050781, 177.07102966308594], [299.7391357421875, 186.96981811523438], [239.76458740234375, 188.27572631835938], [237.51950073242188, 203.3531494140625], [234.79452514648438, 217.11427307128906], [232.12869262695312, 232.10086059570312], [215.5321044921875, 234.42172241210938], [222.65936279296875, 239.46875], [229.46038818359375, 243.06199645996094], [236.44935607910156, 242.30455017089844], [243.56353759765625, 241.25534057617188], [191.2951202392578, 176.21156311035156], [201.5207061767578, 174.5267333984375], [212.24559020996094, 178.12451171875], [218.42420959472656, 187.4755401611328], [208.8699951171875, 186.71749877929688], [198.7803192138672, 182.7091064453125], [256.23101806640625, 195.60311889648438], [264.25201416015625, 189.57211303710938], [274.8070373535156, 192.18829345703125], [282.6427307128906, 197.03915405273438], [274.24908447265625, 199.92636108398438], [264.8431091308594, 199.5250244140625], [196.40475463867188, 249.4647216796875], [208.2581329345703, 250.83792114257812], [219.4830322265625, 251.86813354492188], [226.86839294433594, 255.59494018554688], [233.02976989746094, 254.90525817871094], [241.833251953125, 258.72412109375], [250.73390197753906, 262.96441650390625], [239.21388244628906, 270.27239990234375], [229.06674194335938, 274.18896484375], [222.30227661132812, 272.7212219238281], [215.35842895507812, 270.05859375], [205.86260986328125, 263.66827392578125], [200.25833129882812, 251.47845458984375], [218.50205993652344, 259.7375183105469], [224.91644287109375, 262.54290771484375], [231.9678955078125, 261.9854736328125], [245.7952880859375, 262.9068603515625], [230.69363403320312, 263.18017578125], [224.8975830078125, 263.0137939453125], [217.20870971679688, 260.4953918457031]]]}]
# 展示预测68个关键点结果
tmp_img = src_img.copy()
for index, point in enumerate(result[0]['data'][0]):
cv2.circle(tmp_img, (int(point[0]), int(point[1])), 2, (0, 0, 255), -1)
res_img_path = 'face_landmark.jpg'
cv2.imwrite(res_img_path, tmp_img)
img = mpimg.imread(res_img_path)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis('off')
plt.show()
# 展示预测17个关键点结果,可以看到前17个点显示了脸部轮廓
tmp_img = src_img.copy()
for index, point in enumerate(result[0]['data'][0]):
if(index < 17) :
cv2.circle(tmp_img, (int(point[0]), int(point[1])), 2, (0, 0, 255), -1)
res_img_path = 'face_landmark.jpg'
cv2.imwrite(res_img_path, tmp_img)
img = mpimg.imread(res_img_path)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.axis
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。