--- comments: true --- # Layout Analysis Module User Guide ## 1. Overview Layout analysis is a crucial component in document parsing systems. Its goal is to parse the overall layout of a document, accurately detecting various elements it contains (such as text paragraphs, headings, images, tables, formulas, etc.), and restoring the correct reading order of these elements. The performance of this module directly impacts the overall accuracy and usability of the document parsing system. ## 2. Supported Model List Currently, this module only supports the PP-DocLayoutV2 model. Structurally, PP-DocLayoutV2 is based on the layout detection model [PP-DocLayout_plus-L](./layout_detection.en.md) (built upon the RT-DETR-L model) and cascades a lightweight pointer network with 6 Transformer layers. The PP-DocLayout_plus-L component continues to perform layout detection, identifying different elements in document images (such as text, charts, images, formulas, paragraphs, abstracts, references, etc.), classifying them into predefined categories, and determining their positions within the document. The detected bounding boxes and class labels are then fed into the subsequent pointer network to sort the layout elements and obtain the correct reading order.
| Model | Model Download Link | mAP(0.5) (%) | GPU Inference Time (ms) [Standard / High-Performance Mode] |
CPU Inference Time (ms) [Standard / High-Performance Mode] |
Model Size (MB) | Description |
|---|---|---|---|---|---|---|
| PP-DocLayoutV2 | Inference Model | 81.4 | - | - | 203.8 | In-house layout analysis model trained on a diverse self-built dataset including Chinese and English academic papers, multi-column magazines, newspapers, PPTs, contracts, books, exam papers, research reports, ancient books, Japanese documents, and vertical text documents. Provides high-precision layout region localization and reading order recovery. |
[xmin, ymin, xmax, ymax].
Relevant methods, parameters, and explanations are as follows:
| Parameter | Description | Type | Default |
|---|---|---|---|
model_name |
Model name. If set to None, PP-DocLayout-L will be used. |
str|None |
None |
model_dir |
Model storage path. | str|None |
None |
device |
Device for inference. For example: "cpu", "gpu", "npu", "gpu:0", "gpu:0,1".If multiple devices are specified, parallel inference will be performed. By default, GPU 0 is used if available; otherwise, CPU is used. |
str|None |
None |
enable_hpi |
Whether to enable high-performance inference. | bool |
False |
use_tensorrt |
Whether to use the Paddle Inference TensorRT subgraph engine. If the model does not support acceleration through TensorRT, setting this flag will not enable acceleration. For Paddle with CUDA version 11.8, the compatible TensorRT version is 8.x (x>=6), and it is recommended to install TensorRT 8.6.1.6. |
bool |
False |
precision |
Computation precision when using the TensorRT subgraph engine in Paddle Inference. Options: "fp32", "fp16". |
str |
"fp32" |
enable_mkldnn |
Whether to enable MKL-DNN acceleration for inference. If MKL-DNN is unavailable or the model does not support it, acceleration will not be used even if this flag is set. | bool |
True |
mkldnn_cache_capacity |
MKL-DNN cache capacity. | int |
10 |
cpu_threads |
Number of threads to use for inference on CPUs. | int |
10 |
img_size |
Input image size.
|
int|list|None |
None |
threshold |
Threshold for filtering low-confidence predictions.
|
float|dict|None |
None |
layout_nms |
Whether to use NMS post-processing to filter overlapping boxes.
|
bool|None |
None |
layout_unclip_ratio |
Scaling factor for the side length of the detection box.
|
float|list|dict|None |
None |
layout_merge_bboxes_mode |
Merge mode for model output bounding boxes.
|
str|dict|None |
None |
| Parameter | Description | Type | Default |
|---|---|---|---|
input |
Input data to be predicted. Required. Supports multiple input types:
|
Python Var|str|list |
|
batch_size |
Batch size, positive integer. | int |
1 |
threshold |
Same meaning as the instantiation parameters. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. |
float|dict|None |
None |
layout_nms |
Same meaning as the instantiation parameters. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. |
bool|None |
None |
layout_unclip_ratio |
Same meaning as the instantiation parameters. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. |
float|list|dict|None |
None |
layout_merge_bboxes_mode |
Same meaning as the instantiation parameters. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. |
str|dict|None |
None |
| Method | Method Description | Parameters | Parameter type | Parameter Description | Default value |
|---|---|---|---|---|---|
print() |
Print the result to the terminal | format_json |
bool |
Do you want to use JSON indentation formatting for the output content |
True |
indent |
int |
Specify the indentation level to enhance the readability of the JSON data output, only valid when format_json is True |
4 | ||
ensure_ascii |
bool |
Control whether to escape non ASCII characters to Unicode characters. When set to True, all non ASCII characters will be escaped; False preserves the original characters and is only valid when format_json is True |
False |
||
save_to_json() |
Save the result as a JSON format file | save_path |
str |
The saved file path, when it is a directory, the name of the saved file is consistent with the name of the input file type | None |
indent |
int |
Specify the indentation level to enhance the readability of the JSON data output, only valid when format_json is True |
4 | ||
ensure_ascii |
bool |
Control whether to escape non ASCII characters to Unicode characters. When set to True, all non ASCII characters will be escaped; False preserves the original characters and is only valid whenformat_json is True |
False |
||
save_to_img() |
Save the results as an image format file | save_path |
str |
The saved file path, when it is a directory, the name of the saved file is consistent with the name of the input file type | None |
| Attribute | Description |
|---|---|
json |
Get the prediction result in json format |
img |
Get the visualized image in dict format |