diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-03-20 18:09:06 +0100 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-03-20 18:09:06 +0100 |
commit | 7e8e54e84c63171e748bbf09516fd517e6821ace (patch) | |
tree | 996093f75a5d488dddf7ea1f159ed343a561ef89 /src/text_recognizer/tests/support | |
parent | b0719d84138b6bbe5f04a4982dfca673aea1a368 (diff) |
Inital commit for refactoring to lightning
Diffstat (limited to 'src/text_recognizer/tests/support')
14 files changed, 0 insertions, 133 deletions
diff --git a/src/text_recognizer/tests/support/__init__.py b/src/text_recognizer/tests/support/__init__.py deleted file mode 100644 index a265ede..0000000 --- a/src/text_recognizer/tests/support/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -"""Support file modules.""" -from .create_emnist_support_files import create_emnist_support_files diff --git a/src/text_recognizer/tests/support/create_emnist_lines_support_files.py b/src/text_recognizer/tests/support/create_emnist_lines_support_files.py deleted file mode 100644 index 9abe143..0000000 --- a/src/text_recognizer/tests/support/create_emnist_lines_support_files.py +++ /dev/null @@ -1,51 +0,0 @@ -"""Module for creating EMNIST Lines test support files.""" -# flake8: noqa: S106 - -from pathlib import Path -import shutil - -import numpy as np - -from text_recognizer.datasets import EmnistLinesDataset -import text_recognizer.util as util - - -SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "emnist_lines" - - -def create_emnist_lines_support_files() -> None: - """Create EMNIST Lines test images.""" - shutil.rmtree(SUPPORT_DIRNAME, ignore_errors=True) - SUPPORT_DIRNAME.mkdir() - - # TODO: maybe have to add args to dataset. - dataset = EmnistLinesDataset( - init_token="<sos>", - pad_token="_", - eos_token="<eos>", - transform=[{"type": "ToTensor", "args": {}}], - target_transform=[ - { - "type": "AddTokens", - "args": {"init_token": "<sos>", "pad_token": "_", "eos_token": "<eos>"}, - } - ], - ) # nosec: S106 - dataset.load_or_generate_data() - - for index in [5, 7, 9]: - image, target = dataset[index] - if len(image.shape) == 3: - image = image.squeeze(0) - print(image.sum(), image.dtype) - - label = "".join(dataset.mapper(label) for label in target[1:]).strip( - dataset.mapper.pad_token - ) - print(label) - image = image.numpy() - util.write_image(image, str(SUPPORT_DIRNAME / f"{label}.png")) - - -if __name__ == "__main__": - create_emnist_lines_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 deleted file mode 100644 index f9ff030..0000000 --- a/src/text_recognizer/tests/support/create_emnist_support_files.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Module for creating EMNIST test support files.""" -from pathlib import Path -import shutil - -from text_recognizer.datasets import EmnistDataset -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 = EmnistDataset(train=False) - dataset.load_or_generate_data() - - for index in [5, 7, 9]: - image, label = dataset[index] - if len(image.shape) == 3: - image = image.squeeze(0) - image = image.numpy() - label = dataset.mapper(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/create_iam_lines_support_files.py b/src/text_recognizer/tests/support/create_iam_lines_support_files.py deleted file mode 100644 index 50f9e3d..0000000 --- a/src/text_recognizer/tests/support/create_iam_lines_support_files.py +++ /dev/null @@ -1,50 +0,0 @@ -"""Module for creating IAM Lines test support files.""" -# flake8: noqa -from pathlib import Path -import shutil - -import numpy as np - -from text_recognizer.datasets import IamLinesDataset -import text_recognizer.util as util - - -SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "iam_lines" - - -def create_emnist_lines_support_files() -> None: - """Create IAM Lines test images.""" - shutil.rmtree(SUPPORT_DIRNAME, ignore_errors=True) - SUPPORT_DIRNAME.mkdir() - - # TODO: maybe have to add args to dataset. - dataset = IamLinesDataset( - init_token="<sos>", - pad_token="_", - eos_token="<eos>", - transform=[{"type": "ToTensor", "args": {}}], - target_transform=[ - { - "type": "AddTokens", - "args": {"init_token": "<sos>", "pad_token": "_", "eos_token": "<eos>"}, - } - ], - ) - dataset.load_or_generate_data() - - for index in [0, 1, 3]: - image, target = dataset[index] - if len(image.shape) == 3: - image = image.squeeze(0) - print(image.sum(), image.dtype) - - label = "".join(dataset.mapper(label) for label in target[1:]).strip( - dataset.mapper.pad_token - ) - print(label) - image = image.numpy() - util.write_image(image, str(SUPPORT_DIRNAME / f"{label}.png")) - - -if __name__ == "__main__": - create_emnist_lines_support_files() diff --git a/src/text_recognizer/tests/support/emnist/8.png b/src/text_recognizer/tests/support/emnist/8.png Binary files differdeleted file mode 100644 index faa29aa..0000000 --- a/src/text_recognizer/tests/support/emnist/8.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/emnist/U.png b/src/text_recognizer/tests/support/emnist/U.png Binary files differdeleted file mode 100644 index 304eaec..0000000 --- a/src/text_recognizer/tests/support/emnist/U.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/emnist/e.png b/src/text_recognizer/tests/support/emnist/e.png Binary files differdeleted file mode 100644 index a03ecd4..0000000 --- a/src/text_recognizer/tests/support/emnist/e.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/emnist_lines/Knox Ky<eos>.png b/src/text_recognizer/tests/support/emnist_lines/Knox Ky<eos>.png Binary files differdeleted file mode 100644 index b7d0618..0000000 --- a/src/text_recognizer/tests/support/emnist_lines/Knox Ky<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/emnist_lines/ancillary beliefs and<eos>.png b/src/text_recognizer/tests/support/emnist_lines/ancillary beliefs and<eos>.png Binary files differdeleted file mode 100644 index 14a8cf3..0000000 --- a/src/text_recognizer/tests/support/emnist_lines/ancillary beliefs and<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/emnist_lines/they<eos>.png b/src/text_recognizer/tests/support/emnist_lines/they<eos>.png Binary files differdeleted file mode 100644 index 7f05951..0000000 --- a/src/text_recognizer/tests/support/emnist_lines/they<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/iam_lines/He rose from his breakfast-nook bench<eos>.png b/src/text_recognizer/tests/support/iam_lines/He rose from his breakfast-nook bench<eos>.png Binary files differdeleted file mode 100644 index 6eeb642..0000000 --- a/src/text_recognizer/tests/support/iam_lines/He rose from his breakfast-nook bench<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/iam_lines/and came into the livingroom, where<eos>.png b/src/text_recognizer/tests/support/iam_lines/and came into the livingroom, where<eos>.png Binary files differdeleted file mode 100644 index 4974cf8..0000000 --- a/src/text_recognizer/tests/support/iam_lines/and came into the livingroom, where<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/iam_lines/his entrance. He came, almost falling<eos>.png b/src/text_recognizer/tests/support/iam_lines/his entrance. He came, almost falling<eos>.png Binary files differdeleted file mode 100644 index a731245..0000000 --- a/src/text_recognizer/tests/support/iam_lines/his entrance. He came, almost falling<eos>.png +++ /dev/null diff --git a/src/text_recognizer/tests/support/iam_paragraphs/a01-000u.jpg b/src/text_recognizer/tests/support/iam_paragraphs/a01-000u.jpg Binary files differdeleted file mode 100644 index d9753b6..0000000 --- a/src/text_recognizer/tests/support/iam_paragraphs/a01-000u.jpg +++ /dev/null |