当前位置:网站首页>Code demonstration of fcos face detection model in openvino

Code demonstration of fcos face detection model in openvino

2022-07-19 03:03:00 Xiaobai learns vision

Click on the above “ Xiaobai studies vision ”, Optional plus " Star standard " or “ Roof placement

 Heavy dry goods , First time delivery 

Model input and output

OpenVINO 2020R04 There are two face detection models labeled :

  • face-detection-0105 – MobileNetv2 + FCOS

  • face-detection-0106 – RestNet152 + ATSS

There's a little bit of caution here ,FCOS And ATSS Model detection head output follows SSD Different models , Officially supported IR The file has two output data, which are :

  • boxes: [Nx5],

  • labels:[N]

among N Indicates the number of prediction frames obtained ,5 Represents the coordinates of the upper left and lower right corners of the prediction box , Plus the classification score -5 Elements are :

[x_min, y_min, x_max, y_max, conf]

Here is the special note , Follow SSD And FasterRCNN The object detection network is different , It outputs real coordinate information based on the size of the input image , No 0~1 Between the value of the . The input format is :NCHW=[1xNxHxW], Image channel sequence BGR.

Download these two models , Just execute the following script statement :

9493c4ba53ce3b40f555b76f789912e1.png

You can complete the download !

Code demonstration

The code implementation is based on OpenVINO Python SDK, With FCOS For example ! First load the model , The code is as follows :

1from __future__ import print_function
 2import cv2
 3import time
 4import logging as log
 5from openvino.inference_engine import IECore
 6
 7model_xml = "D:/projects/models/face-detection-0105/FP32/face-detection-0105.xml"
 8model_bin = "D:/projects/models/face-detection-0105/FP32/face-detection-0105.bin"
 9
10log.info("Creating Inference Engine")
11ie = IECore()
12# Read IR
13net = ie.read_network(model=model_xml, weights=model_bin)

Get input and output formatting information

1log.info("Preparing input blobs")
 2input_it = iter(net.input_info)
 3input_blob = next(input_it)
 4print(input_blob)
 5output_it = iter(net.outputs)
 6out_labels = next(output_it)
 7out_boxes = next(output_it)
 8
 9# Read and pre-process input images
10print(net.input_info[input_blob].input_data.shape)

Convert the input data into NCHW Format

1image = cv2.imread("D:/images/selfie.jpg")
 2ih, iw, ic = image.shape
 3rh = ih / 416
 4rw = iw / 416
 5print("rate of height:",rh, "rate of widht:",rw)
 6image_blob = cv2.resize(image, (416, 416))
 7image_blob = image_blob.transpose(2, 0, 1)  # Change data layout from HWC to CHW
 8
 9# Loading model to the plugin
10exec_net = ie.load_network(network=net, device_name="CPU")

To carry out reasoning

1# Start sync inference
2log.info("Starting inference in synchronous mode")
3inf_start1 = time.time()
4res = exec_net.infer(inputs={input_blob:[image_blob]})
5inf_end1 = time.time() - inf_start1
6print("inference time(ms) : %.3f" % (inf_end1 * 1000))

Analytic output

1# Processing output blob
 2log.info("Processing output blob")
 3res = res[out_boxes]
 4face_cnt = 0
 5for obj in res:
 6    if float(obj[4]) > 0.25:
 7        print(obj)
 8        face_cnt += 1
 9        xmin = int(obj[0]*rw)
10        ymin = int(obj[1]*rh)
11        xmax = int(obj[2]*rw)
12        ymax = int(obj[3]*rh)
13        cv2.rectangle(image, (xmin, ymin), (xmax, ymax), (0, 0, 255), 2, 8, 0)
14cv2.putText(image, "Total Detected Face: %d"%face_cnt, (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 255), 2)
15cv2.imshow("FOCS Face detection", image)
16print("total faces : ", face_cnt)
17cv2.imwrite("D:/result_fcos.png", image)
18cv2.waitKey(0)
19cv2.destroyAllWindows()

The running screenshot is as follows :

4b70c5404038280f81dbc7345a7a22c0.png

The good news !

Xiaobai learns visual knowledge about the planet

Open to the outside world

7bbde77c22ea8a2d9c87644e805297f7.jpeg

 download 1:OpenCV-Contrib Chinese version of extension module 

 stay 「 Xiaobai studies vision 」 Official account back office reply : Extension module Chinese course , You can download the first copy of the whole network OpenCV Extension module tutorial Chinese version , Cover expansion module installation 、SFM Algorithm 、 Stereo vision 、 Target tracking 、 Biological vision 、 Super resolution processing and other more than 20 chapters .


 download 2:Python Visual combat project 52 speak 
 stay 「 Xiaobai studies vision 」 Official account back office reply :Python Visual combat project , You can download, including image segmentation 、 Mask detection 、 Lane line detection 、 Vehicle count 、 Add Eyeliner 、 License plate recognition 、 Character recognition 、 Emotional tests 、 Text content extraction 、 Face recognition, etc 31 A visual combat project , Help fast school computer vision .


 download 3:OpenCV Actual project 20 speak 
 stay 「 Xiaobai studies vision 」 Official account back office reply :OpenCV Actual project 20 speak , You can download the 20 Based on OpenCV Realization 20 A real project , Realization OpenCV Learn advanced .


 Communication group 

 Welcome to join the official account reader group to communicate with your colleagues , There are SLAM、 3 d visual 、 sensor 、 Autopilot 、 Computational photography 、 testing 、 Division 、 distinguish 、 Medical imaging 、GAN、 Wechat groups such as algorithm competition ( It will be subdivided gradually in the future ), Please scan the following micro signal clustering , remarks :” nickname + School / company + Research direction “, for example :” Zhang San  +  Shanghai Jiaotong University  +  Vision SLAM“. Please note... According to the format , Otherwise, it will not pass . After successful addition, they will be invited to relevant wechat groups according to the research direction . Please do not send ads in the group , Or you'll be invited out , Thanks for your understanding ~
原网站

版权声明
本文为[Xiaobai learns vision]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207170013315825.html