最近有人脸识别的项目需要预研,我就把paddle hub拿出来做一下试验。试用了几个模型,配置和使用大同小异,这里把pyramidbox整理出来。
官方链接
https://www.paddlepaddle.org.cn/modelbasedetail/pyramidbox
代码
import paddlehub as hub
import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
module = hub.Module(name="pyramidbox_face_detection")
test_img_path = "test2.jpg"
# set input dict
input_dict = {"image": [test_img_path]}
# execute predict and print the result
results = module.face_detection(data=input_dict)
image=cv2.imread(test_img_path)
for result in results[0]['data']:
#print(result)
top=int(image.shape[0]*float(result['top']))
bottom=int(image.shape[0]*float(result['bottom']))
left=int(image.shape[1]*float(result['left']))
right=int(image.shape[1]*float(result['right']))
image_cut=image[top:bottom,left:right]
image_cut=cv2.cvtColor(image_cut,cv2.COLOR_BGR2RGB)
#plt.figure(figsize=(10,10))
plt.imshow(image_cut)
plt.axis("off")
plt.show()
思考和问题
1)paddlehub的封装还不够,pyramidbox模型无法指定输出图片路径,不能通过api控制输出,相比较ultra_light_fast_generic_face_detector差一点
results = module.face_detection(data=input_dict,output_dir=’./output_ultra_light_fast_generic_face_detector_1mb_640/’,visualization=True)
2)从效果来讲,pyramidbox较好
‘confidence’: 0.3070993721485
‘confidence’: 0.151697039604187
感觉遮挡的,只要露出两个眼睛,就很好了,侧脸测试因为在合影场景不大可能实现,下一个场景再做测试。