Skip to content

Commit

Permalink
speed up testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 committed Sep 6, 2024
1 parent 52b6c97 commit a9f54d9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 63 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/mr_ci_text_spotting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install DPText-DETR
run: |
git clone https://github.com/maps-as-data/DPText-DETR.git
python -m pip install 'git+https://github.com/maps-as-data/DPText-DETR.git' --force-reinstall # Install DPText-DETR
python -m pip install 'git+https://github.com/maps-as-data/DPText-DETR.git' # Install DPText-DETR
python -m pip install numpy==1.26.4
wget https://huggingface.co/rwood-97/DPText_DETR_ArT_R_50_poly/resolve/main/art_final.pth
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Install DeepSolo
run: |
git clone https://github.com/maps-as-data/DeepSolo.git
python -m pip install 'git+https://github.com/maps-as-data/DeepSolo.git' --force-reinstall # Install DeepSolo
python -m pip install 'git+https://github.com/maps-as-data/DeepSolo.git' # Install DeepSolo
python -m pip install numpy==1.26.4
wget https://huggingface.co/rwood-97/DeepSolo_ic15_res50/resolve/main/ic15_res50_finetune_synth-tt-mlt-13-15-textocr.pth
Expand All @@ -80,7 +80,7 @@ jobs:
- name: Install MapTextPipeline
run: |
git clone https://github.com/maps-as-data/MapTextPipeline.git
python -m pip install 'git+https://github.com/maps-as-data/MapTextPipeline.git' --force-reinstall # Install MapTextPipeline
python -m pip install 'git+https://github.com/maps-as-data/MapTextPipeline.git' # Install MapTextPipeline
python -m pip install "numpy<2.0.0"
wget https://huggingface.co/rwood-97/MapTextPipeline_rumsey/resolve/main/rumsey-finetune.pth
Expand Down
41 changes: 21 additions & 20 deletions test_text_spotting/test_deepsolo_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
)


@pytest.fixture
@pytest.fixture(scope="session")
def sample_dir():
return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"


@pytest.fixture
@pytest.fixture(scope="session")
def init_dataframes(sample_dir, tmp_path):
"""Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes.
Returns
Expand All @@ -44,7 +44,7 @@ def init_dataframes(sample_dir, tmp_path):
return parent_df, patch_df


@pytest.fixture
@pytest.fixture(scope="session")
def init_runner(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DeepSoloRunner(
Expand All @@ -55,6 +55,13 @@ def init_runner(init_dataframes):
return runner


@pytest.fixture(scope="session")
def runner_run_all(init_runner):
runner = init_runner
_ = runner.run_all()
return runner


def test_deepsolo_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DeepSoloRunner(
Expand Down Expand Up @@ -122,42 +129,37 @@ def test_deepsolo_run_all(init_runner):
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out.keys()
assert isinstance(out["patch-0-0-800-40-#mapreader_text.png#.png"], list)
# dataframe
runner.patch_predictions = {}
out = runner.run_all(return_dataframe=True)
out = runner._dict_to_dataframe(runner.patch_predictions, geo=False, parent=False)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(["image_id", "geometry", "text", "score"])
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out["image_id"].values


def test_deepsolo_convert_to_parent(init_runner):
runner = init_runner
_ = runner.run_all()
def test_deepsolo_convert_to_parent(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_parent_pixel_bounds()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_parent_pixel_bounds(return_dataframe=True)
out = runner._dict_to_dataframe(runner.parent_predictions, geo=False, parent=True)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "text", "score"]
)
assert "mapreader_text.png" in out["image_id"].values


def test_deepsolo_convert_to_parent_coords(init_runner):
runner = init_runner
_ = runner.run_all()
def test_deepsolo_convert_to_parent_coords(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_coords()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_coords(return_dataframe=True)
out = runner._dict_to_dataframe(runner.geo_predictions, geo=True, parent=True)
assert isinstance(out, gpd.GeoDataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "crs", "text", "score"]
Expand All @@ -180,12 +182,12 @@ def test_deepsolo_deduplicate(sample_dir, tmp_path):
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)
len_before = len(out["mapreader_text.png"])
runner.patch_predictions = {}
runner.parent_predictions = {}
out_07 = runner.convert_to_parent_pixel_bounds(deduplicate=True)
len_07 = len(out_07["mapreader_text.png"])
print(len_before, len_07)
assert len_before >= len_07
runner.patch_predictions = {}
runner.parent_predictions = {}
out_05 = runner.convert_to_parent_pixel_bounds(deduplicate=True, min_ioa=0.5)
len_05 = len(out_05["mapreader_text.png"])
print(len_before, len_05)
Expand All @@ -203,9 +205,8 @@ def test_deepsolo_run_on_image(init_runner):
assert isinstance(out["instances"], Instances)


def test_deepsolo_save_to_geojson(init_runner, tmp_path):
runner = init_runner
_ = runner.run_all()
def test_deepsolo_save_to_geojson(runner_run_all, tmp_path):
runner = runner_run_all
_ = runner.convert_to_coords()
runner.save_to_geojson(f"{tmp_path}/text.geojson")
assert os.path.exists(f"{tmp_path}/text.geojson")
Expand Down
41 changes: 21 additions & 20 deletions test_text_spotting/test_dptext_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
)


@pytest.fixture
@pytest.fixture(scope="session")
def sample_dir():
return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"


@pytest.fixture
@pytest.fixture(scope="session")
def init_dataframes(sample_dir, tmp_path):
"""Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes.
Returns
Expand All @@ -44,7 +44,7 @@ def init_dataframes(sample_dir, tmp_path):
return parent_df, patch_df


@pytest.fixture
@pytest.fixture(scope="session")
def init_runner(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DPTextDETRRunner(
Expand All @@ -55,6 +55,13 @@ def init_runner(init_dataframes):
return runner


@pytest.fixture(scope="session")
def runner_run_all(init_runner):
runner = init_runner
_ = runner.run_all()
return runner


def test_dptext_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DPTextDETRRunner(
Expand Down Expand Up @@ -122,40 +129,35 @@ def test_dptext_run_all(init_runner):
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out.keys()
assert isinstance(out["patch-0-0-800-40-#mapreader_text.png#.png"], list)
# dataframe
runner.patch_predictions = {}
out = runner.run_all(return_dataframe=True)
out = runner._dict_to_dataframe(runner.patch_predictions, geo=False, parent=False)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(["image_id", "geometry", "score"])
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out["image_id"].values


def test_dptext_convert_to_parent(init_runner):
runner = init_runner
_ = runner.run_all()
def test_dptext_convert_to_parent(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_parent_pixel_bounds()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_parent_pixel_bounds(return_dataframe=True)
out = runner._dict_to_dataframe(runner.parent_predictions, geo=False, parent=True)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(["image_id", "patch_id", "geometry", "score"])
assert "mapreader_text.png" in out["image_id"].values


def test_dptext_convert_to_parent_coords(init_runner):
runner = init_runner
_ = runner.run_all()
def test_dptext_convert_to_parent_coords(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_coords()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_coords(return_dataframe=True)
out = runner._dict_to_dataframe(runner.geo_predictions, geo=True, parent=True)
assert isinstance(out, gpd.GeoDataFrame)
assert set(out.columns) == set(["image_id", "patch_id", "geometry", "crs", "score"])
assert "mapreader_text.png" in out["image_id"].values
Expand All @@ -176,12 +178,12 @@ def test_dptext_deduplicate(sample_dir, tmp_path):
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)
len_before = len(out["mapreader_text.png"])
runner.patch_predictions = {}
runner.parent_predictions = {}
out_07 = runner.convert_to_parent_pixel_bounds(deduplicate=True)
len_07 = len(out_07["mapreader_text.png"])
print(len_before, len_07)
assert len_before >= len_07
runner.patch_predictions = {}
runner.parent_predictions = {}
out_05 = runner.convert_to_parent_pixel_bounds(deduplicate=True, min_ioa=0.5)
len_05 = len(out_05["mapreader_text.png"])
print(len_before, len_05)
Expand All @@ -199,9 +201,8 @@ def test_dptext_run_on_image(init_runner):
assert isinstance(out["instances"], Instances)


def test_dptext_save_to_geojson(init_runner, tmp_path):
runner = init_runner
_ = runner.run_all()
def test_dptext_save_to_geojson(runner_run_all, tmp_path):
runner = runner_run_all
_ = runner.convert_to_coords()
runner.save_to_geojson(f"{tmp_path}/text.geojson")
assert os.path.exists(f"{tmp_path}/text.geojson")
Expand Down
41 changes: 21 additions & 20 deletions test_text_spotting/test_maptext_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
)


@pytest.fixture
@pytest.fixture(scope="session")
def sample_dir():
return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"


@pytest.fixture
@pytest.fixture(scope="session")
def init_dataframes(sample_dir, tmp_path):
"""Initializes MapImages object (with metadata from csv and patches) and creates parent and patch dataframes.
Returns
Expand All @@ -44,7 +44,7 @@ def init_dataframes(sample_dir, tmp_path):
return parent_df, patch_df


@pytest.fixture
@pytest.fixture(scope="session")
def init_runner(init_dataframes):
parent_df, patch_df = init_dataframes
runner = MapTextRunner(
Expand All @@ -55,6 +55,13 @@ def init_runner(init_dataframes):
return runner


@pytest.fixture(scope="session")
def runner_run_all(init_runner):
runner = init_runner
_ = runner.run_all()
return runner


def test_maptext_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = MapTextRunner(
Expand Down Expand Up @@ -122,42 +129,37 @@ def test_maptext_run_all(init_runner):
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out.keys()
assert isinstance(out["patch-0-0-800-40-#mapreader_text.png#.png"], list)
# dataframe
runner.patch_predictions = {}
out = runner.run_all(return_dataframe=True)
out = runner._dict_to_dataframe(runner.patch_predictions, geo=False, parent=False)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(["image_id", "geometry", "text", "score"])
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out["image_id"].values


def test_maptext_convert_to_parent(init_runner):
runner = init_runner
_ = runner.run_all()
def test_maptext_convert_to_parent(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_parent_pixel_bounds()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_parent_pixel_bounds(return_dataframe=True)
out = runner._dict_to_dataframe(runner.patch_predictions, geo=False, parent=True)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "text", "score"]
)
assert "mapreader_text.png" in out["image_id"].values


def test_maptext_convert_to_parent_coords(init_runner):
runner = init_runner
_ = runner.run_all()
def test_maptext_convert_to_parent_coords(runner_run_all):
runner = runner_run_all
# dict
out = runner.convert_to_coords()
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
# dataframe
runner.parent_predictions = {}
out = runner.convert_to_coords(return_dataframe=True)
out = runner._dict_to_dataframe(runner.parent_predictions, geo=True, parent=True)
assert isinstance(out, gpd.GeoDataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "crs", "text", "score"]
Expand All @@ -180,12 +182,12 @@ def test_maptext_deduplicate(sample_dir, tmp_path):
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)
len_before = len(out["mapreader_text.png"])
runner.patch_predictions = {}
runner.parent_predictions = {}
out_07 = runner.convert_to_parent_pixel_bounds(deduplicate=True)
len_07 = len(out_07["mapreader_text.png"])
print(len_before, len_07)
assert len_before >= len_07
runner.patch_predictions = {}
runner.parent_predictions = {}
out_05 = runner.convert_to_parent_pixel_bounds(deduplicate=True, min_ioa=0.5)
len_05 = len(out_05["mapreader_text.png"])
print(len_before, len_05)
Expand All @@ -203,9 +205,8 @@ def test_maptext_run_on_image(init_runner):
assert isinstance(out["instances"], Instances)


def test_maptext_save_to_geojson(init_runner, tmp_path):
runner = init_runner
_ = runner.run_all()
def test_maptext_save_to_geojson(runner_run_all, tmp_path):
runner = runner_run_all
_ = runner.convert_to_coords()
runner.save_to_geojson(f"{tmp_path}/text.geojson")
assert os.path.exists(f"{tmp_path}/text.geojson")
Expand Down

0 comments on commit a9f54d9

Please sign in to comment.