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 list of detection objects (i.e list[Detection]) wrapped in DetectionResult, each object containing the following attributes:

  • score (float) - Confidence score of the object.

  • id (int) - Class label of the object.

  • str_label (str) - String label of the object.

  • xmin (int) - X-coordinate of the top-left corner of the bounding box.

  • ymin (int) - Y-coordinate of the top-left corner of the bounding box.

  • xmax (int) - X-coordinate of the bottom-right corner of the bounding box.

  • ymax (int) - Y-coordinate of the bottom-right corner of the bounding box.

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 the segmented objects
for pred_obj in predictions.objects:
    pred_score = pred_obj.score
    label_id = pred_obj.id
    bbox = [pred_obj.xmin, pred_obj.ymin, pred_obj.xmax, pred_obj.ymax]
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