Skip to content

Commit

Permalink
feat: add object_type in IssueIdentifyers
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Jan 29, 2025
1 parent 7ce1cc5 commit c9191ff
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 59 deletions.
1 change: 1 addition & 0 deletions raillabel_providerkit/validation/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class IssueIdentifiers:
attribute: str | None = None
frame: int | None = None
object: UUID | None = None
object_type: str | None = None
sensor: str | None = None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ def check(
| raillabel.format.Seg3d,
sensor_type: _SensorType,
frame_id: int,
object_type: str,
) -> list[Issue]:
errors = []

errors.extend(
self._check_undefined_attributes(annotation_uid, annotation, sensor_type, frame_id)
self._check_undefined_attributes(
annotation_uid, annotation, sensor_type, frame_id, object_type
)
)
errors.extend(
self._check_missing_attributes(annotation_uid, annotation, sensor_type, frame_id)
self._check_missing_attributes(
annotation_uid, annotation, sensor_type, frame_id, object_type
)
)
errors.extend(
self._check_false_attribute_type(annotation_uid, annotation, sensor_type, frame_id)
self._check_false_attribute_type(
annotation_uid, annotation, sensor_type, frame_id, object_type
)
)

return errors
Expand All @@ -69,6 +76,7 @@ def _check_undefined_attributes(
| raillabel.format.Seg3d,
sensor_type: _SensorType,
frame_id: int,
object_type: str,
) -> list[Issue]:
return [
Issue(
Expand All @@ -78,6 +86,7 @@ def _check_undefined_attributes(
attribute=attr_name,
frame=frame_id,
object=annotation.object_id,
object_type=object_type,
sensor=annotation.sensor_id,
),
)
Expand All @@ -95,6 +104,7 @@ def _check_missing_attributes(
| raillabel.format.Seg3d,
sensor_type: _SensorType,
frame_id: int,
object_type: str,
) -> list[Issue]:
return [
Issue(
Expand All @@ -104,6 +114,7 @@ def _check_missing_attributes(
attribute=attr_name,
frame=frame_id,
object=annotation.object_id,
object_type=object_type,
sensor=annotation.sensor_id,
),
)
Expand All @@ -121,6 +132,7 @@ def _check_false_attribute_type(
| raillabel.format.Seg3d,
sensor_type: _SensorType,
frame_id: int,
object_type: str,
) -> list[Issue]:
errors = []

Expand All @@ -138,6 +150,7 @@ def _check_false_attribute_type(
attribute=attr_name,
frame=frame_id,
object=annotation.object_id,
object_type=object_type,
sensor=annotation.sensor_id,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def check(self, scene: raillabel.Scene) -> list[Issue]:
if annotation_class not in self.classes:
continue

object_type = scene.objects[annotation.object_id].type

self.errors.extend(
self.classes[annotation_class].check(
annotation_uid, annotation, sensor_type, frame_id
annotation_uid, annotation, sensor_type, frame_id, object_type
)
)

Expand All @@ -52,8 +54,7 @@ def _check_class_validity(self, scene: raillabel.Scene) -> None:
self.errors.append(
Issue(
type=IssueType.OBJECT_TYPE_UNDEFINED,
reason=f"Undefined object type '{object_class}'",
identifiers=IssueIdentifiers(object=obj_uid),
identifiers=IssueIdentifiers(object=obj_uid, object_type=object_class),
)
)

Expand Down
99 changes: 46 additions & 53 deletions tests/validation/validate_onthology/test_onthology.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

from uuid import UUID

import pytest

from raillabel_providerkit.validation.validate_onthology._onthology_classes._onthology import (
_Onthology,
Issue,
IssueType,
IssueIdentifiers,
)
from raillabel_providerkit.validation import IssueType
from raillabel.format import Point2d, Size2d
Expand All @@ -29,9 +34,9 @@ def test_fromdict__simple():
def test_check__empty_scene():
onthology = _Onthology.fromdict({})
scene = SceneBuilder.empty().result

issues = onthology.check(scene)
assert len(issues) == 0
assert issues == onthology.errors
assert issues == []


def test_check__correct():
Expand All @@ -40,25 +45,16 @@ def test_check__correct():
)
scene = (
SceneBuilder.empty()
.add_object(
object_id=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"),
object_type="banana",
object_name="banana_0001",
)
.add_object(object_name="banana_0001")
.add_bbox(
UUID("f54d41d6-5e36-490b-9efc-05a6deb7549a"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=0,
object_name="banana_0001",
sensor_id="rgb_center",
attributes={"is_peelable": True},
)
.result
)

issues = onthology.check(scene)
assert len(issues) == 0
assert issues == onthology.errors
assert issues == []


def test_check__undefined_object_type():
Expand All @@ -73,20 +69,21 @@ def test_check__undefined_object_type():
object_name="apple_0001",
)
.add_bbox(
UUID("f54d41d6-5e36-490b-9efc-05a6deb7549a"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=0,
object_name="banana_0001",
sensor_id="rgb_center",
attributes={"is_peelable": True},
)
.result
)

issues = onthology.check(scene)
assert len(issues) == 1
assert issues == onthology.errors
assert issues[0].type == IssueType.OBJECT_TYPE_UNDEFINED
assert issues == [
Issue(
IssueType.OBJECT_TYPE_UNDEFINED,
IssueIdentifiers(
object=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"), object_type="apple"
),
)
]


def test_check__invalid_attribute_type():
Expand All @@ -102,53 +99,60 @@ def test_check__invalid_attribute_type():
)
.add_bbox(
UUID("f54d41d6-5e36-490b-9efc-05a6deb7549a"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=0,
object_name="banana_0001",
sensor_id="rgb_center",
sensor_id="rgb_middle",
attributes={"is_peelable": "i-like-trains"},
)
.result
)
issues = onthology.check(scene)
assert len(issues) == 1
assert issues == onthology.errors
assert issues[0].type == IssueType.ATTRIBUTE_TYPE
assert issues[0].identifiers == IssueIdentifiers(
annotation=UUID("f54d41d6-5e36-490b-9efc-05a6deb7549a"),
attribute="is_peelable",
frame=0,
object=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"),
object_type="banana",
sensor="rgb_middle",
)


def test_check_class_validity__empty_scene():
onthology = _Onthology.fromdict({})
scene = SceneBuilder.empty().result
onthology._check_class_validity(scene)
assert len(onthology.errors) == 0
assert onthology.errors == []


def test_check_class_validity__correct():
onthology = _Onthology.fromdict(
{"banana": {"is_peelable": {"attribute_type": "boolean", "scope": "annotation"}}}
)
scene = (
SceneBuilder.empty()
.add_object(
object_id=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"),
object_type="banana",
object_name="banana_0001",
)
.result
)
scene = SceneBuilder.empty().add_object(object_type="banana").result
onthology._check_class_validity(scene)
assert len(onthology.errors) == 0
assert onthology.errors == []


def test_check_class_validity__incorrect():
onthology = _Onthology.fromdict(
{"banana": {"is_peelable": {"attribute_type": "boolean", "scope": "annotation"}}}
)
scene = SceneBuilder.empty().add_bbox(object_name="apple_0000").result
scene = (
SceneBuilder.empty()
.add_object(object_id=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"), object_name="apple_0000")
.add_bbox(
object_name="apple_0000",
)
.result
)
onthology._check_class_validity(scene)
assert len(onthology.errors) == 1
assert onthology.errors[0].type == IssueType.OBJECT_TYPE_UNDEFINED
assert onthology.errors[0].identifiers == IssueIdentifiers(
object=UUID("ba73e75d-b996-4f6e-bdad-39c465420a33"), object_type="apple"
)


def test_compile_annotations__empty_scene():
Expand All @@ -161,33 +165,22 @@ def test_compile_annotations__three_annotations_in_two_frames():
scene = (
SceneBuilder.empty()
.add_bbox(
UUID("f54d41d6-5e36-490b-9efc-05a6deb7549a"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=0,
object_name="box_0001",
sensor_id="rgb_center",
attributes={},
)
.add_bbox(
UUID("157ae432-95b0-4e7d-86c5-414c3308e171"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=0,
object_name="box_0002",
sensor_id="rgb_center",
attributes={},
)
.add_bbox(
UUID("711cf3f3-fb2b-4f64-a785-c94bbda9b8c5"),
pos=Point2d(0, 0),
size=Size2d(1, 1),
frame_id=1,
object_name="box_0003",
sensor_id="rgb_center",
attributes={},
)
.result
)
annotations = _Onthology._compile_annotations(scene)
assert len(annotations) == 3


if __name__ == "__main__":
pytest.main([__file__, "-vv"])

0 comments on commit c9191ff

Please sign in to comment.