diff --git a/.github/workflows/mr_ci.yml b/.github/workflows/mr_ci.yml
index 0c93577d..a82bedce 100644
--- a/.github/workflows/mr_ci.yml
+++ b/.github/workflows/mr_ci.yml
@@ -42,7 +42,8 @@ jobs:
- name: Test with pytest
run: |
- python -m pytest --cov=./ --cov-report=xml ./tests
+ python -m pytest ./tests --ignore=tests/test_text_spotting/
+
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
diff --git a/.github/workflows/mr_ci_text_spotting.yml b/.github/workflows/mr_ci_text_spotting.yml
index 7e40217c..c7ec1cfe 100644
--- a/.github/workflows/mr_ci_text_spotting.yml
+++ b/.github/workflows/mr_ci_text_spotting.yml
@@ -5,31 +5,30 @@ on: [push]
# Run linter with github actions for quick feedbacks.
jobs:
-
- macos_tests:
- runs-on: macos-latest
- # run on PRs, or commits to facebookresearch (not internal)
+ all_tests:
strategy:
- fail-fast: false
matrix:
- torch: ["1.13.1", "2.2.2"]
- include:
- - torch: "1.13.1"
- torchvision: "0.14.1"
- - torch: "2.2.2"
- torchvision: "0.17.2"
-
+ os: [ubuntu-latest, windows-latest]
+ fail-fast: false
env:
# point datasets to ~/.torch so it's cached by CI
DETECTRON2_DATASETS: ~/.torch/datasets
+
+ runs-on: ${{ matrix.os }}
steps:
- - name: Checkout
- uses: actions/checkout@v2
+ - uses: actions/checkout@v2
+ with:
+ fetch-depth: 2
- - name: Set up Python 3.9
+ - name: Set up Python 3.11
uses: actions/setup-python@v2
with:
- python-version: 3.9
+ python-version: 3.11
+
+ - name: Install ninja-build tool
+ uses: seanmiddleditch/gha-setup-ninja@v5
+ with:
+ version: 1.12.1
- name: Update pip
run: |
@@ -38,52 +37,45 @@ jobs:
- name: Install dependencies
run: |
- python -m pip install -U pip
- python -m pip install wheel ninja opencv-python-headless onnx pytest-xdist
- python -m pip install numpy==1.26.4
- python -m pip install torch==${{matrix.torch}} torchvision==${{matrix.torchvision}} -f https://download.pytorch.org/whl/torch_stable.html
- # install from github to get latest; install iopath first since fvcore depends on it
- python -m pip install -U 'git+https://github.com/facebookresearch/iopath'
- python -m pip install -U 'git+https://github.com/facebookresearch/fvcore'
- wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
- python collect_env.py
+ python -m pip install wheel
+ python -m pip install numpy==1.26.4 torch==2.2.2 torchvision==0.17.2 -f https://download.pytorch.org/whl/torch_stable.html
+ python -m pip install ".[dev]" # not text ones as windows install fails
+ python -m pip install pytest-cov
+ python -m pip install 'git+https://github.com/facebookresearch/detectron2.git'
- - name: Build and install
- run: |
- 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]"
-
- - name: Install DPText-DETR
+ - name: Clone + 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' # 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
-
- - name: Run DPText-DETR unittests
- run: |
- python -m pytest test_text_spotting/test_dptext_runner.py
-
+ python -m pip install ./DPText-DETR
- - name: Install DeepSolo
+ - name: Clone + 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 --no-deps # 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
+ python -m pip install ./DeepSolo
- - name: Run DeepSolo unittests
+ - name: Clone + install MapTextPipeline
run: |
- python -m pytest test_text_spotting/test_deepsolo_runner.py
+ git clone https://github.com/maps-as-data/MapTextPipeline.git
+ python -m pip install ./MapTextPipeline
- - name: Install MapTextPipeline
+ - name: Hugging Face CLI
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 --no-deps # Install MapTextPipeline
- python -m pip install "numpy<2.0.0"
- wget https://huggingface.co/rwood-97/MapTextPipeline_rumsey/resolve/main/rumsey-finetune.pth
+ pip install -U "huggingface_hub[cli]"
+ huggingface-cli download rwood-97/DPText_DETR_ArT_R_50_poly art_final.pth --local-dir .
+ huggingface-cli download rwood-97/DeepSolo_ic15_res50 ic15_res50_finetune_synth-tt-mlt-13-15-textocr.pth --local-dir .
+ huggingface-cli download rwood-97/MapTextPipeline_rumsey rumsey-finetune.pth --local-dir .
- - name: Run MapTextPipeline unittests
+ - name: Test with pytest
run: |
- python -m pytest test_text_spotting/test_maptext_runner.py
+ python -m pytest --cov=./ --cov-report=xml ./tests
+
+ - name: Upload coverage to Codecov
+ uses: codecov/codecov-action@v4
+ with:
+ token: ${{ secrets.CODECOV_TOKEN }}
+ directory: ./coverage/reports/
+ env_vars: OS,PYTHON
+ fail_ci_if_error: false
+ files: ./coverage.xml,!./cache
+ flags: unittests
+ name: codecov-umbrella
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2eccb22..5e428186 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,7 +15,11 @@ The following table shows which versions of MapReader are compatible with which
## Pre-release
-_ADD NEW CHANGES HERE_
+### Added
+
+- Ability to install all three text-spotting frameworks at same time ([#514](https://github.com/maps-as-data/MapReader/pull/514))
+- Can install text spotting dependencies using `pip install mapreader[text]` ([#514](https://github.com/maps-as-data/MapReader/pull/514))
+- Text spotting code now covered by tests ([#514](https://github.com/maps-as-data/MapReader/pull/514))
## [v1.4.1](https://github.com/Living-with-machines/MapReader/releases/tag/v1.4.1) (2024-09-17)
diff --git a/docs/source/getting-started/installation-instructions/2-install-mapreader.rst b/docs/source/getting-started/installation-instructions/2-install-mapreader.rst
index 2c344b1f..86b04715 100644
--- a/docs/source/getting-started/installation-instructions/2-install-mapreader.rst
+++ b/docs/source/getting-started/installation-instructions/2-install-mapreader.rst
@@ -7,36 +7,49 @@ Method 1: Install from `PyPI `_
If you want to use the latest stable release of MapReader and do not want/need access to the worked examples or MapReader code, we recommend installing from PyPI.
This is probably the easiest way to install MapReader.
-- Install ``mapreader``:
+To install ``mapreader`` without the text spotting dependencies (i.e. just the classification pipeline):
- .. code-block:: bash
+.. code-block:: bash
- pip install mapreader
+ pip install mapreader
-.. note:: To install the dev dependencies too use ``pip install "mapreader[dev]"`` instead.
+Or, to install ``mapreader`` with the text spotting dependencies:
+
+.. code-block:: bash
+
+ pip install "mapreader[text]"
+
+.. note:: To install the dev dependencies too use ``pip install "mapreader[dev]"`` or ``pip install "mapreader[text, dev]"``.
Method 2: Install from source
-----------------------------
-If you want to keep up with the latest changes to MapReader, or want/need easy access to the worked examples or MapReader code, we reccommend installing from source.
+If you want to keep up with the latest changes to MapReader, or want/need easy access to the worked examples or MapReader code, we recommend installing from source.
This method will create a ``MapReader`` directory on your machine which will contain all the MapReader code, docs and worked examples.
.. note:: You will need to have `git `__ installed to use this method. If you are using conda, this can be done by running ``conda install git``. Otherwise, you should install git by following the instructions on `their website `__.
-- Clone the ``mapreader`` source code from the `MapReader GitHub repository `_:
+Clone the ``mapreader`` source code from the `MapReader GitHub repository `_:
+
+.. code-block:: bash
+
+ git clone https://github.com/Living-with-machines/MapReader.git
+
+Then, to install ``mapreader`` without the text spotting dependencies:
- .. code-block:: bash
+.. code-block:: bash
- git clone https://github.com/Living-with-machines/MapReader.git
+ cd MapReader
+ pip install -v -e .
-- Install ``mapreader``:
+Or, to install ``mapreader`` with the text spotting dependencies:
- .. code-block:: bash
+.. code-block:: bash
- cd MapReader
- pip install -v -e .
+ cd MapReader
+ pip install -v -e ".[text]"
-.. note:: To install the dev dependencies too use ``pip install -v -e ".[dev]"`` instead.
+.. note:: To install the dev dependencies too use ``pip install -v -e ".[dev]"`` or ``pip install -v -e ".[text, dev]"``.
..
Method 3: Install via conda (**EXPERIMENTAL**)
diff --git a/docs/source/getting-started/troubleshooting-problems.rst b/docs/source/getting-started/troubleshooting-problems.rst
index 120ab8aa..89fd1c18 100644
--- a/docs/source/getting-started/troubleshooting-problems.rst
+++ b/docs/source/getting-started/troubleshooting-problems.rst
@@ -1,8 +1,8 @@
Troubleshooting
===============
-M1 mac
-------
+numpy/scikit-image issues with M1 mac
+-------------------------------------
If you are using an M1 mac and are having issues installing MapReader due to an error when installing numpy or scikit-image:
@@ -14,17 +14,19 @@ If you are using an M1 mac and are having issues installing MapReader due to an
pip install scikit-image==0.18.3
pip install mapreader
-- Try using conda to install the problem packages (edit as needed) and then pip to install MapReader:
-
- .. code-block:: bash
-
- conda install numpy==1.21.5
- conda install scikit-image==0.18.3
- pip install mapreader
-
- Alternatively, you can try using a different version of openBLAS when installing:
.. code-block:: bash
brew install openblas
OPENBLAS="$(brew --prefix openblas)" pip install mapreader
+
+
+detectron2 issues on Windows
+----------------------------
+
+If you are having issues installing detectron2 and running a windows machine, please try the following:
+
+- Install `Visual Studio Build Tools `__.
+- Follow instructions `here `__ to install the required packages. (The format might be different in newer versions of Visual Studio Build Tools, so you might need to look up the specific package names.
+- Once this is done, try rerunning the installation of detectron2 (`pip install "mapreader[text]"`)
diff --git a/docs/source/using-mapreader/step-by-step-guide/6-spot-text.rst b/docs/source/using-mapreader/step-by-step-guide/6-spot-text.rst
index 47777f71..34a54733 100644
--- a/docs/source/using-mapreader/step-by-step-guide/6-spot-text.rst
+++ b/docs/source/using-mapreader/step-by-step-guide/6-spot-text.rst
@@ -1,7 +1,7 @@
Spot text
=========
-MapReader implements three new frameworks for spotting text on maps:
+MapReader implements three frameworks for spotting text on maps:
- ``DPTextDETRRunner`` - This is used to detect text on maps using `DPTextDETR `__ and outputs bounding boxes and scores.
- ``DeepSoloRunner`` - This is used to detect and recognize text on maps using `DeepSolo `__ and outputs bounding boxes, text and scores.
@@ -9,80 +9,18 @@ MapReader implements three new frameworks for spotting text on maps:
We recommend using the ``MapTextPipeline`` for most use cases as it has been used to train a model on a sample of David Rumsey maps and so should work best for map text spotting.
-Install dependencies
---------------------
+Installing dependencies
+-----------------------
-To run text spotting with MapReader, you will need to install the required dependencies. These are listed below:
+To run text spotting with MapReader, you will need to install the required dependencies.
+Refer to our :doc:`installation instructions ` for guidance on how to install these.
-.. note:: We have our own forks of the ``DPTextDETRRunner``, ``DeepSolo`` and ``MapTextPipeline`` repos to enable them to work on CPU. Please use our forks but remember to cite the original authors in your work!
-
-Detectron2
-~~~~~~~~~~~
-
-Detectron2 is a popular object detection library built by Facebook AI Research.
-The main repo is available `here `__.
-
-To install, run the following commands in your terminal:
-
-.. code:: bash
-
- git clone https://github.com/facebookresearch/detectron2.git
- cd detectron2
- pip install .
-
-
-.. admonition:: Detectron2 issues for windows users
- :class: dropdown
-
- If you are on a windows machine and are having trouble installing Detectron2, you can try the following:
- - Install `Visual Studio Build Tools `__.
- - Follow instructions `here `__ to install the required packages. (The format might be different in newer versions of Visual Studio Build Tools, so you might need to look up the specific package names.)
-
- Once this is done, retry installing Detectron2.
-
-You should then **pick one** of the following to install:
-
-.. note:: Since the DPText-DETR, DeepSolo and MapTextPipeline frameworks are built on top of `AdelaiDet `__, you won't be able to install them at the same. To get around this, you can set up three different conda environments, one for each framework. This will allow you to switch between them as needed.
-
-DPTextDETR
-~~~~~~~~~~~
-
-Our fork for DPText-DETR is available `here `__.
-
-To install, run the following commands in your terminal:
-
-.. code:: bash
-
- git clone https://github.com/rwood-97/DPText-DETR.git
- cd DPText-DETR
- pip install .
-
-DeepSolo
-~~~~~~~~
-
-Our fork for DeepSolo is available `here `__
-
-To install, run the following commands in your terminal:
-
-.. code:: bash
-
- git clone https://github.com/rwood-97/DeepSolo.git
- cd DeepSolo
- pip install .
-
-MapTextPipeline
-~~~~~~~~~~~~~~~
-
-Our fork for MapTextPipeline is available `here `__
-
-To install, run the following commands in your terminal:
-
-.. code:: bash
-
- git clone https://github.com/rwood-97/MapTextPipeline.git
- cd MapTextPipeline
- pip install .
+Assuming your installation is successful, you will have installed the following:
+- detectron2 - This is a popular object detection library built by Facebook AI Research. The main repo is available `here `__.
+- DPTextDETR - Our fork for DPText-DETR is available `here `__.
+- DeepSolo - Our fork for DeepSolo is available `here `__
+- MapTextPipeline - Our fork for MapTextPipeline is available `here `__
Advice for patch size
---------------------
diff --git a/mapreader/spot_text/deepsolo_runner.py b/mapreader/spot_text/deepsolo_runner.py
index 4b7d0832..5901e0aa 100644
--- a/mapreader/spot_text/deepsolo_runner.py
+++ b/mapreader/spot_text/deepsolo_runner.py
@@ -4,27 +4,21 @@
import pickle
try:
- import adet
+ from detectron2.engine import DefaultPredictor
+except ImportError:
+ raise ImportError("[ERROR] Please install Detectron2")
+
+try:
+ import deepsolo # noqa
except ImportError:
raise ImportError(
- "[ERROR] Please install DeepSolo from the following link: https://github.com/rwood-97/DeepSolo"
+ "[ERROR] Please install DeepSolo from the following link: https://github.com/maps-as-data/DeepSolo"
)
import geopandas as gpd
import pandas as pd
import torch
-from adet.config import get_cfg
-
-try:
- from detectron2.engine import DefaultPredictor
-except ImportError:
- raise ImportError("[ERROR] Please install Detectron2")
-
-# first assert we are using the deep solo version of adet
-if adet.__version__ != "0.2.0-deepsolo":
- raise ImportError(
- "[ERROR] Please install DeepSolo from the following link: https://github.com/rwood-97/DeepSolo"
- )
+from deepsolo.config import get_cfg
from .rec_runner_base import RecRunner
diff --git a/mapreader/spot_text/dptext_detr_runner.py b/mapreader/spot_text/dptext_detr_runner.py
index c07873b2..910aea74 100644
--- a/mapreader/spot_text/dptext_detr_runner.py
+++ b/mapreader/spot_text/dptext_detr_runner.py
@@ -3,31 +3,24 @@
import pathlib
try:
- import adet
+ from detectron2.engine import DefaultPredictor
+except ImportError:
+ raise ImportError("[ERROR] Please install Detectron2")
+
+try:
+ import dptext_detr # noqa
except ImportError:
raise ImportError(
- "[ERROR] Please install DPText-DETR from the following link: https://github.com/rwood-97/DPText-DETR"
+ "[ERROR] Please install DPText-DETR from the following link: https://github.com/maps-as-data/DPText-DETR"
)
import geopandas as gpd
import numpy as np
import pandas as pd
import torch
-from adet.config import get_cfg
-
-try:
- from detectron2.engine import DefaultPredictor
-except ImportError:
- raise ImportError("[ERROR] Please install Detectron2")
-
+from dptext_detr.config import get_cfg
from shapely import MultiPolygon, Polygon
-# first assert we are using the dptext detr version of adet
-if adet.__version__ != "0.2.0-dptext-detr":
- raise ImportError(
- "[ERROR] Please install DPText-DETR from the following link: https://github.com/rwood-97/DPText-DETR"
- )
-
from .runner_base import Runner
diff --git a/mapreader/spot_text/maptext_runner.py b/mapreader/spot_text/maptext_runner.py
index c56568e6..95b48103 100644
--- a/mapreader/spot_text/maptext_runner.py
+++ b/mapreader/spot_text/maptext_runner.py
@@ -4,29 +4,21 @@
import pickle
try:
- import adet
+ from detectron2.engine import DefaultPredictor
+except ImportError:
+ raise ImportError("[ERROR] Please install Detectron2")
+
+try:
+ import maptextpipeline # noqa
except ImportError:
raise ImportError(
- "[ERROR] Please install DeepSolo from the following link: https://github.com/rwood-97/DeepSolo"
+ "[ERROR] Please install MapTextPipeline from the following link: https://github.com/maps-as-data/MapTextPipeline"
)
import geopandas as gpd
import pandas as pd
import torch
-from adet.config import get_cfg
-
-try:
- from detectron2.engine import DefaultPredictor
-except ImportError:
- raise ImportError("[ERROR] Please install Detectron2")
-
-from adet.utils.vitae_predictor import ViTAEPredictor
-
-# first assert we are using the deep solo version of adet
-if adet.__version__ != "0.2.0-maptextpipeline":
- raise ImportError(
- "[ERROR] Please install MapTextPipeline from the following link: https://github.com/rwood-97/MapTextPipeline"
- )
+from maptextpipeline.config import get_cfg
from .rec_runner_base import RecRunner
@@ -375,6 +367,8 @@ def __init__(
# setup the predictor
if "vitae" in cfg.MODEL.BACKBONE.NAME.lower():
+ from maptextpipeline.utils.vitae_predictor import ViTAEPredictor
+
self.predictor = ViTAEPredictor(cfg)
self.predictor = DefaultPredictor(cfg)
diff --git a/setup.py b/setup.py
index d1110917..2314c1b2 100644
--- a/setup.py
+++ b/setup.py
@@ -38,8 +38,8 @@
"nest-asyncio>=1.5.1,<2.0.0",
"scikit-image>=0.18.3",
"scikit-learn>=1.0.1,<2.0.0",
- "torch>=1.10.0",
- "torchvision>=0.11.1,<0.17.3",
+ "torch>=1.10.0,<=2.2.2",
+ "torchvision>=0.11.1,<=0.17.2",
"jupyter>=1.0.0,<2.0.0",
"ipykernel>=6.5.1,<7.0.0",
"ipywidgets>=8.0.0,<9.0.0",
@@ -70,6 +70,12 @@
"black>=23.7.0,<25.0.0",
"flake8>=6.0.0,<8.0.0",
],
+ "text": [
+ "detectron2 @ git+https://github.com/facebookresearch/detectron2.git",
+ "DPText-DETR @ git+https://github.com/maps-as-data/DPText-DETR.git",
+ "DeepSolo @ git+https://github.com/maps-as-data/DeepSolo.git",
+ "MapTextPipeline @ git+https://github.com/maps-as-data/MapTextPipeline.git",
+ ],
},
classifiers=[
"Development Status :: 3 - Alpha",
diff --git a/test_text_spotting/test_deepsolo_runner.py b/tests/test_text_spotting/test_deepsolo_runner.py
similarity index 91%
rename from test_text_spotting/test_deepsolo_runner.py
rename to tests/test_text_spotting/test_deepsolo_runner.py
index df9533d9..22a9713d 100644
--- a/test_text_spotting/test_deepsolo_runner.py
+++ b/tests/test_text_spotting/test_deepsolo_runner.py
@@ -4,29 +4,27 @@
import pathlib
import pickle
-import adet
import geopandas as gpd
import pandas as pd
import pytest
+from deepsolo.config import get_cfg
from detectron2.engine import DefaultPredictor
from detectron2.structures.instances import Instances
from mapreader import DeepSoloRunner
from mapreader.load import MapImages
-print(adet.__version__)
-
# use cloned DeepSolo path if running in github actions
-ADET_PATH = (
+DEEPSOLO_PATH = (
pathlib.Path("./DeepSolo/").resolve()
if os.getenv("GITHUB_ACTIONS") == "true"
- else pathlib.Path(os.getenv("ADET_PATH")).resolve()
+ else pathlib.Path(os.getenv("DEEPSOLO_PATH")).resolve()
)
@pytest.fixture
def sample_dir():
- return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"
+ return pathlib.Path(__file__).resolve().parent.parent / "sample_files"
@pytest.fixture
@@ -61,7 +59,7 @@ def init_runner(init_dataframes):
runner = DeepSoloRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
return runner
@@ -73,12 +71,17 @@ def runner_run_all(init_runner, mock_response):
return runner
+def test_get_cfg():
+ cfg = get_cfg()
+ assert "TEMPERATURE" in cfg["MODEL"]["TRANSFORMER"].keys()
+
+
def test_deepsolo_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DeepSoloRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
assert isinstance(runner, DeepSoloRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -93,7 +96,7 @@ def test_deepsolo_init_str(init_dataframes, tmp_path):
runner = DeepSoloRunner(
f"{tmp_path}/patch_df.csv",
parent_df=f"{tmp_path}/parent_df.csv",
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
assert isinstance(runner, DeepSoloRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -108,7 +111,7 @@ def test_deepsolo_init_pathlib(init_dataframes, tmp_path):
runner = DeepSoloRunner(
pathlib.Path(f"{tmp_path}/patch_df.csv"),
parent_df=pathlib.Path(f"{tmp_path}/parent_df.csv"),
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
assert isinstance(runner, DeepSoloRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -124,7 +127,7 @@ def test_deepsolo_init_tsv(init_dataframes, tmp_path):
f"{tmp_path}/patch_df.tsv",
parent_df=f"{tmp_path}/parent_df.tsv",
delimiter="\t",
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
assert isinstance(runner, DeepSoloRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -188,7 +191,7 @@ def test_deepsolo_deduplicate(sample_dir, tmp_path, mock_response):
runner = DeepSoloRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
+ cfg_file=f"{DEEPSOLO_PATH}/configs/R_50/IC15/finetune_150k_tt_mlt_13_15_textocr.yaml",
)
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)
diff --git a/test_text_spotting/test_dptext_runner.py b/tests/test_text_spotting/test_dptext_runner.py
similarity index 90%
rename from test_text_spotting/test_dptext_runner.py
rename to tests/test_text_spotting/test_dptext_runner.py
index 5006a129..cf62baa8 100644
--- a/test_text_spotting/test_dptext_runner.py
+++ b/tests/test_text_spotting/test_dptext_runner.py
@@ -4,29 +4,27 @@
import pathlib
import pickle
-import adet
import geopandas as gpd
import pandas as pd
import pytest
from detectron2.engine import DefaultPredictor
from detectron2.structures.instances import Instances
+from dptext_detr.config import get_cfg
from mapreader import DPTextDETRRunner
from mapreader.load import MapImages
-print(adet.__version__)
-
# use cloned DPText-DETR path if running in github actions
-ADET_PATH = (
+DPTEXT_DETR_PATH = (
pathlib.Path("./DPText-DETR/").resolve()
if os.getenv("GITHUB_ACTIONS") == "true"
- else pathlib.Path(os.getenv("ADET_PATH")).resolve()
+ else pathlib.Path(os.getenv("DPTEXT_DETR_PATH")).resolve()
)
@pytest.fixture
def sample_dir():
- return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"
+ return pathlib.Path(__file__).resolve().parent.parent / "sample_files"
@pytest.fixture
@@ -61,7 +59,7 @@ def init_runner(init_dataframes):
runner = DPTextDETRRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
return runner
@@ -73,12 +71,18 @@ def runner_run_all(init_runner, mock_response):
return runner
+def test_get_cfg():
+ cfg = get_cfg()
+ assert "USE_POLYGON" in cfg["MODEL"]["TRANSFORMER"].keys()
+ assert "DET_ONLY" in cfg["TEST"].keys()
+
+
def test_dptext_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = DPTextDETRRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
assert isinstance(runner, DPTextDETRRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -93,7 +97,7 @@ def test_dptext_init_str(init_dataframes, tmp_path):
runner = DPTextDETRRunner(
f"{tmp_path}/patch_df.csv",
parent_df=f"{tmp_path}/parent_df.csv",
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
assert isinstance(runner, DPTextDETRRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -108,7 +112,7 @@ def test_dptext_init_pathlib(init_dataframes, tmp_path):
runner = DPTextDETRRunner(
pathlib.Path(f"{tmp_path}/patch_df.csv"),
parent_df=pathlib.Path(f"{tmp_path}/parent_df.csv"),
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
assert isinstance(runner, DPTextDETRRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -124,7 +128,7 @@ def test_dptext_init_tsv(init_dataframes, tmp_path):
f"{tmp_path}/patch_df.tsv",
parent_df=f"{tmp_path}/parent_df.tsv",
delimiter="\t",
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
assert isinstance(runner, DPTextDETRRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -184,7 +188,7 @@ def test_dptext_deduplicate(sample_dir, tmp_path, mock_response):
runner = DPTextDETRRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
+ cfg_file=f"{DPTEXT_DETR_PATH}/configs/DPText_DETR/ArT/R_50_poly.yaml",
)
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)
diff --git a/test_text_spotting/test_maptext_runner.py b/tests/test_text_spotting/test_maptext_runner.py
similarity index 91%
rename from test_text_spotting/test_maptext_runner.py
rename to tests/test_text_spotting/test_maptext_runner.py
index d2214f85..2952013c 100644
--- a/test_text_spotting/test_maptext_runner.py
+++ b/tests/test_text_spotting/test_maptext_runner.py
@@ -4,29 +4,27 @@
import pathlib
import pickle
-import adet
import geopandas as gpd
import pandas as pd
import pytest
from detectron2.engine import DefaultPredictor
from detectron2.structures.instances import Instances
+from maptextpipeline.config import get_cfg
from mapreader import MapTextRunner
from mapreader.load import MapImages
-print(adet.__version__)
-
# use cloned MapTextPipeline path if running in github actions
-ADET_PATH = (
+MAPTEXTPIPELINE_PATH = (
pathlib.Path("./MapTextPipeline/").resolve()
if os.getenv("GITHUB_ACTIONS") == "true"
- else pathlib.Path(os.getenv("ADET_PATH")).resolve()
+ else pathlib.Path(os.getenv("MAPTEXTPIPELINE_PATH")).resolve()
)
@pytest.fixture
def sample_dir():
- return pathlib.Path(__file__).resolve().parent.parent / "tests" / "sample_files"
+ return pathlib.Path(__file__).resolve().parent.parent / "sample_files"
@pytest.fixture
@@ -61,7 +59,7 @@ def init_runner(init_dataframes):
runner = MapTextRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
return runner
@@ -73,12 +71,18 @@ def runner_run_all(init_runner, mock_response):
return runner
+def test_get_cfg():
+ cfg = get_cfg()
+ assert "TEMPERATURE" in cfg["MODEL"]["TRANSFORMER"].keys()
+ assert "FROZEN" in cfg["MODEL"]["TRANSFORMER"].keys()
+
+
def test_maptext_init(init_dataframes):
parent_df, patch_df = init_dataframes
runner = MapTextRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
assert isinstance(runner, MapTextRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -93,7 +97,7 @@ def test_maptext_init_str(init_dataframes, tmp_path):
runner = MapTextRunner(
f"{tmp_path}/patch_df.csv",
parent_df=f"{tmp_path}/parent_df.csv",
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
assert isinstance(runner, MapTextRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -108,7 +112,7 @@ def test_maptext_init_pathlib(init_dataframes, tmp_path):
runner = MapTextRunner(
pathlib.Path(f"{tmp_path}/patch_df.csv"),
parent_df=pathlib.Path(f"{tmp_path}/parent_df.csv"),
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
assert isinstance(runner, MapTextRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -124,7 +128,7 @@ def test_maptext_init_tsv(init_dataframes, tmp_path):
f"{tmp_path}/patch_df.tsv",
parent_df=f"{tmp_path}/parent_df.tsv",
delimiter="\t",
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
assert isinstance(runner, MapTextRunner)
assert isinstance(runner.predictor, DefaultPredictor)
@@ -188,7 +192,7 @@ def test_maptext_deduplicate(sample_dir, tmp_path, mock_response):
runner = MapTextRunner(
patch_df,
parent_df=parent_df,
- cfg_file=f"{ADET_PATH}/configs/ViTAEv2_S/rumsey/final_rumsey.yaml",
+ cfg_file=f"{MAPTEXTPIPELINE_PATH}/configs/ViTAEv2_S/rumsey/test.yaml",
)
_ = runner.run_all()
out = runner.convert_to_parent_pixel_bounds(deduplicate=False)