PaddleHub能够便捷地获取PaddlePaddle生态下的预训练模型,完成模型的管理和一键预测。配合使用Fine-tune API,能够基于大规模预训练模型快速完成迁移学习,让预训练模型能更好地服务于用户特定场景的应用。学习
本次介绍如何使用paddlehub实现人脸检测。设计
模型概述blog
Ultra-Light-Fast-Generic-Face-Detector-1MB是针对边缘计算设备或低算力设备(如用ARM推理)设计的实时超轻量级通用人脸检测模型,能够在低算力设备中如用ARM进行实时的通用场景的人脸检测推理。该PaddleHub Module的预训练数据集为WIDER FACE数据集,可支持预测,在预测时会将图片输入缩放为640 * 480。图片
代码以下:input
import matplotlib.pyplot as pltio
import matplotlib.image as mpimgast
import paddlehub as hubtest
module = hub.Module(name="ultra_light_fast_generic_face_detector_1mb_640")import
# 待预测图片module
test_img_path = ["./crowd1.jpg"]
img = mpimg.imread(test_img_path[0])
# 展现待预测图片
plt.imshow(img)
plt.axis('off')
plt.show()
input_dict = {"image": test_img_path}
# execute predict and print the result
results = module.face_detection(data=input_dict)
for result in results:
print(result)
# 预测结果展现
img = mpimg.imread("./face_detector_640_predict_output/crowd1.jpg")
plt.imshow(img)
plt.axis('off')
plt.show()
效果: