summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_character_predictor.py31
-rw-r--r--tests/test_line_predictor.py35
-rw-r--r--tests/test_paragraph_text_recognizer.py37
3 files changed, 0 insertions, 103 deletions
diff --git a/tests/test_character_predictor.py b/tests/test_character_predictor.py
deleted file mode 100644
index 01bda78..0000000
--- a/tests/test_character_predictor.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Test for CharacterPredictor class."""
-import importlib
-import os
-from pathlib import Path
-import unittest
-
-from loguru import logger
-
-from text_recognizer.character_predictor import CharacterPredictor
-from text_recognizer.networks import MLP
-
-SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "support" / "emnist"
-
-os.environ["CUDA_VISIBLE_DEVICES"] = ""
-
-
-class TestCharacterPredictor(unittest.TestCase):
- """Tests for the CharacterPredictor class."""
-
- def test_filename(self) -> None:
- """Test that CharacterPredictor correctly predicts on a single image, for serveral test images."""
- network_fn_ = MLP
- predictor = CharacterPredictor(network_fn=network_fn_)
-
- for filename in SUPPORT_DIRNAME.glob("*.png"):
- pred, conf = predictor.predict(str(filename))
- logger.info(
- f"Prediction: {pred} at confidence: {conf} for image with character {filename.stem}"
- )
- self.assertEqual(pred, filename.stem)
- self.assertGreater(conf, 0.7)
diff --git a/tests/test_line_predictor.py b/tests/test_line_predictor.py
deleted file mode 100644
index eede4d4..0000000
--- a/tests/test_line_predictor.py
+++ /dev/null
@@ -1,35 +0,0 @@
-"""Tests for LinePredictor."""
-import os
-from pathlib import Path
-import unittest
-
-
-import editdistance
-import numpy as np
-
-from text_recognizer.datasets import IamLinesDataset
-from text_recognizer.line_predictor import LinePredictor
-import text_recognizer.util as util
-
-SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "support"
-
-os.environ["CUDA_VISIBLE_DEVICES"] = ""
-
-
-class TestEmnistLinePredictor(unittest.TestCase):
- """Test LinePredictor class on the EmnistLines dataset."""
-
- def test_filename(self) -> None:
- """Test that LinePredictor correctly predicts on single images, for several test images."""
- predictor = LinePredictor(
- dataset="EmnistLineDataset", network_fn="CNNTransformer"
- )
-
- for filename in (SUPPORT_DIRNAME / "emnist_lines").glob("*.png"):
- pred, conf = predictor.predict(str(filename))
- true = str(filename.stem)
- edit_distance = editdistance.eval(pred, true) / len(pred)
- print(
- f'Pred: "{pred}" | Confidence: {conf} | True: {true} | Edit distance: {edit_distance}'
- )
- self.assertLess(edit_distance, 0.2)
diff --git a/tests/test_paragraph_text_recognizer.py b/tests/test_paragraph_text_recognizer.py
deleted file mode 100644
index 3e280b9..0000000
--- a/tests/test_paragraph_text_recognizer.py
+++ /dev/null
@@ -1,37 +0,0 @@
-"""Test for ParagraphTextRecognizer class."""
-import os
-from pathlib import Path
-import unittest
-
-from text_recognizer.paragraph_text_recognizer import ParagraphTextRecognizor
-import text_recognizer.util as util
-
-
-SUPPORT_DIRNAME = Path(__file__).parents[0].resolve() / "support" / "iam_paragraph"
-
-# Prevent using GPU.
-os.environ["CUDA_VISIBLE_DEVICES"] = ""
-
-
-class TestParagraphTextRecognizor(unittest.TestCase):
- """Test that it can take non-square images of max dimension larger than 256px."""
-
- def test_filename(self) -> None:
- """Test model on support image."""
- line_predictor_args = {
- "dataset": "EmnistLineDataset",
- "network_fn": "CNNTransformer",
- }
- line_detector_args = {"dataset": "EmnistLineDataset", "network_fn": "UNet"}
- model = ParagraphTextRecognizor(
- line_predictor_args=line_predictor_args,
- line_detector_args=line_detector_args,
- )
- num_text_lines_by_name = {"a01-000u-cropped": 7}
- for filename in (SUPPORT_DIRNAME).glob("*.jpg"):
- full_image = util.read_image(str(filename), grayscale=True)
- predicted_text, line_region_crops = model.predict(full_image)
- print(predicted_text)
- self.assertTrue(
- len(line_region_crops), num_text_lines_by_name[filename.stem]
- )