Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6484 Discussions

use more than one images as input on openvino

lu__Lucas
Beginner
1,004 Views

In case input is one image,it do correctly.But I have many images,it detected slowly one by one.So I want to detected the face on batch.

I use pre-trained model face-detection-retail-0004, I set the batch_size in IENetwork, batch_size = images num

net = IENetwork(model=model, weights=weights) 
net.batch_size = batch_size

And response is not i expected.

my code to get detected boxes.

import cv2
import numpy as np


def detection(detection_network, inputs, threshold=0.5):
    input_blob = detection_network['input_blob']
    output_blob = detection_network['output_blob']
    input_num = detection_network['input_num']
    input_channel = detection_network['input_channel']
    input_height = detection_network['input_height']
    input_width = detection_network['input_width']
    exec_net = detection_network['exec_net']

    assert len(inputs) == input_num, f'Input length should {input_num}, but receive {len(inputs)}'
    resize_images = np.ndarray(shape=(input_num, input_channel, input_height, input_height))
    original_images = list()
    for i in range(input_num):
        image = cv2.imread(inputs)
        original_images.append(image)
        if image.shape[:-1] != (input_height, input_width):
            image = cv2.resize(image, (input_height, input_width))

        image = image.transpose((2, 0, 1))  # Change data layout from HWC to CHW
        resize_images = image

    # Start sync inference
    res = exec_net.infer(inputs={input_blob: resize_images})
    res = res[output_blob]

    # Parse detection results of the current request
    boxes = list()

    # for idx, input_item in enumerate(res):  # how many input
    #     for obj in input_item[0]:  # how many output for a input
    #         # for obj in output_item:
    #         if obj[2] > threshold:
    #             print(obj[0], obj[1], obj[2], obj[3], obj[4], obj[5], obj[6])
    #             initial_h, initial_w, _ = original_images[idx].shape
    #
    #             try:
    #                 xmin = int(obj[3] * initial_w)
    #                 ymin = int(obj[4] * initial_h)
    #                 xmax = int(obj[5] * initial_w)
    #                 ymax = int(obj[6] * initial_h)
    #             except ValueError:
    #                 continue
    #
    #             box = original_images[idx][xmin:xmax, ymin:ymax, :]
    #             boxes.append(box)
    for obj in res[0][0]:  # how many input
        # for obj in output_item:
        idx = int(obj[0])
        if obj[2] > threshold:
            print(obj[0], obj[1], obj[2], obj[3], obj[4], obj[5], obj[6])
            initial_h, initial_w, _ = original_images[idx].shape

            try:
                xmin = int(obj[3] * initial_w)
                ymin = int(obj[4] * initial_h)
                xmax = int(obj[5] * initial_w)
                ymax = int(obj[6] * initial_h)
            except ValueError:
                continue

            box = original_images[idx][xmin:xmax, ymin:ymax, :]
            boxes.append(box)

    return boxes

 

0 Kudos
0 Replies
Reply