Skip to content

Kind instance_segmentation_prediction

Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object

Details

This kind represents single instance segmentation prediction in form of sv.Detections(...) object.

Example:

sv.Detections(
    xyxy=array([[        127,         189,         322,         303]]), 
    mask=array([
        [[False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        ...,
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False],
        [False, False, False, ..., False, False, False]]
    ]), 
    confidence=array([    0.95898]), 
    class_id=array([6]), 
    tracker_id=None, 
    data={
        'class_name': array(['G'], dtype='<U1'),
        'detection_id': array(['51dfa8d5-261c-4dcb-ab30-9aafe9b52379'], dtype='<U36'),
        'parent_id': array(['image.[0]'], dtype='<U9'),
        'image_dimensions': array([[425, 640]]),
        'inference_id': array(['51dfa8d5-261c-4dcb-ab30-9aafe9b52379'], dtype='<U36'),
        'prediction_type': array(['instance-segmentation'], dtype='<U16'),
        'root_parent_id': array(['image.[0]'], dtype='<U9'),
        'root_parent_coordinates': array([[0, 0]]),
        'root_parent_dimensions': array([[425, 640]]),
        'parent_coordinates': array([[0, 0]]),
        'parent_dimensions': array([[425, 640]]),
        'scaling_relative_to_parent': array([1]),
        'scaling_relative_to_root_parent': array([1]),
    }
)

As you can see, we have extended the standard set of metadata for predictions maintained by supervision. Adding this metadata is needed to ensure compatibility with blocks from roboflow_core plugin.

The design of metadata is suboptimal (as metadata regarding whole image is duplicated across all bounding boxes and there is no way on how to save metadata for empty predictions). We have GH issue to communicate around this problem.

Details of additional fields:

  • detection_id - unique identifier for each detection, to be used for when dependent elements are created based on specific detection (example: Dynamic Crop takes this value as parent id for new image)

  • parent_id - identifier of image that generated prediction (to be fetched from WorkflowImageData object)

  • image_dimensions - dimensions of image that was basis for prediction - format: (height, width)

  • inference_id - identifier of inference request (optional, relevant for Roboflow models)

  • prediction_type - type of prediction

  • root_parent_id - identifier of primary Workflow input that was responsible for downstream prediction (to be fetched from WorkflowImageData object) - usually identifier of Workflow input placeholder

  • root_parent_coordinates - offset regarding origin input - format (offset_x, offset_y)

  • root_parent_dimensions - dimensions of origin input image (height, width)

  • parent_coordinates - offset regarding parent - format (offset_x, offset_y)

  • parent_dimensions - dimensions of parent image (height, width)

  • scaling_relative_to_parent - scaling factor regarding parent image

  • scaling_relative_to_root_parent - scaling factor regarding origin input image

SERIALISATION:

Execution Engine behind API will serialise underlying data once selector of this kind is declared as Workflow output - serialisation will be executed such that sv.Detections.from_inference(...) can decode the output. Entity details: InstanceSegmentationInferenceResponse