微信公眾號:OpenCV學(xué)堂
關(guān)注獲取更多計算機視覺與深度學(xué)習(xí)知識
OpenVINO中提供了八個人臉檢測的相關(guān)模型,其中有兩個與剩余的六個是基于不同的對象檢測頭實現(xiàn)。今天這里就重點介紹一下這兩個與眾不同的人臉檢測預(yù)訓(xùn)練模型的使用。
模型說明
這兩個預(yù)訓(xùn)練模型名稱分別是:
face-detection-0205face-detection-0206
這兩個模型的檢測頭分別是基于FCOS與ATSS實現(xiàn)的,其中FOCS的檢測頭輸出如下:

兩個模型輸入圖象格式分別是:
face-detection-0205 NCHW=1x3x416x416face-detection-0206 NCHW=1x3x640x640
輸出格式:
BGR順序兩個輸出層分別是Boxes表示檢測框label表示對象
Boxes的數(shù)據(jù)格式為Nx5,其中N表示數(shù)目,5表示數(shù)據(jù)如下:
[`x_min`, `y_min`, `x_max`, `y_max`, `conf`]- (`x_min`, `y_min`) – 檢測框左上角坐標- (`x_max`, `y_max`) – 檢測框右下角坐標- `conf` - 置信度
預(yù)測出來的坐標值是基于輸入圖象大小的實際坐標值,conf值在0~1之間。
用法演示
演示如何使用OpenVINO中的FCOS與ATSS人臉檢測模型!
import cv2 as cv
import time
from openvino.inference_engine import IECore
ie = IECore()
for device in ie.available_devices:
print(device)
# Read IR
net = ie.read_network(model=face_xml, weights=face_bin)
input_blob = next(iter(net.input_info))
out_blob = next(iter(net.outputs))
# 輸入設(shè)置
n, c, h, w = net.input_info[input_blob].input_data.shape
# 設(shè)備關(guān)聯(lián)推理創(chuàng)建
exec_net = ie.load_network(network=net, device_name="CPU")
cap = cv.VideoCapture("D:/images/video/Boogie_Up.mp4")
while True:
inf_start = time.time()
ret, src = cap.read()
if ret is not True:
break
# 處理輸入圖象
image = cv.resize(src, (w, h))
image = image.transpose(2, 0, 1)
# 推理
prob = exec_net.infer(inputs={input_blob: [image]})
# 后處理
ih, iw, ic = src.shape
res = prob["boxes"]
for obj in res:
if obj[4] > 0.5:
xmin = int(obj[0] * iw / w)
ymin = int(obj[1] * ih / h)
xmax = int(obj[2] * iw / w)
ymax = int(obj[3] * ih / h)
cv.rectangle(src, (xmin, ymin), (xmax, ymax), (0, 255, 255), 2, 8)
cv.putText(src, str("%.3f" % obj[4]), (xmin, ymin), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1, 8)
inf_end = time.time() - inf_start
cv.putText(src, "infer time(ms): %.3f, FPS: %.2f" % (inf_end * 1000, 1 / (inf_end + 0.0001)), (10, 50),
cv.FONT_HERSHEY_SIMPLEX, 1.0, (255, 0, 255), 2, 8)
cv.imshow("face_detect", src)
c = cv.waitKey(1)
if c == 27: # ESC
break
cv.destroyAllWindows()運行結(jié)果如下:

i7CPU跑出這個速度還不錯!
掃碼查看CV系統(tǒng)化學(xué)習(xí)路線圖

推薦閱讀
CV全棧開發(fā)者說 - 從傳統(tǒng)算法到深度學(xué)習(xí)怎么修煉
Pytorch輕松實現(xiàn)經(jīng)典視覺任務(wù)
教程推薦 | Pytorch框架CV開發(fā)-從入門到實戰(zhàn)
OpenCV4 C++學(xué)習(xí) 必備基礎(chǔ)語法知識三
OpenCV4 C++學(xué)習(xí) 必備基礎(chǔ)語法知識二
OpenCV4.5.4 人臉檢測+五點landmark新功能測試
OpenCV4.5.4人臉識別詳解與代碼演示
