PaddleHub教程合集---(3)PaddleHub人脸检测示例

PaddleHub教程合集—(3)PaddleHub人脸检测示例

本示例利用Ultra-Light-Fast-Generic-Face-Detector-1MB模型完成人脸检测。
该模型是针对边缘计算设备或低算力设备(如用ARM推理)设计的实时超轻量级通用人脸检测模型,可以在低算力设备中如用ARM进行实时的通用场景的人脸检测推理。

一、定义待预测数据

#NOTE: 如果您在本地运行该项目示例,需要首先安装PaddleHub。如果您在线(AISTUDIO)运行,需要首先fork该项目示例。
!pip install paddlehub==1.6.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
# 待预测图片
%matplotlib INLINE 
test_img_path = ["./test_face_detection.jpg"] #根据路径找到该图片

import matplotlib.pyplot as plt 
import matplotlib.image as mpimg 
img = mpimg.imread(test_img_path[0]) 
# 展示待预测图片
plt.figure(figsize=(10,10))
plt.imshow(img) 
plt.axis('off')  #是否显示坐标轴刻度
plt.show()

!cat test.txt
with open('test.txt', 'r') as f:
    test_img_path=[]
    for line in f:
        test_img_path.append(line.strip())
print(test_img_path)

二、加载预训练模型+三、预测

Ultra-Light-Fast-Generic-Face-Detector-1MB提供了两种预训练模型

  1. ultra_light_fast_generic_face_detector_1mb_320
    在预测时会将图片输入缩放为320 * 240,预测速度更快
  2. ultra_light_fast_generic_face_detector_1mb_640
    在预测时会将图片输入缩放为640 * 480,预测精度更高
    用PaddleHub使用该模型时,只需更改指定name,即可实现无缝切换
import paddlehub as hub
module = hub.Module(name="ultra_light_fast_generic_face_detector_1mb_640")
# module = hub.Module(name="ultra_light_fast_generic_face_detector_1mb_320")

#
input_dict = {"image": test_img_path}
# execute predict and print the result
results = module.face_detection(data=input_dict, visualization=True)
for result in results:
    print(result)
    
# 预测结果展示
img = mpimg.imread("face_detector_640_predict_output/test_face_detection.jpg")
plt.figure(figsize=(10,10))
plt.imshow(img) 
plt.axis('off') 
plt.show()

四、总结

PaddleHub用Ultra-Light-Fast-Generic-Face-Detector-1MB完成对该文件的人脸检测

  1. 读入该文件—将文件内容存成list (list中每个元素是待预测图片的存放路径)
  2. 导包paddlehub选模型 module=
    paddlehub.Module(name=“ultra_light_fast_generic_face_detector_1mb_640”)或者paddlehub.Module(name=“ultra_light_fast_generic_face_detector_1mb_320”)
  3. 列表数据转成字典input_dict = {“image”: test_img_path}
  4. 结果results = module.face_detection(data=input_dict, visualization=True)
  5. 图片结果展示
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-KWOK-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值