Skip to content

Commit

Permalink
implement _is_frame_empty()
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 21, 2024
1 parent 15b5965 commit 191ca39
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0
"""Package for validating a scene for empty frames."""
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit 191ca39

Please sign in to comment.