diff --git a/raillabel_providerkit/validation/validate_empty_frames/__init__.py b/raillabel_providerkit/validation/validate_empty_frames/__init__.py new file mode 100644 index 0000000..3f71fbc --- /dev/null +++ b/raillabel_providerkit/validation/validate_empty_frames/__init__.py @@ -0,0 +1,3 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 +"""Package for validating a scene for empty frames.""" diff --git a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py new file mode 100644 index 0000000..65060e4 --- /dev/null +++ b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py @@ -0,0 +1,26 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +from typing import List + +import raillabel + + +def validate_empty_frames(scene: raillabel.Scene) -> List[str]: + """Validate whether all frames of a scene have at least one annotation. + + Parameters + ---------- + scene : raillabel.Scene + Scene, that should be validated. + + Returns + ------- + list[str] + list of all onthology errors in the scene. If an empty list is returned, then there are no + errors present. + """ + + +def _is_frame_empty(frame: raillabel.format.Frame) -> bool: + return len(frame.annotations) == 0 diff --git a/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py new file mode 100644 index 0000000..ec4c146 --- /dev/null +++ b/tests/test_raillabel_providerkit/validation/validate_empty_frame/test_validate_empty_frames.py @@ -0,0 +1,40 @@ +# Copyright DB Netz AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +import os +import sys +from pathlib import Path + +import pytest +import raillabel + +sys.path.append(str(Path(__file__).parent.parent.parent.parent.parent)) +from raillabel_providerkit.validation.validate_empty_frames.validate_empty_frames import ( + _is_frame_empty, +) + +# == Tests ============================ + +def test_is_frame_empty__true(): + frame = raillabel.format.Frame(uid=0, annotations={}) + assert _is_frame_empty(frame) + +def test_is_frame_empty__false(): + frame = raillabel.format.Frame( + uid=0, annotations={ + "581b0df1-c4cf-4a97-828e-13dd740defe5": raillabel.format.Bbox( + uid=None, + object=None, + sensor=None, + attributes=None, + pos=raillabel.format.Point2d(0, 0), + size=raillabel.format.Size2d(0, 0), + ) + } + ) + assert not _is_frame_empty(frame) + + +if __name__ == "__main__": + os.system("clear") + pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])