-
Notifications
You must be signed in to change notification settings - Fork 16
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 furry unittest and benchmark
- Loading branch information
1 parent
9c994e6
commit 00d8b0e
Showing
29 changed files
with
109 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import glob | ||
import os.path | ||
|
||
from natsort import natsorted | ||
|
||
from plot import image_plot | ||
|
||
if __name__ == '__main__': | ||
image_plot( | ||
*natsorted(glob.glob(os.path.join('furry', 'non_furry', '*.jpg'))), | ||
*natsorted(glob.glob(os.path.join('furry', 'furry', '*.jpg'))), | ||
columns=4, figsize=(10, 15), | ||
) |
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,21 @@ | ||
imgutils.validate.furry | ||
============================================= | ||
|
||
.. currentmodule:: imgutils.validate.furry | ||
|
||
.. automodule:: imgutils.validate.furry | ||
|
||
|
||
anime_furry_score | ||
----------------------------- | ||
|
||
.. autofunction:: anime_furry_score | ||
|
||
|
||
|
||
anime_furry | ||
----------------------------- | ||
|
||
.. autofunction:: anime_furry | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,36 @@ | ||
import random | ||
|
||
from benchmark import BaseBenchmark, create_plot_cli | ||
from imgutils.generic.classify import _open_models_for_repo_id | ||
from imgutils.validate import anime_furry | ||
from imgutils.validate.furry import _REPO_ID | ||
|
||
_MODEL_NAMES = _open_models_for_repo_id(_REPO_ID).model_names | ||
|
||
|
||
class AnimeFurryBenchmark(BaseBenchmark): | ||
def __init__(self, model): | ||
BaseBenchmark.__init__(self) | ||
self.model = model | ||
|
||
def load(self): | ||
_open_models_for_repo_id(_REPO_ID)._open_model(self.model) | ||
|
||
def unload(self): | ||
_open_models_for_repo_id(_REPO_ID).clear() | ||
|
||
def run(self): | ||
image_file = random.choice(self.all_images) | ||
_ = anime_furry(image_file, self.model) | ||
|
||
|
||
if __name__ == '__main__': | ||
create_plot_cli( | ||
[ | ||
(name, AnimeFurryBenchmark(name)) | ||
for name in _MODEL_NAMES | ||
], | ||
title='Benchmark for Anime Furry Check Models', | ||
run_times=10, | ||
try_times=20, | ||
)() |
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ imgutils.validate | |
color | ||
completeness | ||
dbrating | ||
furry | ||
monochrome | ||
nsfw | ||
portrait | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
import glob | ||
import os.path | ||
|
||
import pytest | ||
|
||
from imgutils.generic.classify import _open_models_for_repo_id | ||
from imgutils.validate import anime_furry, anime_furry_score | ||
from imgutils.validate.furry import _REPO_ID | ||
from test.testings import get_testfile | ||
|
||
_ROOT_DIR = get_testfile('furry') | ||
_EXAMPLE_FILES = [ | ||
(os.path.relpath(file, _ROOT_DIR), os.path.basename(os.path.dirname(file))) | ||
for file in glob.glob(get_testfile('furry', '**', '*.jpg'), recursive=True) | ||
] | ||
|
||
|
||
@pytest.fixture(scope='module', autouse=True) | ||
def _release_model_after_run(): | ||
try: | ||
yield | ||
finally: | ||
_open_models_for_repo_id(_REPO_ID).clear() | ||
|
||
|
||
@pytest.mark.unittest | ||
class TestValidatePortrait: | ||
@pytest.mark.parametrize(['image', 'label'], _EXAMPLE_FILES) | ||
def test_anime_furry(self, image, label): | ||
image_file = get_testfile('furry', image) | ||
tag, score = anime_furry(image_file) | ||
assert tag == label | ||
|
||
@pytest.mark.parametrize(['image', 'label'], _EXAMPLE_FILES) | ||
def test_anime_furry_score(self, image, label): | ||
image_file = get_testfile('furry', image) | ||
scores = anime_furry_score(image_file) | ||
assert scores[label] > 0.5 |