Skip to content

Commit 5f158e3

Browse files
authored
Improve dependency (#25)
* Remove pycocotools in the dependency * Enforce newest detectron2 version v0.4 * Add test_Detectron2Model_version_compatibility for checking detectron2 v0.4 * disable test_Detectron2Model_version_compatibility * Add installation instructions * Add installation instructions across the repo * Update copyright for doc
1 parent 8dfc007 commit 5f158e3

File tree

10 files changed

+101
-10
lines changed

10 files changed

+101
-10
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ Layout Parser is a deep learning based tool for document image layout analysis t
1818

1919
## Installation
2020

21-
Use pip or conda to install the library:
21+
You can find detailed installation instructions in [installation.md](installation.md). But generally, it's just `pip install`
22+
some libraries:
23+
2224
```bash
23-
pip install layoutparser
25+
pip install -U layoutparser
2426

2527
# Install Detectron2 for using DL Layout Detection Model
2628
# Please make sure the PyTorch version is compatible with
2729
# the installed Detectron2 version.
28-
pip install 'git+https://github.com/facebookresearch/detectron2.git#egg=detectron2'
30+
pip install 'git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2'
2931

3032
# Install the ocr components when necessary
3133
pip install layoutparser[ocr]
3234
```
33-
This by default will install the CPU version of the Detectron2, and it should be able to run on most of the computers. But if you have a GPU, you can consider the GPU version of the Detectron2, referring to the [official instructions](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md).
35+
36+
**For Windows Users:** Please read [installation.md](installation.md) for details about installing Detectron2.
3437

3538
## Quick Start
3639

dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ sphinx_rtd_theme
1010
google-cloud-vision==1
1111
pytesseract
1212
pycocotools
13-
git+https://github.com/facebookresearch/detectron2.git@v0.1.3#egg=detectron2
13+
git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# -- Project information -----------------------------------------------------
1919

2020
project = 'Layout Parser'
21-
copyright = '2020, Zejiang Shen, Ruochen Zhang'
22-
author = 'Zejiang Shen, Ruochen Zhang'
21+
copyright = '2020-2021, Layout Parser Contributors'
22+
author = 'Layout Parser Contributors'
2323

2424
# The full version, including alpha/beta/rc tags
2525
release = layoutparser.__version__

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Welcome to Layout Parser's documentation!
1010
:maxdepth: 2
1111
:caption: Notes
1212

13-
notes/quickstart
13+
notes/installation.md
1414
notes/modelzoo.md
1515

1616
.. toctree::

docs/notes/installation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../installation.md

installation.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Installation
2+
3+
## Install Python
4+
5+
Layout Parser is a Python package that requires Python >= 3.6. If you do not have Python
6+
installed on your computer, you might want to turn to [the official instruction](https://www.python.org/downloads/)
7+
and download and install the appropriate version of Python.
8+
9+
## Install the Layout Parser main library
10+
11+
Installing the Layout Parser library is very straightforward: you just need to run the following command:
12+
13+
```bash
14+
pip3 install -U layoutparser
15+
```
16+
17+
## [Optional] Install Detectron2 and modeling utils
18+
19+
### For Mac OS and Linux users
20+
21+
If you would like to use deep learning model detection, you need also install Detectron2
22+
on your computer. This could be done by running the following command:
23+
24+
```bash
25+
pip3 install 'git+https://github.com/facebookresearch/detectron2.git@v0.4#egg=detectron2'
26+
```
27+
28+
This might take sometime as the command will *compile* the library. You might also install a Detectron2 version with
29+
GPU supports or encounter some issues during the installation process. Please refer to the official Detectron2
30+
[installation instruction](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md) for detailed
31+
information.
32+
33+
### For Windows users
34+
35+
However, as reported by many users, the installation of Detectron2 is very tricky on Windows platforms.
36+
In our extensive tests, we find that it is nearly impossible to provide a one-line installation command for Windows users.
37+
As a workaround solution, for now we conclude the possible challenges for installing Detectron2 on Windows, and attach helpful
38+
resources for solving them.
39+
We are also investigating other possibilities for avoiding Detectron2 and enabling the pre-trained models. If you have any
40+
suggestions or ideas for fixing this issue, please feel free to [submit an issue](https://github.com/Layout-Parser/layout-parser/issues) in our repo.
41+
42+
1. Challenges for installing `pycocotools`
43+
- You can find detailed instructions on [this post](https://changhsinlee.com/pycocotools/) from Chang Hsin Lee.
44+
- Another solution is try to install `pycocotools-windows`, see https://github.com/cocodataset/cocoapi/issues/415.
45+
2. Challenges for installing the `Detectron2` library itself
46+
- [@ivanpp](https://github.com/ivanpp) curates a detailed description for installing `Detectron2` on Windows: [Detectron2 walkthrough (Windows)](https://ivanpp.cc/detectron2-walkthrough-windows/#step3installdetectron2)
47+
- `Detectron2` claims it won't provide official support for Windows (see [1](https://github.com/facebookresearch/detectron2/issues/9#issuecomment-540974288) and [2](https://detectron2.readthedocs.io/en/latest/tutorials/install.html)), but they claim that Detectron2 is continuously built on windows with CircleCI (see [3](https://github.com/facebookresearch/detectron2/blob/master/INSTALL.md#common-installation-issues)). Hopefully this situation will be improved in the future.
48+
49+
50+
## [Optional] Install OCR utils
51+
52+
Layout Parser also comes with supports for OCR functions. In order to use them, you need
53+
to install the OCR utils via:
54+
55+
```bash
56+
pip3 install -U layoutparser[ocr]
57+
```
58+
59+
Additionally, if you want to use the Tesseract-OCR engine, you also need to install it on your computer. Please check the
60+
[official documentation](https://tesseract-ocr.github.io/tessdoc/Installation.html) for detailed installation instructions.
61+
62+
## Known issues
63+
64+
<details><summary>Error: instantiating lp.GCVAgent.with_credential returns module 'google.cloud.vision' has no attribute 'types'. </summary>
65+
<p>
66+
67+
In this case, you have a newer version of the google-cloud-vision. Please consider downgrading the API using:
68+
```bash
69+
pip install layoutparser[ocr]
70+
```
71+
</p>
72+
</details>

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"pyyaml>=5.1",
2727
"torch",
2828
"torchvision",
29-
"pycocotools>=2.0.2",
3029
"iopath",
3130
],
3231
extras_require={
671 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"page_data": {}, "blocks": [{"x_1": 648.9922485351562, "y_1": 1418.7113037109375, "x_2": 1132.6805419921875, "y_2": 1479.303955078125, "block_type": "rectangle", "type": "Text", "score": 0.9995978474617004}, {"x_1": 106.12457275390625, "y_1": 1032.07470703125, "x_2": 599.2977905273438, "y_2": 1323.208984375, "block_type": "rectangle", "type": "Text", "score": 0.9981802701950073}, {"x_1": 639.54736328125, "y_1": 773.1265869140625, "x_2": 1135.9765625, "y_2": 1044.6507568359375, "block_type": "rectangle", "type": "Text", "score": 0.9974864721298218}, {"x_1": 104.36861419677734, "y_1": 767.3282470703125, "x_2": 595.1759643554688, "y_2": 970.451171875, "block_type": "rectangle", "type": "Text", "score": 0.9974320530891418}, {"x_1": 107.37610626220703, "y_1": 1448.544189453125, "x_2": 598.3998413085938, "y_2": 1488.01611328125, "block_type": "rectangle", "type": "Text", "score": 0.9953517913818359}, {"x_1": 132.01339721679688, "y_1": 146.253173828125, "x_2": 1160.3997802734375, "y_2": 652.8322143554688, "block_type": "rectangle", "type": "Figure", "score": 0.9953091740608215}, {"x_1": 103.79012298583984, "y_1": 1327.6717529296875, "x_2": 601.3895874023438, "y_2": 1429.9224853515625, "block_type": "rectangle", "type": "Text", "score": 0.9949470162391663}, {"x_1": 103.83270263671875, "y_1": 671.7702026367188, "x_2": 1138.1756591796875, "y_2": 748.6300659179688, "block_type": "rectangle", "type": "Text", "score": 0.9943684935569763}, {"x_1": 104.0943832397461, "y_1": 985.9046020507812, "x_2": 444.34979248046875, "y_2": 1011.3511352539062, "block_type": "rectangle", "type": "Title", "score": 0.9880087375640869}, {"x_1": 395.9805908203125, "y_1": 141.7040252685547, "x_2": 1141.115478515625, "y_2": 659.3515625, "block_type": "rectangle", "type": "Figure", "score": 0.9815265536308289}, {"x_1": 107.32891845703125, "y_1": 149.01644897460938, "x_2": 405.1805419921875, "y_2": 582.9757690429688, "block_type": "rectangle", "type": "Figure", "score": 0.965209424495697}, {"x_1": 638.6964721679688, "y_1": 1075.6173095703125, "x_2": 1137.9869384765625, "y_2": 1154.6956787109375, "block_type": "rectangle", "type": "Text", "score": 0.9612341523170471}, {"x_1": 137.1743621826172, "y_1": 591.2607421875, "x_2": 376.2920227050781, "y_2": 609.2918701171875, "block_type": "rectangle", "type": "Text", "score": 0.9027073979377747}, {"x_1": 643.3095703125, "y_1": 1175.7694091796875, "x_2": 1127.9664306640625, "y_2": 1416.0784912109375, "block_type": "rectangle", "type": "Table", "score": 0.8846631646156311}]}

tests/test_model.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from layoutparser import load_json
12
from layoutparser.models import *
23
import cv2
34

@@ -32,4 +33,18 @@ def test_Detectron2Model(is_large_scale=False):
3233
# Test in enforce CPU mode
3334
model = Detectron2LayoutModel("tests/fixtures/model/config.yml", enforce_cpu=True)
3435
image = cv2.imread("tests/fixtures/model/test_model_image.jpg")
35-
layout = model.detect(image)
36+
layout = model.detect(image)
37+
38+
def test_Detectron2Model_version_compatibility(enabled=False):
39+
40+
if enabled:
41+
model = Detectron2LayoutModel(
42+
config_path="lp://PubLayNet/faster_rcnn_R_50_FPN_3x/config",
43+
extra_config=[
44+
"MODEL.ROI_HEADS.SCORE_THRESH_TEST", 0.85,
45+
"MODEL.ROI_HEADS.NMS_THRESH_TEST", 0.75,
46+
],
47+
)
48+
image = cv2.imread("tests/fixtures/model/layout_detection_reference.jpg")
49+
layout = model.detect(image)
50+
assert load_json("tests/fixtures/model/layout_detection_reference.json") == layout

0 commit comments

Comments
 (0)