Skip to content

frameworks.ultralytics.services.model.predictor.segmentation

segmentation

Classes:

Name Description
UltralyticsSegmentationModelPredictor

A predictor class that handles model inference and result post-processing for segmentation tasks

UltralyticsSegmentationModelPredictor(model)

Bases: ModelPredictor[UltralyticsModel]

A predictor class that handles model inference and result post-processing for segmentation tasks using the Ultralytics framework.

Parameters:

Name Type Description Default

model

UltralyticsModel

The model used to perform inference.

required

Methods:

Name Description
run_inference_on_batches

Runs inference on each batch of images.

post_process_batches

Converts raw predictions into PicselliaPolygonPrediction objects for each image.

format_predictions

Extracts and formats segmentation predictions into Picsellia types.

format_polygons

Converts a polygon array to a list of integer coordinates.

pre_process_dataset

Extracts all image paths from the dataset's image directory.

prepare_batches
get_picsellia_label

Get or create a PicselliaLabel from a dataset category name.

get_picsellia_confidence

Wrap a confidence score in a PicselliaConfidence object.

get_picsellia_rectangle

Create a PicselliaRectangle from bounding box coordinates.

Attributes:

Name Type Description
model TModel

model = model instance-attribute

run_inference_on_batches(image_batches)

Runs inference on each batch of images.

Parameters:

Name Type Description Default
image_batches
list[list[str]]

A list of image path batches.

required

Returns:

Type Description
list[Results]

list[Results]: The list of inference results for each batch.

post_process_batches(image_batches, batch_results, dataset)

Converts raw predictions into PicselliaPolygonPrediction objects for each image.

Parameters:

Name Type Description Default
image_batches
list[list[str]]

The original image path batches.

required
batch_results
list[Results]

The inference results for each batch.

required
dataset
TBaseDataset

Dataset used to retrieve asset metadata.

required

Returns:

Type Description
list[PicselliaPolygonPrediction]

list[PicselliaPolygonPrediction]: Structured predictions ready for evaluation/logging.

format_predictions(prediction, dataset)

Extracts and formats segmentation predictions into Picsellia types.

Parameters:

Name Type Description Default
prediction
Results

A single inference result containing segmentation masks.

required
dataset
TBaseDataset

Dataset used to resolve labels.

required

Returns:

Name Type Description
tuple tuple[list[PicselliaPolygon], list[PicselliaLabel], list[PicselliaConfidence]]

Lists of PicselliaPolygon, PicselliaLabel, and PicselliaConfidence.

format_polygons(polygon) staticmethod

Converts a polygon array to a list of integer coordinates.

Parameters:

Name Type Description Default
polygon
ndarray

Polygon mask as an array of coordinates.

required

Returns:

Type Description
list[list[int]]

list[list[int]]: Polygon represented as a list of integer point pairs.

pre_process_dataset(dataset)

Extracts all image paths from the dataset's image directory.

Parameters:

Name Type Description Default
dataset
TBaseDataset

The dataset object containing the image directory.

required

Returns:

Type Description
list[str]

list[str]: A list of file paths to the dataset images.

prepare_batches(image_paths, batch_size)

get_picsellia_label(category_name, dataset)

Get or create a PicselliaLabel from a dataset category name.

Parameters:

Name Type Description Default
category_name
str

The name of the label category.

required
dataset
TBaseDataset

Dataset that provides label access.

required

Returns:

Name Type Description
PicselliaLabel PicselliaLabel

Wrapped label object.

get_picsellia_confidence(confidence)

Wrap a confidence score in a PicselliaConfidence object.

Parameters:

Name Type Description Default
confidence
float

Prediction confidence score.

required

Returns:

Name Type Description
PicselliaConfidence PicselliaConfidence

Wrapped confidence object.

get_picsellia_rectangle(x, y, w, h)

Create a PicselliaRectangle from bounding box coordinates.

Parameters:

Name Type Description Default
x
int

Top-left x-coordinate.

required
y
int

Top-left y-coordinate.

required
w
int

Width of the box.

required
h
int

Height of the box.

required

Returns:

Name Type Description
PicselliaRectangle PicselliaRectangle

Rectangle wrapper for object detection.