Cityscapes#

class torch_uncertainty.datasets.segmentation.Cityscapes(root, split='train', mode='fine', target_type='instance', transform=None, target_transform=None, transforms=None)[source]#

Cityscapes dataset wrapper with train ID color mapping.

This class extends the TVCityscapes dataset to provide a fixed color palette for visualization and encode/decode utilities for semantic segmentation targets using Cityscapes train IDs. It also sets up mapping from train IDs to RGB colors for easier interpretation of predicted masks.

Variables:
  • color_palette (list[tuple[int, int, int]]) – List of RGB tuples for each class label in the Cityscapes dataset.

  • train_id_to_color (torch.Tensor) – Tensor mapping train IDs to RGB colors for output decoding.

Parameters:
  • root (str) – Root directory of the Cityscapes dataset.

  • split (str, optional) – Dataset split to use, such as “train”, “val”, or “test”.

  • mode (str, optional) – Annotation mode, e.g., “fine” or “coarse”.

  • target_type (list[str] | str, optional) – One or more target types to load (“instance”, “semantic”, etc.).

  • transform (Callable[..., Any] | None, optional) – Transformation applied to the input image.

  • target_transform (Callable[..., Any] | None, optional) – Transformation applied to the target.

  • transforms (Callable[..., Any] | None, optional) – Combined transformation for image and target.

decode_target(target)[source]#

Decode target tensor to RGB tensor.

Parameters:

target (torch.Tensor) – Target RGB tensor.

Returns:

Decoded target.

Return type:

Image.Image

classmethod encode_target(target)[source]#

Encode target image to tensor.

Parameters:

target (Image.Image) – Target PIL image.

Returns:

Encoded target.

Return type:

torch.Tensor

plot_sample(index, ax=None)[source]#

Plot a sample from the dataset.

Parameters:
  • index – The index of the sample to plot.

  • ax – Optional matplotlib axis to plot on.

Returns:

The axis on which the sample was plotted.