Skip to content

Commit

Permalink
fix: trains 2 attribute parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 28, 2024
1 parent d44b143 commit 38bc750
Showing 1 changed file with 4 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import os

import pytest
import raillabel


@pytest.fixture
def loader():
return raillabel.load_.loader_classes.LoaderUnderstandAi()
from raillabel_providerkit.convert.loader_classes.loader_understand_ai import LoaderUnderstandAi


def test_supports_true(json_data):
assert LoaderUnderstandAi().supports(json_data["understand_ai_real_life"])
def test_supports_true(json_data):
assert LoaderUnderstandAi().supports(json_data["understand_ai_real_life"])

Expand All @@ -35,95 +31,6 @@ def test_validate_schema__real_life_file__errors(json_data):
assert len(actual) == 1
assert "topic" in actual[0]


def test_load(json_data):
input_data_raillabel = remove_non_parsed_fields(json_data["openlabel_v1_short"])
input_data_uai = json_data["understand_ai_t4_short"]

scene_ground_truth = LoaderRailLabel().load(input_data_raillabel, validate=False)
scene = LoaderUnderstandAi().load(input_data_uai, validate=False)

scene.metadata = scene_ground_truth.metadata

assert scene.asdict() == scene_ground_truth.asdict()


def remove_non_parsed_fields(raillabel_data: dict) -> dict:
"""Return RailLabel file with frame_data and poly3ds removed."""

for frame in raillabel_data["openlabel"]["frames"].values():

if "frame_data" in frame["frame_properties"]:
del frame["frame_properties"]["frame_data"]

for object_id, object in list(frame["objects"].items()):
if "poly3d" not in object["object_data"]:
continue

del object["object_data"]["poly3d"]
if len(object["object_data"]) == 0:
del frame["objects"][object_id]

return raillabel_data


# def test_raillabel_loader_warnings():
# scene_dict = {
# "metadata": {
# "clip_id": "db_3_2021-09-22-14-28-01_2021-09-22-14-44-03",
# "external_clip_id": "2021-09-22-14-28-01_2021-09-22-14-44-03",
# "project_id": "trains_4",
# "export_time": "2023-04-20 01:38 UTC",
# "exporter_version": "1.0.0",
# "coordinate_system_3d": "FLU",
# "coordinate_system_reference": "SENSOR",
# "folder_name": "2021-09-22-14-28-01_2021-09-22-14-44-03"
# },
# "coordinateSystems": [],
# "frames": [
# {
# "frameId": "000",
# "timestamp": "1632321743.134149",
# "annotations": {
# "2D_BOUNDING_BOX": [
# {
# "id": "78f0ad89-2750-4a30-9d66-44c9da73a714",
# "objectId": "b40ba3ad-0327-46ff-9c28-2506cfd6d934",
# "className": "2D_person",
# "geometry": {
# "xMin": -1.0,
# "yMin": -0.5,
# "xMax": 1,
# "yMax": 2.5
# },
# "attributes": {},
# "sensor": {
# "type": "NON_EXISTENT_SENSOR", # <-- relevant line
# "uri": "S1206063/rgb_test0.png",
# "timestamp": "1632321743.100000072"
# }
# }
# ],
# "2D_POLYLINE": [],
# "2D_POLYGON": [],
# "3D_BOUNDING_BOX": [],
# "3D_SEGMENTATION": []
# }
# }
# ]
# }
# loader = LoaderUnderstandAi()

# loader.load(scene_dict, validate=True)

# assert len(loader.warnings) == 2

# assert "NON_EXISTENT_SENSOR" in loader.warnings[0]
# assert "frame 0" in loader.warnings[0]

# assert "NON_EXISTENT_SENSOR" in loader.warnings[1]
# assert "78f0ad89-2750-4a30-9d66-44c9da73a714" in loader.warnings[1]

# Executes the test if the file is called

if __name__ == "__main__":
pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear"])

0 comments on commit 38bc750

Please sign in to comment.