Skip to content

frameworks.ultralytics.services.model.predictor.classification

classification

Classes:

Name Description
UltralyticsClassificationModelPredictor

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

UltralyticsClassificationModelPredictor(model)

Bases: ModelPredictor[UltralyticsModel]

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

This class performs pre-processing of datasets, runs inference on batches of images, and post-processes the predictions to generate PicselliaClassificationPrediction objects for classification tasks.

Parameters:

Name Type Description Default

model

UltralyticsModel

The context containing the loaded model and its configurations.

required

Methods:

Name Description
pre_process_dataset

Prepares the dataset by extracting and returning a list of image file paths from the dataset directory.

run_inference_on_batches

Runs inference on each batch of images using the model.

post_process_batches

Post-processes all inference results by matching predictions with assets.

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

pre_process_dataset(dataset)

Prepares the dataset by extracting and returning a list of image file paths from the dataset directory.

Parameters:

Name Type Description Default
dataset
TBaseDataset

The dataset containing image directories structured by class.

required

Returns:

Type Description
list[str]

list[str]: A list of full image file paths.

run_inference_on_batches(image_batches)

Runs inference on each batch of images using the model.

Parameters:

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

Batches of image paths.

required

Returns:

Type Description
list[Results]

list[Results]: A list of inference result objects, one per batch.

post_process_batches(image_batches, batch_results, dataset)

Post-processes all inference results by matching predictions with assets.

Parameters:

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

List of image batches.

required
batch_results
list[Results]

Corresponding model outputs for each batch.

required
dataset
TBaseDataset

Dataset used to resolve label references.

required

Returns:

Type Description
list[PicselliaClassificationPrediction]

list[PicselliaClassificationPrediction]: Formatted predictions.

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.