summaryrefslogtreecommitdiff
path: root/src/text_recognizer/tests/support
diff options
context:
space:
mode:
authoraktersnurra <gustaf.rydholm@gmail.com>2020-06-23 22:39:54 +0200
committeraktersnurra <gustaf.rydholm@gmail.com>2020-06-23 22:39:54 +0200
commit7c4de6d88664d2ea1b084f316a11896dde3e1150 (patch)
treecbde7e64c8064e9b523dfb65cd6c487d061ec805 /src/text_recognizer/tests/support
parenta7a9ce59fc37317dd74c3a52caf7c4e68e570ee8 (diff)
latest
Diffstat (limited to 'src/text_recognizer/tests/support')
-rw-r--r--src/text_recognizer/tests/support/__init__.py2
-rw-r--r--src/text_recognizer/tests/support/create_emnist_support_files.py33
-rw-r--r--src/text_recognizer/tests/support/emnist/8.pngbin0 -> 498 bytes
-rw-r--r--src/text_recognizer/tests/support/emnist/U.pngbin0 -> 524 bytes
-rw-r--r--src/text_recognizer/tests/support/emnist/e.pngbin0 -> 563 bytes
5 files changed, 35 insertions, 0 deletions
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
--- /dev/null
+++ b/src/text_recognizer/tests/support/emnist/8.png
Binary files 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
--- /dev/null
+++ b/src/text_recognizer/tests/support/emnist/U.png
Binary files 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
--- /dev/null
+++ b/src/text_recognizer/tests/support/emnist/e.png
Binary files differ