Skip to content

Commit

Permalink
feat: uai warning duplicate frame id
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Sep 19, 2023
1 parent a09b9c2 commit 729586c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion raillabel/format/understand_ai/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import typing as t
from dataclasses import dataclass

from ..._util._warning import _warning
from .coordinate_system import CoordinateSystem
from .frame import Frame
from .metadata import Metadata
Expand Down Expand Up @@ -77,7 +78,16 @@ def _coordinate_systems_fromdict(cls, data_dict: t.List[dict]) -> t.Dict[str, Co
def _frames_fromdict(cls, data_dict: t.List[dict]) -> t.Dict[int, Frame]:
frames = {}
for frame in data_dict:
frames[int(frame["frameId"])] = Frame.fromdict(frame)
frame_id = int(frame["frameId"])

if frame_id in frames:
_warning(
f"Frame UID {frame_id} is contained more than once in the scene. "
+ "The duplicate frame will be omitted."
)
continue

frames[frame_id] = Frame.fromdict(frame)

return frames

Expand Down
25 changes: 25 additions & 0 deletions tests/test_raillabel/format/understand_ai/test_uai_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
sys.path.insert(1, str(Path(__file__).parent.parent.parent.parent.parent))

import raillabel.format.understand_ai as uai_format
from raillabel._util._warning import _WarningsLogger

# == Fixtures =========================

Expand Down Expand Up @@ -90,6 +91,30 @@ def test_fromdict(
frame_uai.id: frame_uai
}

def test_fromdict_duplicate_frame_id_warning(
metadata_uai_dict,
coordinate_system_camera_uai_dict,
coordinate_system_lidar_uai_dict,
coordinate_system_radar_uai_dict,
frame_uai_dict,
):
with _WarningsLogger() as logger:
scene = uai_format.Scene.fromdict(
{
"metadata": metadata_uai_dict,
"coordinateSystems": [
coordinate_system_camera_uai_dict,
coordinate_system_lidar_uai_dict,
coordinate_system_radar_uai_dict,
],
"frames": [frame_uai_dict, frame_uai_dict]
}
)

assert len(logger.warnings) == 1
assert "0" in logger.warnings[0]
assert len(scene.frames) == 1


def test_to_raillabel__metadata(metadata_uai, metadata_raillabel_dict):
scene = uai_format.Scene(
Expand Down

0 comments on commit 729586c

Please sign in to comment.