Skip to content

Commit

Permalink
tests for new relabel function for Darknet (YOLO) annotation files
Browse files Browse the repository at this point in the history
  • Loading branch information
monocongo committed Feb 5, 2020
1 parent f8e02ec commit 8b8f389
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
55 changes: 53 additions & 2 deletions tests/test_relabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,57 @@
logging.disable(logging.CRITICAL)


# ------------------------------------------------------------------------------
@pytest.mark.usefixtures(
"data_dir",
)
def test_relabel_darknet(
data_dir,
):
"""
Test for the cvdata.relabel.relabel_darknet() function
:param data_dir: temporary directory into which test files will be loaded
"""
darknet_file_name = "darknet_1.txt"
darknet_file_path = str(data_dir.join(darknet_file_name))

# confirm that a relabeling won't occur if the old value is not present
relabel.relabel_darknet(darknet_file_path, 58, 59)
expected_darknet_file_name = "expected_darknet_1.txt"
expected_darknet_file_path = str(data_dir.join(expected_darknet_file_name))
assert text_files_equal(
darknet_file_path,
expected_darknet_file_path,
)

# confirm that relabeling occurred as expected
relabel.relabel_darknet(darknet_file_path, 3, 2)
expected_darknet_file_name = "expected_darknet_2.txt"
expected_darknet_file_path = str(data_dir.join(expected_darknet_file_name))
assert text_files_equal(
darknet_file_path,
expected_darknet_file_path,
)

# confirm that various invalid arguments raise an error
with pytest.raises(TypeError):
relabel.relabel_darknet(darknet_file_path, None, 0)
relabel.relabel_darknet(darknet_file_path, 0, None)
relabel.relabel_darknet(1, 0, 1)
relabel.relabel_darknet(None, 1, 0)
relabel.relabel_darknet("/not/present", 0, 1)
relabel.relabel_darknet(1.0, "strings won't work", 0)
relabel.relabel_darknet(darknet_file_path, 1, "strings won't work")
relabel.relabel_darknet(darknet_file_path, 1.0, 0)
relabel.relabel_darknet(darknet_file_path, 2, 1.0)
relabel.relabel_darknet(darknet_file_path, True, 0)
relabel.relabel_darknet(darknet_file_path, 1, True)
with pytest.raises(ValueError):
relabel.relabel_darknet(darknet_file_path, -5, 1)
relabel.relabel_darknet(darknet_file_path, 1, -4)


# ------------------------------------------------------------------------------
@pytest.mark.usefixtures(
"data_dir",
Expand Down Expand Up @@ -44,7 +95,7 @@ def test_relabel_kitti(
expected_kitti_file_path,
)

# confirm that invalid argument types raise an error
# confirm that various invalid arguments raise an error
with pytest.raises(ValueError):
relabel.relabel_kitti(None, "don't care", "don't care")
relabel.relabel_kitti(kitti_file_path, None, "don't care")
Expand Down Expand Up @@ -95,7 +146,7 @@ def test_relabel_pascal(
etree_after_relabel.getroot(),
)

# confirm that invalid argument types raise an error
# confirm that various invalid arguments raise an error
with pytest.raises(ValueError):
relabel.relabel_pascal(None, "don't care", "don't care")
relabel.relabel_pascal(pascal_file_path, None, "don't care")
Expand Down
1 change: 1 addition & 0 deletions tests/test_relabel/darknet_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3 0.4995 0.2012 0.3994 0.0456
1 change: 1 addition & 0 deletions tests/test_relabel/expected_darknet_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3 0.4995 0.2012 0.3994 0.0456
1 change: 1 addition & 0 deletions tests/test_relabel/expected_darknet_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2 0.4995 0.2012 0.3994 0.0456

0 comments on commit 8b8f389

Please sign in to comment.