Skip to content

Commit

Permalink
fix deepsolo tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 committed Nov 27, 2024
1 parent a4127b7 commit b7e3b0b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tests/test_text_spotting/test_deepsolo_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from mapreader import DeepSoloRunner
from mapreader.load import MapImages
from mapreader.spot_text.dataclasses import Prediction
from mapreader.spot_text.dataclasses import ParentPrediction, PatchPrediction

# use cloned DeepSolo path if running in github actions
DEEPSOLO_PATH = (
Expand Down Expand Up @@ -143,11 +143,20 @@ def test_deepsolo_run_all(init_runner, mock_response):
assert isinstance(out, dict)
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)
assert isinstance(out["patch-0-0-800-40-#mapreader_text.png#.png"][0], Prediction)
assert isinstance(
out["patch-0-0-800-40-#mapreader_text.png#.png"][0], PatchPrediction
)
# dataframe
out = runner._dict_to_dataframe(runner.patch_predictions)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(["image_id", "geometry", "text", "score"])
assert set(out.columns) == set(
[
"image_id",
"pixel_geometry",
"text",
"score",
]
)
assert "patch-0-0-800-40-#mapreader_text.png#.png" in out["image_id"].values


Expand All @@ -158,12 +167,12 @@ def test_deepsolo_convert_to_parent(runner_run_all, mock_response):
assert isinstance(out, dict)
assert "mapreader_text.png" in out.keys()
assert isinstance(out["mapreader_text.png"], list)
assert isinstance(out["mapreader_text.png"][0], Prediction)
assert isinstance(out["mapreader_text.png"][0], ParentPrediction)
# dataframe
out = runner._dict_to_dataframe(runner.parent_predictions)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "text", "score"]
["image_id", "patch_id", "pixel_geometry", "text", "score"]
)
assert "mapreader_text.png" in out["image_id"].values

Expand All @@ -179,7 +188,7 @@ def test_deepsolo_convert_to_parent_coords(runner_run_all, mock_response):
out = runner._dict_to_dataframe(runner.geo_predictions)
assert isinstance(out, gpd.GeoDataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "crs", "text", "score"]
["image_id", "patch_id", "pixel_geometry", "geometry", "crs", "text", "score"]
)
assert "mapreader_text.png" in out["image_id"].values
assert out.crs == runner.parent_df.crs
Expand Down Expand Up @@ -230,7 +239,7 @@ def test_deepsolo_save_to_geojson(runner_run_all, tmp_path, mock_response):
gdf = gpd.read_file(f"{tmp_path}/text.geojson")
assert isinstance(gdf, gpd.GeoDataFrame)
assert set(gdf.columns) == set(
["image_id", "patch_id", "geometry", "crs", "text", "score"]
["image_id", "patch_id", "pixel_geometry", "geometry", "crs", "text", "score"]
)


Expand All @@ -244,7 +253,7 @@ def test_deepsolo_search_preds(runner_run_all, mock_response):
out = runner.search_preds("map", ignore_case=True, return_dataframe=True)
assert isinstance(out, pd.DataFrame)
assert set(out.columns) == set(
["image_id", "patch_id", "geometry", "text", "score"]
["image_id", "patch_id", "pixel_geometry", "text", "score"]
)
assert "mapreader_text.png" in out["image_id"].values
out = runner.search_preds("somethingelse", ignore_case=True, return_dataframe=True)
Expand All @@ -267,7 +276,7 @@ def test_deepsolo_save_search_results(runner_run_all, tmp_path, mock_response):
gdf = gpd.read_file(f"{tmp_path}/search_results.geojson")
assert isinstance(gdf, gpd.GeoDataFrame)
assert set(gdf.columns) == set(
["image_id", "patch_id", "geometry", "crs", "text", "score"]
["image_id", "patch_id", "pixel_geometry", "geometry", "crs", "text", "score"]
)
assert "mapreader_text.png" in gdf["image_id"].values

Expand Down

0 comments on commit b7e3b0b

Please sign in to comment.