Skip to content

frameworks.ultralytics.services.model.logger.classification

classification

Classes:

Name Description
UltralyticsClassificationMetricMapping

Defines the metric mapping for classification tasks in the Ultralytics framework.

UltralyticsClassificationLogger

Logger for Ultralytics-based classification models.

UltralyticsClassificationMetricMapping()

Bases: UltralyticsBaseMetricMapping

Defines the metric mapping for classification tasks in the Ultralytics framework.

This class extends the base Ultralytics metric mapping and adds classification-specific metrics such as top-1 and top-5 accuracy and loss for both training and validation phases.

Registers classification metrics including loss, top-1 accuracy, and top-5 accuracy for both training and validation.

Methods:

Name Description
add_metric

Add a metric to the specified phase.

get_mapping

Get mapping of framework names to standard names for a given phase.

Attributes:

Name Type Description
mappings dict[str, list[Metric]]

mappings = {'train': [], 'val': [], 'test': []} instance-attribute

add_metric(phase, metric)

Add a metric to the specified phase.

Parameters:

Name Type Description Default
phase
str

One of 'train', 'val', or 'test'.

required
metric
Metric

The metric to register.

required

get_mapping(phase=None)

Get mapping of framework names to standard names for a given phase.

Parameters:

Name Type Description Default
phase
str | None

One of 'train', 'val', 'test'.

None

Returns:

Name Type Description
dict dict[str, str]

Mapping of metric names.

UltralyticsClassificationLogger(experiment, metric_mapping)

Bases: BaseLogger

Logger for Ultralytics-based classification models.

This class is responsible for logging classification-related metrics during training and validation, using an Ultralytics-compatible metric mapping.

Parameters:

Name Type Description Default

experiment

Experiment

The experiment object used for logging.

required

metric_mapping

ClassificationMetricMapping

The metric mapping used to normalize metric names.

required

Methods:

Name Description
log_metric

Log a metric value (e.g. for line plot).

log_value

Log a scalar value (e.g., accuracy score).

log_image

Log an image file.

log_confusion_matrix

Log a confusion matrix as a heatmap.

log_table

Log a table (either a key-value dict or 2D matrix).

get_log_name

Construct log name with optional phase and mapped name.

Attributes:

Name Type Description
experiment
metric_mapping

experiment = experiment instance-attribute

metric_mapping = metric_mapping instance-attribute

log_metric(name, value, log_type=LogType.LINE, phase=None)

Log a metric value (e.g. for line plot).

Parameters:

Name Type Description Default
name
str

Metric name.

required
value
float

Metric value.

required
log_type
LogType

Logging type (default LINE).

LINE
phase
str | None

Phase name.

None

log_value(name, value, phase=None, precision=4)

Log a scalar value (e.g., accuracy score).

Parameters:

Name Type Description Default
name
str

Metric name.

required
value
float

Value to log.

required
phase
str | None

Phase name.

None
precision
int

Decimal precision to round.

4

log_image(name, image_path, phase=None)

Log an image file.

Parameters:

Name Type Description Default
name
str

Log name.

required
image_path
str

Path to image.

required
phase
str | None

Phase name.

None

log_confusion_matrix(name, labelmap, matrix, phase=None)

Log a confusion matrix as a heatmap.

Parameters:

Name Type Description Default
name
str

Log name.

required
labelmap
dict

Mapping of label indices to names.

required
matrix
ndarray

Confusion matrix.

required
phase
str | None

Phase name.

None

log_table(name, data, phase=None)

Log a table (either a key-value dict or 2D matrix).

Parameters:

Name Type Description Default
name
str

Log name.

required
data
dict

Data to log.

required
phase
str | None

Phase name.

None

get_log_name(metric_name, phase=None)

Construct log name with optional phase and mapped name.

Parameters:

Name Type Description Default
metric_name
str

Base metric name.

required
phase
str | None

Optional phase.

None

Returns:

Name Type Description
str str

Full log name.