diff --git a/docs/version3.x/module_usage/layout_detection.en.md b/docs/version3.x/module_usage/layout_detection.en.md new file mode 100644 index 0000000000..de0905f20b --- /dev/null +++ b/docs/version3.x/module_usage/layout_detection.en.md @@ -0,0 +1,622 @@ +--- +comments: true +--- + +# Layout Detection Module Tutorial + +## I. Overview +The core task of structure analysis is to parse and segment the content of input document images. By identifying different elements in the image (such as text, charts, images, etc.), they are classified into predefined categories (e.g., pure text area, title area, table area, image area, list area, etc.), and the position and size of these regions in the document are determined. + +## II. Supported Model List + +* The layout detection model includes 20 common categories: document title, paragraph title, text, page number, abstract, table, references, footnotes, header, footer, algorithm, formula, formula number, image, table, seal, figure_table title, chart, and sidebar text and lists of references + + + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PP-DocLayout_plus-LInference Model/Training Model83.234.6244 / 10.3945510.57 / - 126.01 MA higher-precision layout area localization model trained on a self-built dataset containing Chinese and English papers, PPT, multi-layout magazines, contracts, books, exams, ancient books and research reports using RT-DETR-L
+ + +* The layout detection model includes 1 category: Block: + + + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PP-DocBlockLayoutInference Model/Training Model95.934.6244 / 10.3945510.57 / - 123.92 MA layout block localization model trained on a self-built dataset containing Chinese and English papers, PPT, multi-layout magazines, contracts, books, exams, ancient books and research reports using RT-DETR-L
+ + +* The layout detection model includes 23 common categories: document title, paragraph title, text, page number, abstract, table of contents, references, footnotes, header, footer, algorithm, formula, formula number, image, figure caption, table, table caption, seal, figure title, figure, header image, footer image, and sidebar text + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PP-DocLayout-LInference Model/Training Model90.434.6244 / 10.3945510.57 / -123.76 MA high-precision layout area localization model trained on a self-built dataset containing Chinese and English papers, magazines, contracts, books, exams, and research reports using RT-DETR-L.
PP-DocLayout-MInference Model/Training Model75.213.3259 / 4.868544.0680 / 44.068022.578A layout area localization model with balanced precision and efficiency, trained on a self-built dataset containing Chinese and English papers, magazines, contracts, books, exams, and research reports using PicoDet-L.
PP-DocLayout-SInference Model/Training Model70.98.3008 / 2.379410.0623 / 9.92964.834A high-efficiency layout area localization model trained on a self-built dataset containing Chinese and English papers, magazines, contracts, books, exams, and research reports using PicoDet-S.
+ +> ❗ The above list includes the 4 core models that are key supported by the text recognition module. The module actually supports a total of 12 full models, including several predefined models with different categories. The complete model list is as follows: + +
👉 Details of Model List + +* Table Layout Detection Model + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PicoDet_layout_1x_tableInference Model/Training Model97.58.02 / 3.0923.70 / 20.417.4 MA high-efficiency layout area localization model trained on a self-built dataset using PicoDet-1x, capable of detecting table regions.
+ +* 3-Class Layout Detection Model, including Table, Image, and Stamp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PicoDet-S_layout_3clsInference Model/Training Model88.28.99 / 2.2216.11 / 8.734.8A high-efficiency layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using PicoDet-S.
PicoDet-L_layout_3clsInference Model/Training Model89.013.05 / 4.5041.30 / 41.3022.6A balanced efficiency and precision layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using PicoDet-L.
RT-DETR-H_layout_3clsInference Model/Training Model95.8114.93 / 27.71947.56 / 947.56470.1A high-precision layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using RT-DETR-H.
+ +* 5-Class English Document Area Detection Model, including Text, Title, Table, Image, and List + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PicoDet_layout_1xInference Model/Training Model97.89.03 / 3.1025.82 / 20.707.4A high-efficiency English document layout area localization model trained on the PubLayNet dataset using PicoDet-1x.
+ +* 17-Class Area Detection Model, including 17 common layout categories: Paragraph Title, Image, Text, Number, Abstract, Content, Figure Caption, Formula, Table, Table Caption, References, Document Title, Footnote, Header, Algorithm, Footer, and Stamp + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModelModel Download LinkmAP(0.5) (%)GPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
CPU Inference Time (ms)
[Normal Mode / High-Performance Mode]
Model Storage Size (M)Introduction
PicoDet-S_layout_17clsInference Model/Training Model87.49.11 / 2.1215.42 / 9.124.8A high-efficiency layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using PicoDet-S.
PicoDet-L_layout_17clsInference Model/Training Model89.013.50 / 4.6943.32 / 43.3222.6A balanced efficiency and precision layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using PicoDet-L.
RT-DETR-H_layout_17clsInference Model/Training Model98.3115.29 / 104.09995.27 / 995.27470.2A high-precision layout area localization model trained on a self-built dataset of Chinese and English papers, magazines, and research reports using RT-DETR-H.
+ +Test Environment Description: + + + + + + + + + + + + + + + + + + + + + + + + + + +
ModeGPU Configuration CPU Configuration Acceleration Technology Combination
Normal ModeFP32 Precision / No TRT AccelerationFP32 Precision / 8 ThreadsPaddleInference
High-Performance ModeOptimal combination of pre-selected precision types and acceleration strategiesFP32 Precision / 8 ThreadsPre-selected optimal backend (Paddle/OpenVINO/TRT, etc.)
+ +
+ + +## III. Quick Integration + +> ❗ Before quick integration, please install the PaddleOCR wheel package. For detailed instructions, refer to [PaddleOCR Local Installation Tutorial](../ppocr/installation.en.md)。 + +Quickly experience with just one command: + +```bash +paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg +``` + +You can also integrate the model inference from the layout area detection module into your project. Before running the following code, please download [Example Image](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg) Go to the local area. + +```python +from paddleocr import LayoutDetection + +model = LayoutDetection(model_name="PP-DocLayout_plus-L") +output = model.predict("layout.jpg", batch_size=1, layout_nms=True) +for res in output: + res.print() + res.save_to_img(save_path="./output/") + res.save_to_json(save_path="./output/res.json") +``` + +After running, the result obtained is: + +```bash +{'res': {'input_path': 'layout.jpg', 'page_index': None, 'boxes': [{'cls_id': 2, 'label': 'text', 'score': 0.9870226979255676, 'coordinate': [34.101906, 349.85275, 358.59213, 611.0772]}, {'cls_id': 2, 'label': 'text', 'score': 0.9866003394126892, 'coordinate': [34.500324, 647.1585, 358.29367, 848.66797]}, {'cls_id': 2, 'label': 'text', 'score': 0.9846674203872681, 'coordinate': [385.71445, 497.40973, 711.2261, 697.84265]}, {'cls_id': 8, 'label': 'table', 'score': 0.984126091003418, 'coordinate': [73.76879, 105.94899, 321.95303, 298.84888]}, {'cls_id': 8, 'label': 'table', 'score': 0.9834211468696594, 'coordinate': [436.95642, 105.81531, 662.7168, 313.48462]}, {'cls_id': 2, 'label': 'text', 'score': 0.9832247495651245, 'coordinate': [385.62787, 346.2288, 710.10095, 458.77127]}, {'cls_id': 2, 'label': 'text', 'score': 0.9816061854362488, 'coordinate': [385.7802, 735.1931, 710.56134, 849.9764]}, {'cls_id': 6, 'label': 'figure_title', 'score': 0.9577341079711914, 'coordinate': [34.421448, 20.055151, 358.71283, 76.53663]}, {'cls_id': 6, 'label': 'figure_title', 'score': 0.9505634307861328, 'coordinate': [385.72278, 20.053688, 711.29333, 74.92744]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.9001723527908325, 'coordinate': [386.46344, 477.03488, 699.4023, 490.07474]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.8845751285552979, 'coordinate': [35.413048, 627.73596, 185.58383, 640.52264]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.8837394118309021, 'coordinate': [387.17603, 716.3423, 524.7841, 729.258]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.8508939743041992, 'coordinate': [35.50064, 331.18445, 141.6444, 344.81097]}]}} +``` + +The meanings of the parameters are as follows: +- `input_path`: The path to the input image for prediction. +- `page_index`: If the input is a PDF file, it indicates which page of the PDF it is; otherwise, it is `None`. +- `boxes`: Information about the predicted bounding boxes, a list of dictionaries. Each dictionary represents a detected object and contains the following information: + - `cls_id`: Class ID, an integer. + - `label`: Class label, a string. + - `score`: Confidence score of the bounding box, a float. + - `coordinate`: Coordinates of the bounding box, a list of floats in the format [xmin, ymin, xmax, ymax]. + + +The visualized image is as follows: + + + +Relevant methods, parameters, and explanations are as follows: + +* `LayoutDetection` instantiates a target detection model (here, `PP-DocLayout_plus-L` is used as an example). The detailed explanation is as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterDescriptionTypeOptionsDefault Value
model_nameName of the modelstrNoneNone
model_dirPath to store the modelstrNoneNone
deviceThe device used for model inferencestrIt supports specifying specific GPU card numbers, such as "gpu:0", other hardware card numbers, such as "npu:0", or CPU, such as "cpu".gpu:0
img_sizeSize of the input image; if not specified, the default PaddleX official model configuration will be usedint/list/None +
    +
  • int, e.g., 640, means resizing the input image to 640x640
  • +
  • List, e.g., [640, 512], means resizing the input image to a width of 640 and a height of 512
  • +
  • None, not specified, will use the default PaddleX official model configuration
  • +
+
None
thresholdThreshold for filtering low-confidence prediction results; if not specified, the default PaddleX official model configuration will be usedfloat/dict/None +
    +
  • float, e.g., 0.2, means filtering out all bounding boxes with a confidence score less than 0.2
  • +
  • Dictionary, with keys as int representing cls_id and values as float thresholds. For example, {0: 0.45, 2: 0.48, 7: 0.4} means applying a threshold of 0.45 for cls_id 0, 0.48 for cls_id 2, and 0.4 for cls_id 7
  • +
  • None, not specified, will use the default PaddleX official model configuration
  • +
+
None
layout_nmsWhether to use NMS post-processing to filter overlapping boxes; if not specified, the default PaddleX official model configuration will be usedbool/None +
    +
  • bool, True/False, indicates whether to use NMS for post-processing to filter overlapping boxes
  • +
  • None, not specified, will use the default PaddleX official model configuration
  • +
+
None
layout_unclip_ratioScaling factor for the side length of the detection box; if not specified, the default PaddleX official model configuration will be usedfloat/list/dict/None +
    +
  • float, a positive float number, e.g., 1.1, means expanding the width and height of the detection box by 1.1 times while keeping the center unchanged
  • +
  • List, e.g., [1.2, 1.5], means expanding the width by 1.2 times and the height by 1.5 times while keeping the center unchanged
  • +
  • dict, keys as int representing cls_id, values as float scaling factors, e.g., {0: (1.1, 2.0)} means cls_id 0 expanding the width by 1.1 times and the height by 2.0 times while keeping the center unchanged
  • +
  • None, not specified, will use the default PaddleX official model configuration
  • +
+
layout_merge_bboxes_modeMerging mode for the detection boxes output by the model; if not specified, the default PaddleX official model configuration will be usedstring/dict/None +
    +
  • large, when set to large, only the largest external box will be retained for overlapping detection boxes, and the internal overlapping boxes will be deleted
  • +
  • small, when set to small, only the smallest internal box will be retained for overlapping detection boxes, and the external overlapping boxes will be deleted
  • +
  • union, no filtering of boxes will be performed, and both internal and external boxes will be retained
  • +
  • dict, keys as int representing cls_id and values as merging modes, e.g., {0: "large", 2: "small"}
  • +
  • None, not specified, will use the default PaddleX official model configuration
  • +
+
None
use_hpipWhether to enable the high-performance inference pluginboolNoneFalse
hpi_configHigh-performance inference configurationdict | NoneNoneNone
+ +* Note that `model_name` must be specified. After specifying `model_name`, the default PaddleX built-in model parameters will be used. If `model_dir` is specified, the user-defined model will be used. + +* The `predict()` method of the target detection model is called for inference prediction. The parameters of the `predict()` method are `input`, `batch_size`, and `threshold`, which are explained as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ParameterDescriptionTypeOptionsDefault Value
inputData for prediction, supporting multiple input typesPython Var/str/list +
    +
  • Python Variable, such as image data represented by numpy.ndarray
  • +
  • File Path, such as the local path of an image file: /root/data/img.jpg
  • +
  • URL link, such as the network URL of an image file: 示例
  • +
  • Local Directory, the directory should contain the data files to be predicted, such as the local path: /root/data/
  • +
  • List, the elements of the list should be of the above-mentioned data types, such as [numpy.ndarray, numpy.ndarray], [\"/root/data/img1.jpg\", \"/root/data/img2.jpg\"], [\"/root/data1\", \"/root/data2\"]
  • +
+
None
batch_sizeBatch sizeintAny integer greater than 01
thresholdThreshold for filtering low-confidence prediction resultsfloat/dict/None +
    +
  • float, e.g., 0.2, means filtering out all bounding boxes with a confidence score less than 0.2
  • +
  • Dictionary, with keys as int representing cls_id and values as float thresholds. For example, {0: 0.45, 2: 0.48, 7: 0.4} means applying a threshold of 0.45 for cls_id 0, 0.48 for cls_id 2, and 0.4 for cls_id 7
  • +
  • None, not specified, will use the threshold parameter specified in create_model. If not specified in create_model, the default PaddleX official model configuration will be used
  • +
+
layout_nmsWhether to use NMS post-processing to filter overlapping boxes; if not specified, the default PaddleX official model configuration will be usedbool/None +
    +
  • bool, True/False, indicates whether to use NMS for post-processing to filter overlapping boxes
  • +
  • None, not specified, will use the layout_nms parameter specified in create_model. If not specified in create_model, the default PaddleX official model configuration will be used
  • +
+
None
layout_unclip_ratioScaling factor for the side length of the detection box; if not specified, the default PaddleX official model configuration will be usedfloat/list/dict/None +
    +
  • float, a positive float number, e.g., 1.1, means expanding the width and height of the detection box by 1.1 times while keeping the center unchanged
  • +
  • List, e.g., [1.2, 1.5], means expanding the width by 1.2 times and the height by 1.5 times while keeping the center unchanged
  • +
  • dict, keys as int representing cls_id, values as float scaling factors, e.g., {0: (1.1, 2.0)} means cls_id 0 expanding the width by 1.1 times and the height by 2.0 times while keeping the center unchanged
  • +
  • None, not specified, will use the layout_unclip_ratio parameter specified in create_model. If not specified in create_model, the default PaddleX official model configuration will be used
  • +
+
layout_merge_bboxes_modeMerging mode for the detection boxes output by the model; if not specified, the default PaddleX official model configuration will be usedstring/dict/None +
    +
  • large, when set to large, only the largest external box will be retained for overlapping detection boxes, and the internal overlapping boxes will be deleted
  • +
  • small, when set to small, only the smallest internal box will be retained for overlapping detection boxes, and the external overlapping boxes will be deleted
  • +
  • union, no filtering of boxes will be performed, and both internal and external boxes will be retained
  • +
  • dict, keys as int representing cls_id and values as merging modes, e.g., {0: "large", 2: "small"}
  • +
  • None, not specified, will use the layout_merge_bboxes_mode parameter specified in create_model. If not specified in create_model, the default PaddleX official model configuration will be used
  • +
+
None
+ +* Process the prediction results, with each sample's prediction result being the corresponding Result object, and supporting operations such as printing, saving as an image, and saving as a 'json' file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
MethodMethod DescriptionParametersParameter typeParameter DescriptionDefault value
print()Print the result to the terminalformat_jsonboolDo you want to use JSON indentation formatting for the output contentTrue
indentintSpecify the indentation level to enhance the readability of the JSON data output, only valid when format_json is True4
ensure_asciiboolControl 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 TrueFalse
save_to_json()Save the result as a JSON format filesave_pathstrThe saved file path, when it is a directory, the name of the saved file is consistent with the name of the input file typeNone
indentintSpecify the indentation level to enhance the readability of the JSON data output, only valid when format_json is True4
ensure_asciiboolControl 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 TrueFalse
save_to_img()Save the results as an image format filesave_pathstrThe saved file path, when it is a directory, the name of the saved file is consistent with the name of the input file typeNone
+ + +* Additionally, it also supports obtaining the visualized image with results and the prediction results via attributes, as follows: + + + + + + + + + + + + + + + + +
AttributeDescription
jsonGet the prediction result in json format
imgGet the visualized image in dict format
+ + +## IV. Custom Development + +Since PaddleOCR does not directly provide training for the layout detection module, if you need to train the layout area detection model, you can refer to [PaddleX Layout Detection Module Secondary Development](https://paddlepaddle.github.io/PaddleX/latest/module_usage/tutorials/ocr_modules/layout_detection.html#_5)Partially conduct training. The trained model can be seamlessly integrated into PaddleOCR's API for inference. diff --git a/docs/version3.x/module_usage/layout_detection.md b/docs/version3.x/module_usage/layout_detection.md index 0954138d04..0a66f664a0 100644 --- a/docs/version3.x/module_usage/layout_detection.md +++ b/docs/version3.x/module_usage/layout_detection.md @@ -10,6 +10,60 @@ comments: true ## 二、支持模型列表 +* 版面检测模型,包含20个常见的类别:文档标题、段落标题、文本、页码、摘要、目录、参考文献、脚注、页眉、页脚、算法、公式、公式编号、图像、表格、图和表标题(图标题、表格标题和图表标题)、印章、图表、侧栏文本和参考文献内容 + + + + + + + + + + + + + + + + + + + + + + +
模型模型下载链接mAP(0.5)(%)GPU推理耗时(ms)
[常规模式 / 高性能模式]
CPU推理耗时(ms)
[常规模式 / 高性能模式]
模型存储大小(M)介绍
PP-DocLayout_plus-L推理模型/训练模型83.234.6244 / 10.3945510.57 / - 126.01 M基于RT-DETR-L在包含中英文论文、多栏杂志、报纸、PPT、合同、书本、试卷、研报、古籍、日文文档、竖版文字文档等场景的自建数据集训练的更高精度版面区域定位模型
+ +注:以上精度指标的评估集是自建的版面区域检测数据集,包含中英文论文、杂志、报纸、研报、PPT、试卷、课本等 1300 张文档类型图片。 + +* 文档图像版面子模块检测,包含1个 版面区域 类别,能检测多栏的报纸、杂志的每个子文章的文本区域: + + + + + + + + + + + + + + + + + + + + + + +
模型模型下载链接mAP(0.5)(%)GPU推理耗时(ms)
[常规模式 / 高性能模式]
CPU推理耗时(ms)
[常规模式 / 高性能模式]
模型存储大小(M)介绍
PP-DocBlockLayout推理模型/训练模型95.934.6244 / 10.3945510.57 / - 123.92 M基于RT-DETR-L在包含中英文论文、多栏杂志、报纸、PPT、合同、书本、试卷、研报、古籍、日文文档、竖版文字文档等场景的自建数据集训练的文档图像版面子模块检测模型
+ +注:以上精度指标的评估集是自建的版面子区域检测数据集,包含中英文论文、杂志、报纸、研报、PPT、试卷、课本等 1000 张文档类型图片。 + * 版面检测模型,包含23个常见的类别:文档标题、段落标题、文本、页码、摘要、目录、参考文献、脚注、页眉、页脚、算法、公式、公式编号、图像、图表标题、表格、表格标题、印章、图表标题、图表、页眉图像、页脚图像、侧栏文本 @@ -50,8 +104,9 @@ comments: true
+注:以上精度指标的评估集是自建的版面区域检测数据集,包含中英文论文、报纸、研报和试卷等 500 张文档类型图片。 -> ❗ 以上列出的是版面检测模块重点支持的3个核心模型,该模块总共支持11个全量模型,包含多个预定义了不同类别的模型,完整的模型列表如下: +> ❗ 以上列出的是版面检测模块重点支持的5个核心模型,该模块总共支持13个全量模型,包含多个预定义了不同类别的模型,完整的模型列表如下:
👉模型列表详情 @@ -187,8 +242,9 @@ comments: true