tlc.client.torch.metrics.metrics_collectors.segmentation_metrics_collector#

Collect metrics for segmentation problems.

Module Contents#

Classes#

Class

Description

SegmentationMetricsCollector

Collect predicted masks from model output.

Data#

Data

Description

PREDICTED_MASK_METRIC_NAME

API#

tlc.client.torch.metrics.metrics_collectors.segmentation_metrics_collector.PREDICTED_MASK_METRIC_NAME = predicted_mask#
class tlc.client.torch.metrics.metrics_collectors.segmentation_metrics_collector.SegmentationMetricsCollector(label_map: dict[int, str], preprocess_fn: Callable[[tlc.core.builtins.types.SampleData, tlc.client.torch.metrics.predictor.PredictorOutput], tuple[Any, Any]] | None = None)#

Bases: tlc.client.torch.metrics.metrics_collectors.metrics_collector_base.MetricsCollector

Collect predicted masks from model output.

Predicted masks are converted to PIL images, which can be written to the Run folder by a MetricsTableWriter.

Initialize the SegmentationMetricsCollector.

Parameters:
  • label_map – A dictionary mapping class ids to class labels.

  • preprocess_fn – A function that pre-processes the model output before computing metrics.

compute_metrics(batch: tlc.core.builtins.types.SampleData, predictor_output: tlc.client.torch.metrics.predictor.PredictorOutput) dict[str, tlc.core.builtins.types.MetricData]#

Convert predicted masks from model output to PIL images.

The result of preprocessing the model output is expected to be a list of tensors.

Parameters:
  • batch – The input batch (not used).

  • predictor_output – The output from the Predictor.

Returns:

A batch of metrics, where each metric is a PIL image corresponding to a mask.

preprocess(batch: tlc.core.builtins.types.SampleData, predictor_output: tlc.client.torch.metrics.predictor.PredictorOutput) tuple[tlc.core.builtins.types.SampleData, torch.Tensor]#

Default preprocessor for segmentation output.

By default just forwards the model predictions.

Parameters:
  • batch – A batch of samples.

  • predictor_output – A batch of predictions.

Returns:

A tuple containing the preprocessed batch and predictions.

tensor_to_pil_image(predicted_mask: torch.Tensor) PIL.Image.Image#
property column_schemas: dict[str, tlc.core.schema.Schema]#