tlc.data_types.semantic_segmentation¶

The semantic-segmentation domain type and its class-role surface.

A semantic segmentation is a dense (H, W) integer label map — an exhaustive partition of the image. The user-facing piece in this module is the SemanticSegmentation carrier (the read form and the optional explicit write wrapper).

Class roles are not expressed by building a special value map; they are plain background and void id keyword arguments on every public entry point — the column schema (tlc.schemas.SemanticSegmentationRleSchema), the table front door (tlc.Table.from_semantic_segmentation()), and the metrics helper (tlc.metrics.semantic_segmentation.semantic_segmentation_metrics()). The internal builders/readers below translate those ids into the persisted value map and back; callers never touch them.

The (de)serializer that converts between this type and the RLE wire format lives in tlc.sample_types.SemanticSegmentationSampleType.

Two classes carry meaning beyond “a label”. Background (the implicit/default fill) is not a class at all: it is omitted from the value map and the wire, and its id is recorded in the column schema’s metadata — consulted only at the (de)serialization boundary. Void (a.k.a. border / ignore — excluded from metrics, not a prediction target, GT-only) stays in the value map, tagged by a reserved internal_name constant rather than a new role field.

Module Contents¶

Classes¶

Class

Description

SemanticSegmentation

The semantic-segmentation carrier: a dense (H, W) integer label map.

Data¶

Data

Description

TLC_SEMSEG_VOID

API¶

class SemanticSegmentation¶

The semantic-segmentation carrier: a dense (H, W) integer label map.

This is a thin, public type with two jobs:

  • Read form — from_row() always returns one, so the sample view of a semseg column has a single, stable shape regardless of how the row was authored. Read .mask for the dense label map and .present_class_ids for the classes present.

  • Explicit write wrapper — you rarely need it on write. The write path is lenient (see accepts()): hand a bare (H, W) numpy array or a single-channel PIL.Image straight to a TableWriter, or use Table.from_semantic_segmentation(). Reach for this wrapper only to say something the bare array can’t — today that means pinning an explicit background_id.

mask is a (H, W) integer array where each pixel holds a class id; image_width and image_height are inferred from it when omitted.

background_id names the class treated as the implicit background — the “absence of a labeled object” canvas. It is a pure write-time instruction, never persisted. The background is omitted from the wire whenever it can be recovered on read: id 0 is always recovered by from_row()’s fill, and a background at any other id is recovered from the id recorded in the column schema’s metadata (the table read path binds that schema). Used standalone with no bound schema, only an id-0 background is recoverable, so a non-zero one is kept as an ordinary layer (never unusable). None keeps every present class, including any at id 0.

background_id: int | None = None¶
image_height: int | None = None¶
image_width: int | None = None¶
mask: ndarray = None¶
property present_class_ids: ndarray¶

Class ids actually present in the mask, sorted ascending.

TLC_SEMSEG_VOID = __tlc_semseg_void__¶