Detection Model#

Description#

Detection model aims to detect objects in an image. The model outputs a list of detected objects, each containing a bounding box, score and class label.

OpenVINO Model Specifications#

Inputs#

A single input image of shape (H, W, 3) where H and W are the height and width of the image, respectively.

Outputs#

Detection model outputs a DetectionResult objects containing the following attributes:

  • boxes (np.ndarray) - Bounding boxes of the detected objects. Each in format of x1, y1, x2 y2.

  • scores (np.ndarray) - Confidence scores of the detected objects.

  • labels (np.ndarray) - Class labels of the detected objects.

  • label_names (list[str]) - List of class names of the detected objects.

Example#

import cv2
from model_api.models import SSD

# Load the model
model = SSD.create_model("model.xml")

# Forward pass
predictions = model(image)

# Iterate over detection result
for box, score, label, label_name in zip(
    predictions.boxes,
    predictions.scores,
    predictions.labels,
    predictions.label_names,
):
    print(f"Box: {box}, Score: {score}, Label: {label}, Label Name: {label_name}")
class model_api.models.detection_model.DetectionModel(inference_adapter, configuration={}, preload=False)#

Bases: ImageModel

An abstract wrapper for object detection model

The DetectionModel must have a single image input. It inherits preprocess from ImageModel wrapper. Also, it defines _resize_detections method, which should be used in postprocess, to clip bounding boxes and resize ones to original image shape.

The postprocess method must be implemented in a specific inherited wrapper.

Detection Model constructor

It extends the ImageModel construtor.

Parameters:
  • inference_adapter (InferenceAdapter) – allows working with the specified executor

  • configuration (dict, optional) – it contains values for parameters accepted by specific wrapper (confidence_threshold, labels etc.) which are set as data attributes

  • preload (bool, optional) – a flag whether the model is loaded to device while initialization. If preload=False, the model must be loaded via load method before inference

Raises:

WrapperError – if the model has more than 1 image inputs

classmethod parameters()#

Defines the description and type of configurable data parameters for the wrapper.

See types.py to find available types of the data parameter. For each parameter the type, default value and description must be provided.

The example of possible data parameter:
‘confidence_threshold’: NumericalValue(

default_value=0.5, description=”Threshold value for detection box confidence”

)

The method must be implemented in each specific inherited wrapper.

Returns:

  • the dictionary with defined wrapper data parameters