Skip to content

Commit

Permalink
Merge pull request #55 from DSD-DBS/loading_and_saving_redo
Browse files Browse the repository at this point in the history
Loading and saving redo
  • Loading branch information
unexcellent authored Nov 14, 2024
2 parents 6ae1039 + 737a97b commit 4d20c6d
Show file tree
Hide file tree
Showing 98 changed files with 2,190 additions and 4,438 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Release
- ```frame_data``` can only contain ```Num``` instances
- ```object_data``` can not contain ```Num``` instances anymore
- Major restructuring of the project directories
- ```FrameInterval.from_frame_uids()```: create ```FrameIntervals``` by providing a list of frame uids
- ```FrameInterval.from_frame_ids()```: create ```FrameIntervals``` by providing a list of frame uids
- ```Object.object_data_pointers()```: generate ```ElementDataPointers```
- ```Scene.frame_intervals()```, ```Object.frame_intervals()```: generate ```FrameIntervals```
- ```Object.asdict()``` now provides also frame intervals and object data pointers, if the frames from the scene are provided
Expand Down Expand Up @@ -109,3 +109,4 @@ Other breaking changes:
- `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
- `raillabel.format.Sensor` has been removed in favor of the different sensor type classes `raillabel.format.Camera`, `raillabel.format.Lidar`, `raillabel.format.Radar` and `raillabel.format.GpsImu`
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ The key differences are:
etc.
- For classes that are not builtin (e.g. `Iterable`),
`import collections.abc as cabc` and then use them like `cabc.Iterable`.
- Use [PEP-604-style unions], e.g. `int | float` instead of
- Use [PEP-604-style unions], e.g. `float` instead of
`t.Union[int, float]`.
- Use `... | None` (with `None` always as the last union member) instead of
`t.Optional[...]` and always explicitly annotate where `None` is possible.
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ classifiers = [
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = ["jsonschema>=4.4.0", "fastjsonschema>=2.16.2", "pydantic<3.0.0"]
dependencies = [
"pydantic<3.0.0",
"eval-type-backport==0.2.0"
]

[project.urls]
Homepage = "https://github.com/DSD-DBS/raillabel"
Documentation = "https://dsd-dbs.github.io/raillabel"

[project.optional-dependencies]
docs = ["furo", "sphinx", "sphinx-copybutton", "tomli; python_version<'3.11'"]
docs = ["furo", "sphinx", "sphinx-copybutton", "tomli; python_version<'3.14'"]

test = ["pytest", "pytest-cov", "json5"]

Expand Down
17 changes: 10 additions & 7 deletions raillabel/format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,55 @@
# SPDX-License-Identifier: Apache-2.0
"""Module containing all relevant format classes."""

from ._object_annotation import _ObjectAnnotation, annotation_classes
from .bbox import Bbox
from .camera import Camera
from .cuboid import Cuboid
from .element_data_pointer import ElementDataPointer
from .frame import Frame
from .frame_interval import FrameInterval
from .gps_imu import GpsImu
from .intrinsics_pinhole import IntrinsicsPinhole
from .intrinsics_radar import IntrinsicsRadar
from .lidar import Lidar
from .metadata import Metadata
from .num import Num
from .object import Object
from .other_sensor import OtherSensor
from .point2d import Point2d
from .point3d import Point3d
from .poly2d import Poly2d
from .poly3d import Poly3d
from .quaternion import Quaternion
from .radar import Radar
from .scene import Scene
from .seg3d import Seg3d
from .sensor import Sensor, SensorType
from .sensor_reference import SensorReference
from .size2d import Size2d
from .size3d import Size3d
from .transform import Transform

__all__ = [
"_ObjectAnnotation",
"annotation_classes",
"Bbox",
"Camera",
"Cuboid",
"ElementDataPointer",
"Frame",
"FrameInterval",
"GpsImu",
"IntrinsicsPinhole",
"IntrinsicsRadar",
"Lidar",
"Metadata",
"Num",
"Object",
"OtherSensor",
"Point2d",
"Point3d",
"Poly2d",
"Poly3d",
"Quaternion",
"Radar",
"Scene",
"Seg3d",
"Sensor",
"SensorType",
"SensorReference",
"Size2d",
"Size3d",
Expand Down
57 changes: 0 additions & 57 deletions raillabel/format/_attribute_type.py

This file was deleted.

76 changes: 76 additions & 0 deletions raillabel/format/_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from raillabel.json_format import (
JSONAttributes,
JSONBooleanAttribute,
JSONNumAttribute,
JSONTextAttribute,
JSONVecAttribute,
)


def _attributes_from_json(json: JSONAttributes | None) -> dict[str, float | bool | str | list]:
"""Parse the annotation attributes from json."""
if json is None:
return {}

attributes: dict[str, float | bool | str | list] = {}

if json.boolean is not None:
for bool_attribute in json.boolean:
attributes[bool_attribute.name] = bool_attribute.val

if json.num is not None:
for num_attribute in json.num:
attributes[num_attribute.name] = num_attribute.val

if json.text is not None:
for text_attribute in json.text:
attributes[text_attribute.name] = text_attribute.val

if json.vec is not None:
for vec_attribute in json.vec:
attributes[vec_attribute.name] = vec_attribute.val

return attributes


def _attributes_to_json(attributes: dict[str, float | bool | str | list]) -> JSONAttributes | None:
if len(attributes) == 0:
return None

boolean_attributes = []
num_attributes = []
text_attributes = []
vec_attributes = []

for name, value in attributes.items():
if isinstance(value, bool):
boolean_attributes.append(JSONBooleanAttribute(name=name, val=value))

elif isinstance(value, (int, float)):
num_attributes.append(JSONNumAttribute(name=name, val=value))

elif isinstance(value, str):
text_attributes.append(JSONTextAttribute(name=name, val=value))

elif isinstance(value, list):
vec_attributes.append(JSONVecAttribute(name=name, val=value))

else:
raise UnsupportedAttributeTypeError(name, value)

return JSONAttributes(
boolean=boolean_attributes, num=num_attributes, text=text_attributes, vec=vec_attributes
)


class UnsupportedAttributeTypeError(TypeError):
def __init__(self, attribute_name: str, attribute_value: object) -> None:
super().__init__(
f"{attribute_value.__class__.__name__} of attribute {attribute_name} "
"is not a supported attribute type"
)
117 changes: 0 additions & 117 deletions raillabel/format/_object_annotation.py

This file was deleted.

30 changes: 30 additions & 0 deletions raillabel/format/_sensor_without_intrinsics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from dataclasses import dataclass

from raillabel.json_format import JSONTransformData

from .transform import Transform


@dataclass
class _SensorWithoutIntrinsics:
"""Parent class of all sensors, that do not have an intrinsic calibration."""

extrinsics: Transform | None = None
"External calibration of the sensor defined by the 3D transform to the coordinate system origin."

uri: str | None = None
"Name of the subdirectory containing the sensor files."

description: str | None = None
"Additional information about the sensor."


def _extrinsics_from_json(json_transform: JSONTransformData | None) -> Transform | None:
if json_transform is None:
return None
return Transform.from_json(json_transform)
Loading

0 comments on commit 4d20c6d

Please sign in to comment.