Skip to content

Latest commit

 

History

History
135 lines (94 loc) · 6.92 KB

File metadata and controls

135 lines (94 loc) · 6.92 KB

Layout Parser Logo

A unified toolkit for Deep Learning Based Document Image Analysis

Python 3.6 3.7 3.8 PyPI - Downloads


Installation

You can find detailed installation instructions in installation.md. But generally, it's just pip install some libraries:

pip install -U layoutparser

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

# Install the ocr components when necessary 
pip install layoutparser[ocr]      

For Windows Users: Please read installation.md for details about installing Detectron2.

Recent updates

2021.6.8 Update new layout detection model (PaddleDetection) and ocr model (PaddleOCR). We test Detectron2 and PaddleDetection models on PubLayNet and TableBank datasets, the indicators are as follows:

PubLayNet Dataset:

Model mAP CPU time cost GPU time cost
Detectron2 88.98 16545.5ms 209.5ms
PaddleDetection 93.6 1713.7ms 66.6ms

TableBank Dataset:

Model mAP CPU time cost GPU time cost
Detectron2 91.26 7623.2ms 104.2.ms
PaddleDetection 96.2 1968.4ms 65.1ms

Envrionment:

CPU: Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz,24core

GPU: a single NVIDIA Tesla P40

You can also find detailed installation instructions in installation.md. But generally, it's just pip install some libraries:

# Install PaddlePaddle
# CUDA10.1
python -m pip install paddlepaddle-gpu==2.1.0.post101 -f https://paddlepaddle.org.cn/whl/mkl/stable.html
# CPU
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple

# Install the paddle ocr components when necessary 
pip install layoutparser[paddleocr] 

For more PaddlePaddle CUDA version or environment to quick install, please refer to the PaddlePaddle Quick Installation document

Quick Start

We provide a series of examples for to help you start using the layout parser library:

  1. Table OCR and Results Parsing: layoutparser can be used for conveniently OCR documents and convert the output in to structured data.
  2. Deep Layout Parsing Example: With the help of Deep Learning, layoutparser supports the analysis very complex documents and processing of the hierarchical structure in the layouts.
  3. Deep Layout Parsing using Paddle: layoutparser supports the analysis very complex documents and processing of the hierarchical structure in the layouts Using Paddle models.

DL Assisted Layout Prediction Example

Example Usage

The images shown in the figure above are: a screenshot of this paper, an image from the PRIMA Layout Analysis Dataset, a screenshot of the WSJ website, and an image from the HJDataset.

With only 4 lines of code in layoutparse, you can unlock the information from complex documents that existing tools could not provide. You can either choose a deep learning model from the ModelZoo, or load the model that you trained on your own. And use the following code to predict the layout as well as visualize it:

>>> import layoutparser as lp
>>> model = lp.Detectron2LayoutModel('lp://PrimaLayout/mask_rcnn_R_50_FPN_3x/config')
>>> layout = model.detect(image) # You need to load the image somewhere else, e.g., image = cv2.imread(...)
>>> lp.draw_box(image, layout,) # With extra configurations

Use PaddleDetection model:

>>> import layoutparser as lp
>>> model = lp.PaddleDetectionLayoutModel('lp://PubLayNet/ppyolov2_r50vd_dcn_365e_publaynet/config')
>>> layout = model.detect(image) # You need to load the image somewhere else, e.g., image = cv2.imread(...)
>>> lp.draw_box(image, layout,) # With extra configurations

If you want to train a Paddledetection model yourself, please refer to:Train PaddleDetection model

If you want to learn more about PaddleOCR, please refer to: PaddleOCRPaddleOCR infer

Contributing

We encourage you to contribute to Layout Parser! Please check out the Contributing guidelines for guidelines about how to proceed. Join us!

Citing layoutparser

If you find layoutparser helpful to your work, please consider citing our tool and paper using the following BibTeX entry.

@article{shen2021layoutparser,
  title={LayoutParser: A Unified Toolkit for Deep Learning Based Document Image Analysis},
  author={Shen, Zejiang and Zhang, Ruochen and Dell, Melissa and Lee, Benjamin Charles Germain and Carlson, Jacob and Li, Weining},
  journal={arXiv preprint arXiv:2103.15348},
  year={2021}
}