-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev(narugo): add unittest for booru_yolo
- Loading branch information
1 parent
16e3887
commit 8b68489
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
from PIL import Image | ||
|
||
from imgutils.detect import detect_with_booru_yolo | ||
from imgutils.detect.booru_yolo import _open_booru_yolo_model, _get_booru_yolo_labels | ||
from ..testings import get_testfile | ||
|
||
|
||
@pytest.fixture(scope='module', autouse=True) | ||
def _release_model_after_run(): | ||
try: | ||
yield | ||
finally: | ||
_open_booru_yolo_model.cache_clear() | ||
_get_booru_yolo_labels.cache_clear() | ||
|
||
|
||
@pytest.fixture() | ||
def nude_girl_file(): | ||
return get_testfile('nude_girl.png') | ||
|
||
|
||
@pytest.fixture() | ||
def nude_girl_image(nude_girl_file): | ||
return Image.open(nude_girl_file) | ||
|
||
|
||
@pytest.fixture() | ||
def nude_girl_detection(): | ||
return [ | ||
((236, 1, 452, 247), 'head', 0.9584360718727112), | ||
((211, 236, 431, 346), 'boob', 0.9300149083137512), | ||
((62, 402, 427, 697), 'sprd', 0.8708215951919556) | ||
] | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestDetectBooruYOLO: | ||
def test_detect_with_booru_yolo_file(self, nude_girl_file, nude_girl_detection): | ||
detection = detect_with_booru_yolo(nude_girl_file) | ||
assert [label for _, label, _ in detection] == \ | ||
[label for _, label, _ in nude_girl_detection] | ||
for (actual_box, _, _), (expected_box, _, _) in zip(detection, nude_girl_detection): | ||
assert actual_box == pytest.approx(expected_box) | ||
assert [score for _, _, score in detection] == \ | ||
pytest.approx([score for _, _, score in nude_girl_detection], abs=1e-4) | ||
|
||
def test_detect_with_booru_yolo_image(self, nude_girl_image, nude_girl_detection): | ||
detection = detect_with_booru_yolo(nude_girl_image) | ||
assert [label for _, label, _ in detection] == \ | ||
[label for _, label, _ in nude_girl_detection] | ||
for (actual_box, _, _), (expected_box, _, _) in zip(detection, nude_girl_detection): | ||
assert actual_box == pytest.approx(expected_box) | ||
assert [score for _, _, score in detection] == \ | ||
pytest.approx([score for _, _, score in nude_girl_detection], abs=1e-4) |