Skip to content

Commit

Permalink
Merge pull request #514 from maps-as-data/update-text-spotting
Browse files Browse the repository at this point in the history
Update text spotting and tests with new package names
  • Loading branch information
rwood-97 authored Oct 29, 2024
2 parents a2aeb30 + 4d8f055 commit d55fbbf
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 233 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/mr_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
98 changes: 45 additions & 53 deletions .github/workflows/mr_ci_text_spotting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,49 @@ Method 1: Install from `PyPI <https://pypi.org/project/mapreader/>`_
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 <https://git-scm.com/>`__ 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 <https://git-scm.com/book/en/v2/Getting-Started-Installing-Git>`__.

- Clone the ``mapreader`` source code from the `MapReader GitHub repository <https://github.com/Living-with-machines/MapReader>`_:
Clone the ``mapreader`` source code from the `MapReader GitHub repository <https://github.com/Living-with-machines/MapReader>`_:

.. 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**)
Expand Down
22 changes: 12 additions & 10 deletions docs/source/getting-started/troubleshooting-problems.rst
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -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 <https://visualstudio.microsoft.com/downloads/?q=build+tools>`__.
- Follow instructions `here <https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst>`__ 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]"`)
82 changes: 10 additions & 72 deletions docs/source/using-mapreader/step-by-step-guide/6-spot-text.rst
Original file line number Diff line number Diff line change
@@ -1,88 +1,26 @@
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 <https://github.com/ymy-k/DPText-DETR/tree/main>`__ and outputs bounding boxes and scores.
- ``DeepSoloRunner`` - This is used to detect and recognize text on maps using `DeepSolo <https://github.com/ViTAE-Transformer/DeepSolo/tree/main>`__ and outputs bounding boxes, text and scores.
- ``MapTextPipeline`` - This is used to detect and recognize text on maps using `MapTextPipeline <https://github.com/yyyyyxie/MapTextPipeline>`__ and outputs bounding boxes, text and scores.

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 </getting-started/installation-instructions/index>` 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 <https://github.com/facebookresearch/detectron2>`__.

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 <https://visualstudio.microsoft.com/downloads/?q=build+tools>`__.
- Follow instructions `here <https://stackoverflow.com/questions/64261546/how-to-solve-error-microsoft-visual-c-14-0-or-greater-is-required-when-inst>`__ 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 <https://github.com/aim-uofa/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 <https://github.com/rwood-97/DPText-DETR>`__.

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 <https://github.com/rwood-97/DeepSolo>`__

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 <https://github.com/rwood-97/MapTextPipeline>`__

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 <https://github.com/facebookresearch/detectron2>`__.
- DPTextDETR - Our fork for DPText-DETR is available `here <https://github.com/rwood-97/DPText-DETR>`__.
- DeepSolo - Our fork for DeepSolo is available `here <https://github.com/rwood-97/DeepSolo>`__
- MapTextPipeline - Our fork for MapTextPipeline is available `here <https://github.com/rwood-97/MapTextPipeline>`__

Advice for patch size
---------------------
Expand Down
22 changes: 8 additions & 14 deletions mapreader/spot_text/deepsolo_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit d55fbbf

Please sign in to comment.