raillabel package

Subpackages

Module contents

Devkit for working with recorded and annotated train ride data from DB.

The first step in using raillabel is downloading a desired dataset (like [OSDaR23](https://data.fid-move.de/dataset/osdar23)). You can then load any scene by running

import raillabel

scene = raillabel.load("path/to/annotation_file.json")

This returns the root class for the annotations.

If a file is too extensive for your use-case you can filter out certain parts of a scene like this

from raillabel.filter import (
    IncludeObjectTypeFilter,
    ExcludeAnnotationTypeFilter,
    StartTimeFilter, ExcludeFrameIdFilter,
    IncludeAttributesFilter
)

scene_with_only_trains = scene.filter([IncludeObjectTypeFilter(["rail_vehicle"])])

scene_without_bboxs = scene.filter([ExcludeAnnotationTypeFilter(["bbox"])])

cut_scene_with_only_red_trains = scene.filter([
    StartTimeFilter("1587349200.004200000"),
    ExcludeFrameIdFilter([2, 4]),
    IncludeObjectTypeFilter(["rail_vehicle"]),
    IncludeAttributesFilter({"color": "red"}),
])

An overview of all available filters can be found [here](https://dsd-dbs.github.io/raillabel/code/raillabel.filter.html#module-raillabel.filter).

If you then want to save your changes, then use

raillabel.save(cut_scene_with_only_red_trains, "/path/to/target.json")
class raillabel.Scene(metadata: ~raillabel.format.metadata.Metadata, sensors: dict[str, ~raillabel.format.camera.Camera | ~raillabel.format.lidar.Lidar | ~raillabel.format.radar.Radar | ~raillabel.format.gps_imu.GpsImu | ~raillabel.format.other_sensor.OtherSensor] = <factory>, objects: dict[~uuid.UUID, ~raillabel.format.object.Object] = <factory>, frames: dict[int, ~raillabel.format.frame.Frame] = <factory>)

Bases: object

The root RailLabel class, which contains all data.

Examples: You can load scenes like this:

import raillabel
scene = raillabel.load("path/to/scene.json")

The scenes then contain all of the data. This is how you can iterate over the annotations:

for frame in scene.frames.values():
    for annotation in frame.annotations.values():
        pass  # do something with the annotation here
filter(filters: list[_FilterAbc]) Scene

Return a scene with annotations, sensors, objects and frames excluded.

Example:

from raillabel.filter import (
    IncludeObjectTypeFilter,
    ExcludeAnnotationTypeFilter,
    StartTimeFilter, ExcludeFrameIdFilter,
    IncludeAttributesFilter
)

scene_with_only_trains = scene.filter([IncludeObjectTypeFilter(["rail_vehicle"])])

scene_without_bboxs = scene.filter([ExcludeAnnotationTypeFilter(["bbox"])])

cut_scene_with_only_red_trains = scene.filter([
    StartTimeFilter("1587349200.004200000"),
    ExcludeFrameIdFilter([2, 4]),
    IncludeObjectTypeFilter(["rail_vehicle"]),
    IncludeAttributesFilter({"color": "red"}),
])
frames: dict[int, Frame]

A container of dynamic, timewise, information. Keys are the frame integer number.

classmethod from_json(json: JSONScene) Scene

Construct a scene from a json object.

metadata: Metadata

Container of information about the annotation file itself.

objects: dict[UUID, Object]

Unique objects (like a specific person) in this scene. Keys are object uuids

sensors: dict[str, Camera | Lidar | Radar | GpsImu | OtherSensor]

The sensors used in this scene. Keys are sensor names.

to_json() JSONScene

Export this scene into the RailLabel JSON format.

raillabel.load(path: Path | str) Scene

Load an annotation file as a scene.

Example:

import raillabel
scene = raillabel.load("path/to/scene.json")
raillabel.save(scene: Scene, path: Path | str, prettify_json: bool = False) None

Save a raillabel.Scene to a JSON file.

Example:

import raillabel
scene = raillabel.load("path/to/scene.json")

# change something about the scene

raillabel.save(scene, "path/to/new_scene.json")
# or to get a human readable (but much larger) file
raillabel.save(scene, "path/to/new_scene.json", prettify_json=True)