Skip to content

Commit

Permalink
refactor: disable functionality that is probably not used
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Nov 25, 2024
1 parent 6aad142 commit c20df02
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from pathlib import Path

import jsonschema
import raillabel
from raillabel import Scene
from raillabel.json_format import JSONScene

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

from ._loader_abc import LoaderABC
Expand Down Expand Up @@ -52,18 +52,17 @@ def load(self, data: dict, validate_schema: bool = False) -> uai_format.Scene:
The loaded scene with the data.
"""
raise NotImplementedError(
"We were not sure if this class is even used anymore. If you see this error, contact us " # noqa: EM101
"and we will re-implement the class."
)

if validate_schema:
self.validate_schema(data)

with _WarningsLogger() as logger:
data_converted_to_raillabel = uai_format.Scene.fromdict(data).to_raillabel()

raillabel_loader = raillabel.load_.loader_classes.LoaderRailLabel()
raillabel_scene = raillabel_loader.load(data_converted_to_raillabel, validate=False)

self.warnings = logger.warnings + raillabel_loader.warnings
data_converted_to_raillabel = uai_format.Scene.fromdict(data).to_raillabel()

return raillabel_scene
return Scene.from_json(JSONScene(**data_converted_to_raillabel))

def supports(self, data: dict) -> bool:
"""Determine if the loader is suitable for the data (lightweight).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@
# SPDX-License-Identifier: Apache-2.0

import pytest
import raillabel
from raillabel import Scene
from raillabel.json_format import JSONScene

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"])


def test_supports__false(json_data):
data = json_data["understand_ai_real_life"]
del data["metadata"]["project_id"]
assert not LoaderUnderstandAi().supports(data)
# def test_supports__false(json_data):
# data = json_data["understand_ai_real_life"]
# del data["metadata"]["project_id"]
# assert not LoaderUnderstandAi().supports(data)


def test_validate_schema__real_life_file__no_errors(json_data):
actual = LoaderUnderstandAi().validate_schema(json_data["understand_ai_real_life"])
assert actual == []
# def test_validate_schema__real_life_file__no_errors(json_data):
# actual = LoaderUnderstandAi().validate_schema(json_data["understand_ai_real_life"])
# assert actual == []


def test_validate_schema__real_life_file__errors(json_data):
data = json_data["understand_ai_real_life"]
del data["coordinateSystems"][0]["topic"]
# def test_validate_schema__real_life_file__errors(json_data):
# data = json_data["understand_ai_real_life"]
# del data["coordinateSystems"][0]["topic"]

actual = LoaderUnderstandAi().validate_schema(json_data["understand_ai_real_life"])
assert len(actual) == 1
assert "topic" in actual[0]
# actual = LoaderUnderstandAi().validate_schema(json_data["understand_ai_real_life"])
# 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"]
# 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 = raillabel.load_.loader_classes.loader_raillabel.LoaderRailLabel().load(
input_data_raillabel, validate=False
)
scene = LoaderUnderstandAi().load(input_data_uai, validate_schema=False)
# scene_ground_truth = Scene.from_json(JSONScene(**input_data_raillabel))
# scene = LoaderUnderstandAi().load(input_data_uai, validate_schema=False)

scene.metadata = scene_ground_truth.metadata
assert scene == scene_ground_truth
# scene.metadata = scene_ground_truth.metadata
# assert scene.frames[0].annotations == scene_ground_truth.frames[0].annotations
# assert scene == scene_ground_truth


def remove_non_parsed_fields(raillabel_data: dict) -> dict:
"""Return RailLabel file with frame_data and poly3ds removed."""
# 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 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
# 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]
# del object["object_data"]["poly3d"]
# if len(object["object_data"]) == 0:
# del frame["objects"][object_id]

return raillabel_data
# return raillabel_data


if __name__ == "__main__":
Expand Down
18 changes: 9 additions & 9 deletions tests/test_raillabel_providerkit/convert/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
import raillabel_providerkit


def test_convert_uai_select_class(json_data):
scene = raillabel_providerkit.convert(data=json_data["understand_ai_t4_short"])
assert len(scene.frames) != 0
# def test_convert_uai_select_class(json_data):
# scene = raillabel_providerkit.convert(data=json_data["understand_ai_t4_short"])
# assert len(scene.frames) != 0


def test_convert_uai_provide_class(json_data):
scene = raillabel_providerkit.convert(
data=json_data["understand_ai_t4_short"],
loader_class=raillabel_providerkit.loader_classes.LoaderUnderstandAi,
)
assert len(scene.frames) != 0
# def test_convert_uai_provide_class(json_data):
# scene = raillabel_providerkit.convert(
# data=json_data["understand_ai_t4_short"],
# loader_class=raillabel_providerkit.loader_classes.LoaderUnderstandAi,
# )
# assert len(scene.frames) != 0


# Executes the test if the file is called
Expand Down

0 comments on commit c20df02

Please sign in to comment.