Skip to content

Commit

Permalink
refactor: replace all raillabel format UUIDs with str
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Sep 6, 2023
1 parent afa7968 commit 4f0ef6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
10 changes: 5 additions & 5 deletions raillabel/format/raillabel/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ class Frame:
Read-Only Attributes
--------------------
object_data: dict[str, dict[UUID, _ObjectAnnotation subclass]]
object_data: dict[str, dict[str, _ObjectAnnotation subclass]]
Annotations categorized by object. Keys are object uids and values are the annotations
as a dict, that have the object.
as a dict, that are part of the object.
"""

uid: int
timestamp: t.Optional[decimal.Decimal] = None
sensors: t.Dict[str, SensorReference] = field(default_factory=dict)
frame_data: t.Dict[str, Num] = field(default_factory=dict)
annotations: t.Dict[uuid.UUID, t.Type[_ObjectAnnotation]] = field(default_factory=dict)
annotations: t.Dict[str, t.Type[_ObjectAnnotation]] = field(default_factory=dict)

@property
def object_data(self) -> t.Dict[str, t.Dict[uuid.UUID, t.Type[_ObjectAnnotation]]]:
def object_data(self) -> t.Dict[str, t.Dict[str, t.Type[_ObjectAnnotation]]]:
"""Return annotations categorized by Object-Id.
Returns
Expand Down Expand Up @@ -221,7 +221,7 @@ def _objects_fromdict(
for annotation in object_annotations:
if annotation.uid in annotations:
cls._issue_duplicate_annotation_uid_warning(annotation.uid, frame_id)
annotation.uid = uuid.uuid4()
annotation.uid = str(uuid.uuid4())

annotations[annotation.uid] = annotation

Expand Down
3 changes: 1 addition & 2 deletions raillabel/format/raillabel/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import typing as t
from dataclasses import dataclass
from uuid import UUID

from _collections_abc import dict_values

Expand Down Expand Up @@ -143,7 +142,7 @@ def _object_data_pointers_asdict(
}

def _is_object_in_frame(self, frame: "Frame") -> bool:
return UUID(self.uid) in frame.object_data or str(self.uid) in frame.object_data
return self.uid in frame.object_data

def _filtered_annotations(self, frame: "Frame") -> dict_values:
return [ann for ann in frame.annotations.values() if ann.object.uid == self.uid]
Expand Down
5 changes: 2 additions & 3 deletions raillabel/format/raillabel/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: Apache-2.0

import typing as t
import uuid
from dataclasses import dataclass, field

from ... import exceptions
Expand Down Expand Up @@ -37,7 +36,7 @@ class Scene:

metadata: Metadata
sensors: t.Dict[str, Sensor] = field(default_factory=dict)
objects: t.Dict[uuid.UUID, Object] = field(default_factory=dict)
objects: t.Dict[str, Object] = field(default_factory=dict)
frames: t.Dict[int, Frame] = field(default_factory=dict)

@property
Expand Down Expand Up @@ -223,7 +222,7 @@ def _coordinate_systems_asdict(self, sensors: t.Dict[str, Sensor]) -> dict:

return coordinate_systems

def _objects_asdict(self, objects: t.Dict[uuid.UUID, Object], calculate_pointers: bool) -> dict:
def _objects_asdict(self, objects: t.Dict[str, Object], calculate_pointers: bool) -> dict:

if calculate_pointers:
return {str(uid): object.asdict(self.frames) for uid, object in objects.items()}
Expand Down
6 changes: 3 additions & 3 deletions tests/test_raillabel/format/raillabel/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def build_annotation(name: str, object: Object, attributes: dict={}) -> t.Union[

if ann_type == "bbox":
return Bbox(
uid=uuid4(),
uid=str(uuid4()),
object=object,
attributes=attributes,
sensor=sensor,
Expand All @@ -395,7 +395,7 @@ def build_annotation(name: str, object: Object, attributes: dict={}) -> t.Union[

elif ann_type == "cuboid":
return Cuboid(
uid=uuid4(),
uid=str(uuid4()),
object=object,
attributes=attributes,
sensor=sensor,
Expand All @@ -417,7 +417,7 @@ def build_frame(uid: int, raw_object_data: t.Dict[Object, t.List[t.Union[Bbox, C

def build_object(type: str) -> Object:
return Object(
uid=uuid4(),
uid=str(uuid4()),
name=f"{type}_{str(random.randint(0, 9999)).zfill(4)}",
type=type
)
Expand Down

0 comments on commit 4f0ef6d

Please sign in to comment.