Datasets

Every dataset takes the dataset root and a split and discovers its scenarios internally. Datasets built from the same root/split (and clip_len/stride) align index-for-index: dataset_a[i] and dataset_b[i] refer to the same scenario and timestep window. Every dataset returns a time dimension T even when clip_len=1.

Camera

class carlanomaly.datasets.RGBDataset(root=None, split='train', direction='front', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: AtomicDataset

Per-timestep RGB images from a single camera.

Returns a FloatTensor (T, 3, H, W) in [0, 1].

With download=True the required archive parts are fetched into root (front lives in base; other directions add camera-extended). Remaining keyword arguments (clip_len, stride, parts, …) are forwarded to ScenarioIndex.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • direction (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

modality: ClassVar[str | None] = 'rgb'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.SegmentationDataset(root=None, split='train', direction='front', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: AtomicDataset

Per-timestep instance segmentation masks from a single camera.

Returns a dict with:
'semantic': LongTensor (T, H, W) of CARLA class ids (1-28,

non-contiguous).

'instance': LongTensor (T, H, W) of instance ids

(green * 256 + blue channel of the RGBA mask).

With download=True the required archive parts are fetched into root (front lives in base; other directions add camera-extended). Remaining keyword arguments (clip_len, stride, parts, …) are forwarded to ScenarioIndex.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • direction (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

modality: ClassVar[str | None] = 'segmentation'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Dict[str, Tensor]

Parameters:

idx (int)

class carlanomaly.datasets.DepthDataset(root=None, split='train', direction='front', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: AtomicDataset

Per-timestep log-encoded depth maps from a single camera.

Returns a FloatTensor (T, 1, H, W) in [0, 1] (uint8 / 255).

Depth maps live in the depth part; with download=True it (plus the base part) is fetched into root. Remaining keyword arguments (clip_len, stride, parts, …) are forwarded to ScenarioIndex.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • direction (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

modality: ClassVar[str | None] = 'depth'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

LiDAR

class carlanomaly.datasets.PointCloudDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep LiDAR point clouds.

Returns a List[pd.DataFrame] of length T. Each DataFrame has columns: x, y, z, cos_inc_angle, object_id, object_tag.

With download=True the lidar part (plus base) is fetched into root.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'pointcloud'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

List[DataFrame]

Parameters:

idx (int)

Anomaly labels

Ground-truth labels for every evaluation level: per-pixel masks and per-point labels (sample level), per-sensor-reading labels (sensor level), per-timestep labels (timestep level), and per-scenario labels (scenario level). The evaluators load these labels themselves; these datasets exist for inspection, visualisation, and custom evaluation.

class carlanomaly.datasets.AnomalySegmentationDataset(root=None, split='train', direction='front', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: AtomicDataset

Per-timestep pixel-level anomaly masks from a single camera.

Returns a BoolTensor (T, H, W). For the train split (where no anomaly masks exist), returns all-False tensors.

With download=True the required archive parts are fetched into root (front lives in base; other directions add camera-extended). Remaining keyword arguments (clip_len, stride, parts, …) are forwarded to ScenarioIndex.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • direction (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

modality: ClassVar[str | None] = 'anomaly_seg'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.AnomalyLiDARDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep, per-point LiDAR anomaly labels.

Returns a List[BoolTensor] of length T. Each tensor has shape (N_points,) matching the corresponding point cloud. For the train split, returns all-False tensors sized to match the actual point cloud.

With download=True the lidar part (plus base) is fetched into root.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'anomaly_lidar'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

List[Tensor]

Parameters:

idx (int)

class carlanomaly.datasets.AnomalySensorDataset(*args, sensor='front', **kwargs)[source]

Bases: AtomicDataset

Sensor-level anomaly labels for one sensor (one label per timestep).

Returns a BoolTensor (T,) marking whether the anomaly is visible in this specific sensor at each timestep. Labels are stored on disk as anomaly-{sensor}/sensor.feather. For the train split (where no label file exists), returns all-False.

Parameters:

sensor – Any sensor name ("front", "left", "right", "rear", "lidar").

Parameters:
  • args (Any)

  • sensor (str)

  • kwargs (Any)

modality: ClassVar[str | None] = 'anomaly_sensor'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.AnomalyTimestepDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Timestep-level anomaly labels (one label per timestep).

Returns a BoolTensor (T,). Labels are stored on disk as anomaly-observation.feather. For the train split (where no label file exists), returns all-False.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'anomaly_timestep'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.AnomalyScenarioDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Scenario-level anomaly labels (one label per scenario).

Returns a scalar BoolTensor: True iff the item’s scenario is an anomaly scenario. The label is derived from the scenario’s location in the dataset layout (test/anomaly/ vs test/normal/); no label file is read. Unlike the per-timestep datasets, the returned tensor has no time dimension: the label applies to the scenario as a whole.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'anomaly_scenario'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

Tabular

class carlanomaly.datasets.WeatherDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep weather parameters.

Returns a FloatTensor (T, 14) with columns: cloudiness, precipitation, sun_altitude_angle, sun_azimuth_angle, fog_density, fog_distance, fog_falloff, precipitation_deposits, wind_intensity, wetness, scattering_intensity, mie_scattering_scale, rayleigh_scattering_scale, dust_storm.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'weather'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.GNSSDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep GNSS position.

Returns a FloatTensor (T, 3) with columns: altitude, latitude, longitude.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'gnss'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.IMUDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep inertial measurement unit readings.

Returns a FloatTensor (T, 7) with columns: acceleration_x, acceleration_y, acceleration_z (m/s²), compass (heading in radians, clockwise from north), longitude_x, longitude_y, longitude_z.

Despite their name, the longitude_* columns hold the gyroscope’s angular velocity around the x, y and z axes in rad/s: the generator wrote CARLA’s IMUMeasurement.gyroscope under that name. They are kept as stored in imu.feather.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'imu'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.ActionsDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep ego-vehicle control actions.

Returns a FloatTensor (T, 7) with columns: throttle, steer, brake, hand_brake, reverse, manual_gear_shift, gear. Boolean columns are cast to float.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'actions'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

Tensor

Parameters:

idx (int)

class carlanomaly.datasets.CollisionsDataset(root=None, split='train', *, clip_len=1, stride=None, anomaly_types=None, towns=None, download=False, parts=None, download_verify=True, direction=None, transform=None, index=None)[source]

Bases: AtomicDataset

Per-timestep collision events (sparse).

Returns a List[pd.DataFrame] of length T. Each DataFrame contains zero or more rows with columns: ego_id, ego_type, other_id, other_type, normal_impulse_x, normal_impulse_y, normal_impulse_z, normal_impulse_norm. Most timesteps have no collisions (empty DataFrame).

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • clip_len (int)

  • stride (Optional[int])

  • anomaly_types (Optional[Sequence[str]])

  • towns (Optional[Sequence[str]])

  • download (bool)

  • parts (Optional[Sequence[str]])

  • download_verify (bool)

  • direction (Optional[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

modality: ClassVar[str | None] = 'collisions'

Dataset-registry modality key (see carlanomaly.download). Drives the download part auto-selection; None disables it.

__getitem__(idx)[source]
Return type:

List[DataFrame]

Parameters:

idx (int)

Composite

Composite datasets return dicts that already include the evaluator identifiers scenario_id and timesteps.

class carlanomaly.datasets.CameraDataset(root=None, split='train', direction='front', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: Dataset

Composite dataset for a single camera direction.

Wraps RGBDataset, DepthDataset, SegmentationDataset, and AnomalySegmentationDataset.

Returns a dict with keys 'rgb', 'depth', 'segmentation' (sub-dict with 'semantic' and 'instance'), and 'anomaly_mask', plus the evaluator identifiers 'scenario_id' and 'timesteps'.

Parameters:
  • root – Path to the CarlAnomaly dataset directory.

  • split – 'train', 'test_normal', 'test_anomaly', or 'test'.

  • direction – Camera direction ('front', 'left', 'right', 'rear').

  • transform – Optional transform applied to the merged output dict.

  • download – If True, fetch the archive parts this composite needs (base + depth, plus camera-extended for non-front directions) into root before loading. By default (False) the parts must already be there; a missing part raises FileNotFoundError with download instructions.

  • Additional keyword arguments (``clip_len``, ``stride``, ``parts``, …)

  • are forwarded to :class:`~carlanomaly.index.ScenarioIndex`.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • direction (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

property index: ScenarioIndex

The ScenarioIndex this dataset is built on (shareable).

__len__()[source]
Return type:

int

__getitem__(idx)[source]
Return type:

Dict

Parameters:

idx (int)

class carlanomaly.datasets.LiDARDataset(root=None, split='train', *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: Dataset

Composite dataset for LiDAR point clouds with anomaly labels.

Wraps PointCloudDataset and AnomalyLiDARDataset.

Returns a dict with keys 'points' (List[DataFrame]) and 'anomaly_lidar' (List[BoolTensor]), plus the evaluator identifiers 'scenario_id' and 'timesteps'.

Parameters:
  • root – Path to the CarlAnomaly dataset directory.

  • split – 'train', 'test_normal', 'test_anomaly', or 'test'.

  • transform – Optional transform applied to the merged output dict.

  • download – If True, fetch the archive parts this composite needs (base + lidar) into root before loading. By default (False) the parts must already be there; a missing part raises FileNotFoundError with download instructions.

  • Additional keyword arguments (``clip_len``, ``stride``, ``parts``, …)

  • are forwarded to :class:`~carlanomaly.index.ScenarioIndex`.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

property index: ScenarioIndex

The ScenarioIndex this dataset is built on (shareable).

__len__()[source]
Return type:

int

__getitem__(idx)[source]
Return type:

Dict

Parameters:

idx (int)

class carlanomaly.datasets.CarlAnomalyDataset(root=None, split='train', cameras=('front', 'left', 'right', 'rear'), *, transform=None, index=None, download=False, **index_kwargs)[source]

Bases: Dataset

Joint dataset wrapping all modalities and all cameras.

Returns a dict with prefixed camera keys (front_rgb, left_depth, etc.) plus tabular, LiDAR, and timestep-label entries.

Use carlanomaly_collate_fn() as the DataLoader collate_fn.

Parameters:
  • root – Path to the CarlAnomaly dataset directory.

  • split – 'train', 'test_normal', 'test_anomaly', or 'test'.

  • cameras – Camera directions to include. Defaults to all four.

  • transform – Optional transform applied to the merged output dict.

  • download – If True, fetch every archive part this joint dataset needs (base, depth, lidar, plus camera-extended when any non-front camera is included) into root before loading. By default (False) the parts must already be there; a missing part raises FileNotFoundError with download instructions.

  • Additional keyword arguments (``clip_len``, ``stride``, ``parts``, …)

  • are forwarded to :class:`~carlanomaly.index.ScenarioIndex`.

Parameters:
  • root (Optional[PathLike])

  • split (str)

  • cameras (Sequence[str])

  • transform (Optional[Callable])

  • index (Optional[ScenarioIndex])

  • download (bool)

  • index_kwargs (Any)

property index: ScenarioIndex

The ScenarioIndex this dataset is built on (shareable).

__len__()[source]
Return type:

int

__getitem__(idx)[source]
Return type:

Dict[str, Any]

Parameters:

idx (int)

carlanomaly.datasets.carlanomaly_collate_fn(batch)[source]

Custom collate function for CarlAnomalyDataset.

  • Stacks torch.Tensor values along a new batch dimension.

  • Keeps List, str, None, and pd.DataFrame values as plain Python lists.

  • Recurses into dicts.

Return type:

Dict[str, Any]

Parameters:

batch (List[Dict[str, Any]])

Utilities

class carlanomaly.datasets.WithIdentifiers(dataset)[source]

Bases: Dataset

Attach evaluator identifiers to any CarlAnomaly dataset’s items.

Wraps a dataset and returns {"data": <wrapped item>, "scenario_id": str, "timesteps": LongTensor (T,)}, so that a DataLoader batch carries everything the evaluators need (see the evaluation guide). Works with every atomic and composite CarlAnomaly dataset:

rgb = WithIdentifiers(RGBDataset(root, split="test"))
item = rgb[0]
item["data"]         # what RGBDataset(...)[0] would have returned
item["scenario_id"]  # str, e.g. ".../test/normal/Town10HD/scenario-3"
item["timesteps"]    # LongTensor (T,)

When the wrapped dataset returns non-tensor values (point clouds, collision DataFrames), use carlanomaly_collate_fn() as the DataLoader collate_fn.

Parameters:

dataset (Dataset)

property index: ScenarioIndex
__len__()[source]
Return type:

int

__getitem__(idx)[source]
Return type:

Dict[str, Any]

Parameters:

idx (int)