From 7c4de6d88664d2ea1b084f316a11896dde3e1150 Mon Sep 17 00:00:00 2001 From: aktersnurra Date: Tue, 23 Jun 2020 22:39:54 +0200 Subject: latest --- src/text_recognizer/tests/support/__init__.py | 2 ++ .../tests/support/create_emnist_support_files.py | 33 +++++++++++++++++++++ src/text_recognizer/tests/support/emnist/8.png | Bin 0 -> 498 bytes src/text_recognizer/tests/support/emnist/U.png | Bin 0 -> 524 bytes src/text_recognizer/tests/support/emnist/e.png | Bin 0 -> 563 bytes 5 files changed, 35 insertions(+) create mode 100644 src/text_recognizer/tests/support/__init__.py create mode 100644 src/text_recognizer/tests/support/create_emnist_support_files.py create mode 100644 src/text_recognizer/tests/support/emnist/8.png create mode 100644 src/text_recognizer/tests/support/emnist/U.png create mode 100644 src/text_recognizer/tests/support/emnist/e.png (limited to 'src/text_recognizer/tests/support') diff --git a/src/text_recognizer/tests/support/__init__.py b/src/text_recognizer/tests/support/__init__.py new file mode 100644 index 0000000..a265ede --- /dev/null +++ b/src/text_recognizer/tests/support/__init__.py @@ -0,0 +1,2 @@ +"""Support file modules.""" +from .create_emnist_support_files import create_emnist_support_files diff --git a/src/text_recognizer/tests/support/create_emnist_support_files.py b/src/text_recognizer/tests/support/create_emnist_support_files.py new file mode 100644 index 0000000..5dd1a81 --- /dev/null +++ b/src/text_recognizer/tests/support/create_emnist_support_files.py @@ -0,0 +1,33 @@ +"""Module for creating EMNIST test support files.""" +from pathlib import Path +import shutil + +from text_recognizer.datasets.emnist_dataset import ( + fetch_emnist_dataset, + load_emnist_mapping, +) +from text_recognizer.util import write_image + +SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "emnist" + + +def create_emnist_support_files() -> None: + """Create support images for test of CharacterPredictor class.""" + shutil.rmtree(SUPPORT_DIRNAME, ignore_errors=True) + SUPPORT_DIRNAME.mkdir() + + dataset = fetch_emnist_dataset(split="byclass", train=False) + mapping = load_emnist_mapping() + + for index in [5, 7, 9]: + image, label = dataset[index] + if len(image.shape) == 3: + image = image.squeeze(0) + image = image.numpy() + label = mapping[int(label)] + print(index, label) + write_image(image, str(SUPPORT_DIRNAME / f"{label}.png")) + + +if __name__ == "__main__": + create_emnist_support_files() diff --git a/src/text_recognizer/tests/support/emnist/8.png b/src/text_recognizer/tests/support/emnist/8.png new file mode 100644 index 0000000..faa29aa Binary files /dev/null and b/src/text_recognizer/tests/support/emnist/8.png differ diff --git a/src/text_recognizer/tests/support/emnist/U.png b/src/text_recognizer/tests/support/emnist/U.png new file mode 100644 index 0000000..304eaec Binary files /dev/null and b/src/text_recognizer/tests/support/emnist/U.png differ diff --git a/src/text_recognizer/tests/support/emnist/e.png b/src/text_recognizer/tests/support/emnist/e.png new file mode 100644 index 0000000..a03ecd4 Binary files /dev/null and b/src/text_recognizer/tests/support/emnist/e.png differ -- cgit v1.2.3-70-g09d2