InstanceSegmentation

class InstanceSegmentationPrediction(box, mask, confidence, label, index)

A single prediction from InstanceSegmentation.

property label

The label describing this prediction result.

Type

string

property index

The index of this result in the master label list.

Type

integer

property mask

The mask of this detected instance of the object.

Type

numpy array

property box

The bounding box around the object.

Type

BoundingBox

property confidence

The confidence of this prediction.

Type

float

class InstanceSegmentationResults(predictions, duration, image, **kwargs)

All the results of instance segmentation from :class: InstanceSegmentation.

Predictions are stored in sorted order, with descending order of confidence.

property duration

The duration of the inference in seconds.

Type

float

property predictions

The list of predictions.

Type

list of InstanceSegmentationPrediction

property image

The image the results were processed on.

Image is not available when results are obtained from EyeCloud Cameras.

Type

numpy array – The image in BGR format

class InstanceSegmentation(model_id)

Detect, segment and classify individual objects in an image.

Typical usage:

instance_segmentation = edgeiq.InstanceSegmentation(
        'alwaysai/mask_rcnn')
instance_segmentation.load(engine=edgeiq.Engine.DNN)

<get image>
results = instance_segmentation.segment_image(image, confidence_level=.5)
image = instance_segmentation.markup_image(
        image, results.predictions)

for prediction in results.predictions:
        text.append("{}: {:2.2f}%".format(
            prediction.label, prediction.confidence * 100))
Parameters

model_id (string) – The ID of the model you want to use for instance segmentation.

property accelerator

The accelerator being used.

Return type

Optional[Accelerator]

property colors

The auto-generated colors for the loaded model.

Note: Initialized to None when the model doesn’t have any labels. Note: To update, the new colors list must be same length as the label list.

Return type

List[Tuple[int, int, int]]

property engine

The engine being used.

Return type

Optional[Engine]

property labels

The labels for the loaded model.

Note: Initialized to None when the model doesn’t have any labels.

Return type

List[str]

load(engine=<Engine.DNN: 'DNN'>, accelerator=<Accelerator.DEFAULT: 'DEFAULT'>)

Load the model to an engine and accelerator.

Parameters
  • engine (Engine) – The engine to load the model to

  • accelerator (Accelerator) – The accelerator to load the model to

property model_config

The configuration of the model that was loaded

Return type

ModelConfig

property model_id

The ID of the loaded model.

Return type

str

property model_purpose

The purpose of the model being used.

Return type

str

segment_image(image, confidence_level=0.3)

Detect, segment and classify individual objects in an image.

Parameters

image (numpy array of image) – The image to analyze.

Returns

InstanceSegmentationResults

markup_image(image, predictions, mask_threshold=0.3, show_labels=True, show_confidences=True, show_masks=True, colors=None, line_thickness=2, font_size=0.5, font_thickness=2)

Draw boxes, masks, labels, and confidences on the specified image.

Parameters
  • image (numpy array of image in BGR format) – The image to draw on.

  • predictions (list of InstanceSegmentationPrediction) – The list of prediction results.

  • mask_threshold (float) – Confidence threshold for displaying masks of detected objects.

  • show_labels (boolean) – Indicates whether to show the label of the prediction.

  • show_confidences (boolean) – Indicates whether to show the confidences of the prediction.

  • show_masks (boolean) – Indicates whether to show the masks of the prediction.

  • colors (list of tuples in the format (B, G, R)) – A custom color list to use for the bounding boxes. The index of the color will be matched with a label index.

  • line_thickness (float) – The thickness of the lines that make up the bounding box.

  • font_size (float) – The scale factor for the text.

  • font_thickness (float) – The thickness of the lines used to draw the text.

Returns

numpy array – The marked-up image.