Skip to content

Commit

Permalink
add initial tests for all 3 pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 committed Sep 4, 2024
1 parent 25be652 commit 4b74728
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 8 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/mr_ci_text_spotting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 41 additions & 0 deletions test_text_spotting/test_deepsolo_runner.py
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions test_text_spotting/test_dptext_runner.py
Original file line number Diff line number Diff line change
@@ -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)
41 changes: 41 additions & 0 deletions test_text_spotting/test_maptext_runner.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 0 additions & 5 deletions tests/test_text_spotting/test_import.py

This file was deleted.

0 comments on commit 4b74728

Please sign in to comment.