From 4b74728df0caa6d389ab8e2a65f93f6a2a61873a Mon Sep 17 00:00:00 2001 From: Rosie Wood Date: Wed, 4 Sep 2024 16:04:33 +0100 Subject: [PATCH] add initial tests for all 3 pipelines --- .github/workflows/mr_ci_text_spotting.yml | 23 ++++++++++-- test_text_spotting/test_deepsolo_runner.py | 41 ++++++++++++++++++++++ test_text_spotting/test_dptext_runner.py | 41 ++++++++++++++++++++++ test_text_spotting/test_maptext_runner.py | 41 ++++++++++++++++++++++ tests/test_text_spotting/test_import.py | 5 --- 5 files changed, 143 insertions(+), 8 deletions(-) create mode 100644 test_text_spotting/test_deepsolo_runner.py create mode 100644 test_text_spotting/test_dptext_runner.py create mode 100644 test_text_spotting/test_maptext_runner.py delete mode 100644 tests/test_text_spotting/test_import.py diff --git a/.github/workflows/mr_ci_text_spotting.yml b/.github/workflows/mr_ci_text_spotting.yml index c9b88f22..4966b4fd 100644 --- a/.github/workflows/mr_ci_text_spotting.yml +++ b/.github/workflows/mr_ci_text_spotting.yml @@ -60,7 +60,24 @@ jobs: CC=clang CXX=clang++ python -m pip install 'git+https://github.com/facebookresearch/detectron2.git' python -m detectron2.utils.collect_env python -m pip install ".[dev]" - python -m pip install 'git+https://github.com/maps-as-data/DPText-DETR.git' # Install DPText-DETR - - name: Run unittests - run: python -m pytest tests/test_text_spotting/ + - name: Install DPText-DETR and run unittests + run: | + git clone https://github.com/maps-as-data/DPText-DETR.git + python -m pip install DPText-DETR # Install DPText-DETR + wget https://huggingface.co/rwood-97/DPText_DETR_ArT_R_50_poly/resolve/main/art_final.pth + python -m pytest test_text_spotting/test_dptext_runner.py + + - name: Install DeepSolo and run unittests + run: | + git clone https://github.com/maps-as-data/DeepSolo.git + python -m pip install DeepSolo # Install DeepSolo + wget https://huggingface.co/rwood-97/DeepSolo_ic15_res50/resolve/main/ic15_res50_finetune_synth-tt-mlt-13-15-textocr.pth + python -m pytest test_text_spotting/test_deepsolo_runner.py + + - name: Install MapTextPipeline and run unittests + run: | + git clone https://github.com/maps-as-data/MapTextPipeline.git + python -m pip install MapTextPipeline # Install MapTextPipeline + wget https://huggingface.co/rwood-97/MapTextPipeline_rumsey/resolve/main/rumsey-finetune.pth + python -m pytest test_text_spotting/test_maptext_runner.py diff --git a/test_text_spotting/test_deepsolo_runner.py b/test_text_spotting/test_deepsolo_runner.py new file mode 100644 index 00000000..1edef9d2 --- /dev/null +++ b/test_text_spotting/test_deepsolo_runner.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +import pathlib + +import pytest +from detectron2.engine import DefaultPredictor + +from mapreader import DeepSoloRunner +from mapreader.load import MapImages + + +@pytest.fixture +def sample_dir(): + return pathlib.Path(__file__).resolve().parent.parent / "sample_files" + + +@pytest.fixture +def init_dataframes(sample_dir, tmp_path): + """Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes. + Returns + ------- + tuple + path to parent and patch dataframes + """ + maps = MapImages(f"{sample_dir}/cropped_74488689.png") + maps.add_metadata(f"{sample_dir}/ts_downloaded_maps.csv") + maps.patchify_all(patch_size=3, path_save=tmp_path) # gives 9 patches + maps.add_center_coord(tree_level="parent") + maps.add_patch_polygons() + parent_df, patch_df = maps.convert_images() + return parent_df, patch_df + + +def test_dptext_init(init_dataframes): + parent_df, patch_df = init_dataframes + runner = DeepSoloRunner( + parent_df, + patch_df, + ) + assert isinstance(runner, DeepSoloRunner) + assert isinstance(runner.predictor, DefaultPredictor) diff --git a/test_text_spotting/test_dptext_runner.py b/test_text_spotting/test_dptext_runner.py new file mode 100644 index 00000000..01ae5cfa --- /dev/null +++ b/test_text_spotting/test_dptext_runner.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +import pathlib + +import pytest +from detectron2.engine import DefaultPredictor + +from mapreader import DPTextDETRRunner +from mapreader.load import MapImages + + +@pytest.fixture +def sample_dir(): + return pathlib.Path(__file__).resolve().parent.parent / "sample_files" + + +@pytest.fixture +def init_dataframes(sample_dir, tmp_path): + """Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes. + Returns + ------- + tuple + path to parent and patch dataframes + """ + maps = MapImages(f"{sample_dir}/cropped_74488689.png") + maps.add_metadata(f"{sample_dir}/ts_downloaded_maps.csv") + maps.patchify_all(patch_size=3, path_save=tmp_path) # gives 9 patches + maps.add_center_coord(tree_level="parent") + maps.add_patch_polygons() + parent_df, patch_df = maps.convert_images() + return parent_df, patch_df + + +def test_dptext_init(init_dataframes): + parent_df, patch_df = init_dataframes + runner = DPTextDETRRunner( + parent_df, + patch_df, + ) + assert isinstance(runner, DPTextDETRRunner) + assert isinstance(runner.predictor, DefaultPredictor) diff --git a/test_text_spotting/test_maptext_runner.py b/test_text_spotting/test_maptext_runner.py new file mode 100644 index 00000000..d29a4854 --- /dev/null +++ b/test_text_spotting/test_maptext_runner.py @@ -0,0 +1,41 @@ +from __future__ import annotations + +import pathlib + +import pytest +from detectron2.engine import DefaultPredictor + +from mapreader import MapTextRunner +from mapreader.load import MapImages + + +@pytest.fixture +def sample_dir(): + return pathlib.Path(__file__).resolve().parent.parent / "sample_files" + + +@pytest.fixture +def init_dataframes(sample_dir, tmp_path): + """Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes. + Returns + ------- + tuple + path to parent and patch dataframes + """ + maps = MapImages(f"{sample_dir}/cropped_74488689.png") + maps.add_metadata(f"{sample_dir}/ts_downloaded_maps.csv") + maps.patchify_all(patch_size=3, path_save=tmp_path) # gives 9 patches + maps.add_center_coord(tree_level="parent") + maps.add_patch_polygons() + parent_df, patch_df = maps.convert_images() + return parent_df, patch_df + + +def test_dptext_init(init_dataframes): + parent_df, patch_df = init_dataframes + runner = MapTextRunner( + parent_df, + patch_df, + ) + assert isinstance(runner, MapTextRunner) + assert isinstance(runner.predictor, DefaultPredictor) diff --git a/tests/test_text_spotting/test_import.py b/tests/test_text_spotting/test_import.py deleted file mode 100644 index 8ec103f8..00000000 --- a/tests/test_text_spotting/test_import.py +++ /dev/null @@ -1,5 +0,0 @@ - -def test_import(): - from mapreader import ( - DPTextDETRRunner, - ) \ No newline at end of file