diff --git a/CHANGELOG.md b/CHANGELOG.md index ae73b05..41db548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,3 +108,4 @@ Other breaking changes: - the `fromdict()` and `asdict()` methods in `raillabel.format` classes have been replaced with `from_json()` and `to_json` respectively - `raillabel.format.Transform` fields have been changed by `pos -> position` and `quad -> quaternion` to make it more explicit - `raillabel.format.FrameInterval` fields have been changed by `frame_start -> start` and `frame_end -> end` to make it more concise +- `raillabel.format.Frame.uid` field has been removed to avoid redundant information diff --git a/raillabel/format/frame.py b/raillabel/format/frame.py index bb4a618..0dcd722 100644 --- a/raillabel/format/frame.py +++ b/raillabel/format/frame.py @@ -20,8 +20,6 @@ class Frame: Parameters ---------- - uid: int - Number of the frame within the annotation file. Must be unique. timestamp: decimal.Decimal, optional Timestamp containing the Unix epoch time of the frame with up to nanosecond precision. sensors: dict of raillabel.format.SensorReference, optional @@ -42,7 +40,6 @@ class Frame: """ - uid: int timestamp: decimal.Decimal | None = None sensors: dict[str, SensorReference] = field(default_factory=dict) frame_data: dict[str, Num] = field(default_factory=dict) @@ -71,7 +68,6 @@ def object_data(self) -> dict[str, dict[str, type[_ObjectAnnotation]]]: @classmethod def fromdict( cls, - uid: str, data_dict: dict, objects: dict[str, Object], sensors: dict[str, Sensor], @@ -96,7 +92,6 @@ def fromdict( """ return Frame( - uid=int(uid), timestamp=cls._timestamp_fromdict(data_dict), sensors=cls._sensors_fromdict(data_dict, sensors), frame_data=cls._frame_data_fromdict(data_dict, sensors), diff --git a/raillabel/format/object.py b/raillabel/format/object.py index 06dfa13..9301ce0 100644 --- a/raillabel/format/object.py +++ b/raillabel/format/object.py @@ -98,7 +98,7 @@ def frame_intervals(self, frames: dict[int, Frame]) -> list[FrameInterval]: """ frame_uids_containing_object = [ - frame.uid for frame in frames.values() if self._is_object_in_frame(frame) + frame_uid for frame_uid, frame in frames.items() if self._is_object_in_frame(frame) ] return FrameInterval.from_frame_uids(frame_uids_containing_object) @@ -150,11 +150,11 @@ def _filtered_annotations(self, frame: Frame) -> list[t.Any]: def _collect_pointer_ids_per_frame(self, frames: dict[int, Frame]) -> dict[int, set[str]]: pointer_ids_per_frame: dict[int, set[str]] = {} - for frame in frames.values(): - pointer_ids_per_frame[frame.uid] = set() + for frame_uid, frame in frames.items(): + pointer_ids_per_frame[frame_uid] = set() for annotation in self._filtered_annotations(frame): - pointer_ids_per_frame[frame.uid].add(annotation.name) # type: ignore + pointer_ids_per_frame[frame_uid].add(annotation.name) # type: ignore return pointer_ids_per_frame diff --git a/raillabel/format/scene.py b/raillabel/format/scene.py index 170f5ea..abe5bf4 100644 --- a/raillabel/format/scene.py +++ b/raillabel/format/scene.py @@ -173,7 +173,7 @@ def _frames_fromdict( ) -> dict[int, Frame]: frames = {} for frame_uid, frame_dict in frames_dict.items(): - frames[int(frame_uid)] = Frame.fromdict(frame_uid, frame_dict, objects, sensors) + frames[int(frame_uid)] = Frame.fromdict(frame_dict, objects, sensors) return frames diff --git a/tests/test_raillabel/format/test_frame.py b/tests/test_raillabel/format/test_frame.py index 904d69b..c644794 100644 --- a/tests/test_raillabel/format/test_frame.py +++ b/tests/test_raillabel/format/test_frame.py @@ -42,7 +42,6 @@ def frame_dict( @pytest.fixture def frame(sensor_reference_camera, num, all_annotations) -> dict: return Frame( - uid=0, timestamp=Decimal("1632321743.100000072"), sensors={sensor_reference_camera.sensor.uid: sensor_reference_camera}, frame_data={num.name: num}, @@ -55,7 +54,6 @@ def frame(sensor_reference_camera, num, all_annotations) -> dict: def test_fromdict_sensors(sensor_reference_camera_dict, sensor_reference_camera, sensor_camera): frame = Frame.fromdict( - uid=0, data_dict={ "frame_properties": { "timestamp": "1632321743.100000072", @@ -66,14 +64,12 @@ def test_fromdict_sensors(sensor_reference_camera_dict, sensor_reference_camera, objects={}, ) - assert frame.uid == 0 assert frame.timestamp == Decimal("1632321743.100000072") assert frame.sensors == {sensor_reference_camera.sensor.uid: sensor_reference_camera} def test_fromdict_frame_data(num, num_dict, sensor_camera): frame = Frame.fromdict( - uid=1, data_dict={"frame_properties": {"frame_data": {"num": [num_dict]}}}, sensors={sensor_camera.uid: sensor_camera}, objects={}, @@ -91,7 +87,6 @@ def test_fromdict_annotations( all_annotations, ): frame = Frame.fromdict( - uid=2, data_dict={ "objects": { object_person.uid: object_data_person_dict, @@ -113,7 +108,6 @@ def test_asdict_sensors( sensor_reference_camera, ): frame = Frame( - uid=0, timestamp=Decimal("1632321743.100000072"), sensors={sensor_reference_camera.sensor.uid: sensor_reference_camera}, ) @@ -127,7 +121,7 @@ def test_asdict_sensors( def test_asdict_frame_data(num, num_dict): - frame = Frame(uid=0, frame_data={num.name: num}) + frame = Frame(frame_data={num.name: num}) assert frame.asdict() == {"frame_properties": {"frame_data": {"num": [num_dict]}}} @@ -135,7 +129,7 @@ def test_asdict_frame_data(num, num_dict): def test_asdict_object_data( object_data_person_dict, object_person, object_data_train_dict, object_train, all_annotations ): - frame = Frame(uid=0, annotations=all_annotations) + frame = Frame(annotations=all_annotations) assert frame.asdict() == { "objects": { @@ -147,7 +141,6 @@ def test_asdict_object_data( def test_object_data(object_person, object_train, bbox, cuboid, poly2d, poly3d, seg3d, bbox_train): frame = Frame( - uid=2, annotations={ bbox.uid: bbox, poly2d.uid: poly2d, diff --git a/tests/test_raillabel/format/test_object.py b/tests/test_raillabel/format/test_object.py index a3657a3..482f49a 100644 --- a/tests/test_raillabel/format/test_object.py +++ b/tests/test_raillabel/format/test_object.py @@ -8,7 +8,7 @@ import sys import typing as t from pathlib import Path -from uuid import UUID, uuid4 +from uuid import uuid4 import pytest @@ -405,11 +405,11 @@ def build_annotation(name: str, object: Object, attributes: dict = {}) -> t.Unio def build_frame(uid: int, raw_object_data: dict[Object, list[t.Union[Bbox, Cuboid]]]) -> Frame: annotations = {} - for object, object_data in raw_object_data.items(): + for object_data in raw_object_data.values(): for annotation in object_data: annotations[annotation.uid] = annotation - return Frame(uid=uid, annotations=annotations) + return Frame(annotations=annotations) def build_object(type: str) -> Object: diff --git a/tests/test_raillabel/format/test_scene.py b/tests/test_raillabel/format/test_scene.py index e342dbe..124b55d 100644 --- a/tests/test_raillabel/format/test_scene.py +++ b/tests/test_raillabel/format/test_scene.py @@ -194,7 +194,7 @@ def test_fromdict_frames( "coordinate_systems": coordinate_systems_dict, "objects": objects_dict, "frames": { - str(frame.uid): frame_dict, + "0": frame_dict, }, "frame_intervals": [ { @@ -208,7 +208,7 @@ def test_fromdict_frames( ) assert scene.frames == { - frame.uid: frame, + 0: frame, } @@ -300,7 +300,7 @@ def test_asdict_frames( sensors=sensors, objects=objects, frames={ - frame.uid: frame, + "0": frame, }, ) @@ -311,7 +311,7 @@ def test_asdict_frames( "coordinate_systems": coordinate_systems_dict, "objects": objects_dict, "frames": { - str(frame.uid): frame_dict, + "0": frame_dict, }, "frame_intervals": [ {