From de0ecd466f7d0e3a3e1358aa8d95eb7c61661a88 Mon Sep 17 00:00:00 2001 From: Lin Manhui Date: Sat, 28 Jun 2025 23:13:32 +0800 Subject: [PATCH] [Feat] Add PP-DocTranslate and update docs (#15890) * Add PP-DocTranslate and update docs * Fix docs * Add English doc * Fix ut --- docs/version3.x/deployment/mcp_server.en.md | 2 +- docs/version3.x/deployment/mcp_server.md | 8 +- docs/version3.x/paddleocr_and_paddlex.en.md | 8 +- docs/version3.x/paddleocr_and_paddlex.md | 6 +- docs/version3.x/pipeline_usage/OCR.en.md | 76 +- docs/version3.x/pipeline_usage/OCR.md | 76 +- .../pipeline_usage/PP-ChatOCRv4.en.md | 118 +- .../version3.x/pipeline_usage/PP-ChatOCRv4.md | 142 +- .../pipeline_usage/PP-DocTranslation.en.md | 2874 ++++++++++++++++ .../pipeline_usage/PP-DocTranslation.md | 2993 +++++++++++++++++ .../pipeline_usage/PP-StructureV3.en.md | 100 +- .../pipeline_usage/PP-StructureV3.md | 130 +- .../pipeline_usage/doc_preprocessor.en.md | 32 +- .../pipeline_usage/doc_preprocessor.md | 32 +- .../pipeline_usage/doc_understanding.en.md | 2 +- .../pipeline_usage/doc_understanding.md | 2 +- .../pipeline_usage/formula_recognition.en.md | 56 +- .../pipeline_usage/formula_recognition.md | 58 +- .../pipeline_usage/seal_recognition.en.md | 52 +- .../pipeline_usage/seal_recognition.md | 72 +- .../pipeline_usage/table_recognition_v2.en.md | 84 +- .../pipeline_usage/table_recognition_v2.md | 62 +- mkdocs.yml | 1 + paddleocr/__init__.py | 2 + paddleocr/_cli.py | 2 + paddleocr/_pipelines/__init__.py | 2 + paddleocr/_pipelines/pp_chatocrv4_doc.py | 4 +- paddleocr/_pipelines/pp_doctranslation.py | 936 ++++++ paddleocr/_pipelines/pp_structurev3.py | 2 + paddleocr/_pipelines/table_recognition_v2.py | 2 + pyproject.toml | 2 +- tests/{predictors => models}/__init__.py | 0 .../image_classification_common.py | 0 .../object_detection_common.py | 0 .../test_doc_img_orientation_classifcation.py | 0 tests/{predictors => models}/test_doc_vlm.py | 0 .../test_formula_recognition.py | 0 .../test_layout_detection.py | 0 .../test_seal_text_detection.py | 0 .../test_table_cells_detection.py | 0 .../test_table_classifcation.py | 0 .../test_table_structure_recognition.py | 0 .../test_text_detection.py | 0 .../test_text_image_unwarping.py | 0 .../test_text_recognition.py | 1 + ...test_textline_orientation_classifcation.py | 0 tests/pipelines/test_pp_doctranslation.py | 80 + 47 files changed, 7459 insertions(+), 560 deletions(-) create mode 100644 docs/version3.x/pipeline_usage/PP-DocTranslation.en.md create mode 100644 docs/version3.x/pipeline_usage/PP-DocTranslation.md create mode 100644 paddleocr/_pipelines/pp_doctranslation.py rename tests/{predictors => models}/__init__.py (100%) rename tests/{predictors => models}/image_classification_common.py (100%) rename tests/{predictors => models}/object_detection_common.py (100%) rename tests/{predictors => models}/test_doc_img_orientation_classifcation.py (100%) rename tests/{predictors => models}/test_doc_vlm.py (100%) rename tests/{predictors => models}/test_formula_recognition.py (100%) rename tests/{predictors => models}/test_layout_detection.py (100%) rename tests/{predictors => models}/test_seal_text_detection.py (100%) rename tests/{predictors => models}/test_table_cells_detection.py (100%) rename tests/{predictors => models}/test_table_classifcation.py (100%) rename tests/{predictors => models}/test_table_structure_recognition.py (100%) rename tests/{predictors => models}/test_text_detection.py (100%) rename tests/{predictors => models}/test_text_image_unwarping.py (100%) rename tests/{predictors => models}/test_text_recognition.py (96%) rename tests/{predictors => models}/test_textline_orientation_classifcation.py (100%) create mode 100644 tests/pipelines/test_pp_doctranslation.py diff --git a/docs/version3.x/deployment/mcp_server.en.md b/docs/version3.x/deployment/mcp_server.en.md index a1f50744ea..4220f4f91c 100644 --- a/docs/version3.x/deployment/mcp_server.en.md +++ b/docs/version3.x/deployment/mcp_server.en.md @@ -167,7 +167,7 @@ See [2.1 Quick Start](#21-quick-start). 1. Install `paddleocr-mcp`. 2. Set up AI Studio community service. - Visit [PaddlePaddle AI Studio Community](https://aistudio.baidu.com/pipeline/mine) and log in. **Note: A China mainland phone number is required to use this service.** If unavailable, consider other modes. - - In the left panel under "More Content" → "PaddleX Pipelines", [Create Pipeline] - [OCR] - [General OCR] - [Deploy Directly] - [Start Deployment]. + - Under "PaddleX Pipeline" in the "More" section on the left, click in sequence: [Create Pipeline] - [OCR] - [General OCR] - [Deploy Directly] - [Start Deployment]. - After deployment, obtain your **service base URL** (e.g., `https://xxxxxx.aistudio-hub.baidu.com`). - Get your **access token** from [this page](https://aistudio.baidu.com/index/accessToken). 3. Refer to the configuration example below to modify the contents of the `claude_desktop_config.json` file. diff --git a/docs/version3.x/deployment/mcp_server.md b/docs/version3.x/deployment/mcp_server.md index 4f975f3c1a..f02eb5783c 100644 --- a/docs/version3.x/deployment/mcp_server.md +++ b/docs/version3.x/deployment/mcp_server.md @@ -67,7 +67,7 @@ ImportError: failed to find libmagic. Check your installation ### 2.1 快速开始 -接下来以 **星河社区服务** 工作模式为例,引导您完成快速配置。此模式无需在本地安装复杂的依赖,因此比较适合用于快速体验。 +接下来以 **星河社区服务** 工作模式为例,引导您快速上手。此模式无需在本地安装复杂的依赖,因此比较适合用于快速体验。 1. **安装 `paddleocr-mcp`** @@ -76,7 +76,7 @@ ImportError: failed to find libmagic. Check your installation 2. **准备星河社区服务** - 访问 [飞桨星河社区](https://aistudio.baidu.com/pipeline/mine) 并登录。**请注意,目前星河社区要求用户绑定中国大陆手机号。** 如果您不具备此条件,请考虑使用其他工作模式。 - - 在左侧"更多内容"下的 "PaddleX 产线" 部分,[创建产线] - [OCR] - [通用 OCR] - [直接部署] - [开始部署]。 + - 在左侧"更多内容"下的 "PaddleX 产线" 部分,依次点击:【创建产线】 - 【OCR】- 【通用OCR】-【直接部署】-【开始部署】。 - 部署成功后,获取您的 **服务基础 URL**(示例:`https://xxxxxx.aistudio-hub.baidu.com`)。 - 在 [此页面](https://aistudio.baidu.com/index/accessToken) 获取您的 **访问令牌**。 @@ -109,8 +109,8 @@ ImportError: failed to find libmagic. Check your installation **说明**: - - 将 `` 替换为您的星河社区服务的 **服务基础 URL**,例如 `https://xxxxx.aistudio-hub.baidu.com`,注意不要带有端点路径(如 `/ocr`)。 - - 将 `` 替换为您的 **访问令牌**。 + - 将 `` 替换为您的星河社区服务的基础 URL,例如 `https://xxxxx.aistudio-hub.baidu.com`,注意不要带有端点路径(如 `/ocr`)。 + - 将 `` 替换为您的访问令牌。 **注意**: diff --git a/docs/version3.x/paddleocr_and_paddlex.en.md b/docs/version3.x/paddleocr_and_paddlex.en.md index e253512fb2..16e54c5de9 100644 --- a/docs/version3.x/paddleocr_and_paddlex.en.md +++ b/docs/version3.x/paddleocr_and_paddlex.en.md @@ -26,19 +26,21 @@ The version correspondence between PaddleOCR, PaddleX, and the PaddlePaddle fram | `3.0.1` | `3.0.1` | `>= 3.0.0` | | `3.0.2` | `3.0.2` | `>= 3.0.0` | | `3.0.3` | `>= 3.0.3` | `>= 3.0.0` | +| `3.1.0` | `>= 3.1.0` | `>= 3.0.0` | ## 2. Correspondence Between PaddleOCR Pipelines and PaddleX Pipeline Registration Names | PaddleOCR Pipeline | PaddleX Pipeline Registration Name | | --- | --- | | General OCR | `OCR` | -| General Layout Analysis v3 | `PP-StructureV3` | -| Document Scenario Information Extraction v4 | `PP-ChatOCRv4-doc` | -| General Table Recognition v2 | `table_recognition_v2` | +| PP-StructureV3 | `PP-StructureV3` | +| PP-ChatOCRv4 | `PP-ChatOCRv4-doc` | +| General Table Recognition V2 | `table_recognition_v2` | | Formula Recognition | `formula_recognition` | | Seal Text Recognition | `seal_recognition` | | Document Image Preprocessing | `doc_preprocessor` | | Document Understanding | `doc_understanding` | +| PP-DocTranslation | `PP-DocTranslation` | ## 3. Using PaddleX Pipeline Configuration Files diff --git a/docs/version3.x/paddleocr_and_paddlex.md b/docs/version3.x/paddleocr_and_paddlex.md index ee672ad58b..9e753a9d22 100644 --- a/docs/version3.x/paddleocr_and_paddlex.md +++ b/docs/version3.x/paddleocr_and_paddlex.md @@ -26,19 +26,21 @@ PaddleOCR、PaddleX 和飞桨框架的版本存在如下对应关系: | `3.0.1` | `3.0.1` | `>= 3.0.0` | | `3.0.2` | `3.0.2` | `>= 3.0.0` | | `3.0.3` | `>= 3.0.3` | `>= 3.0.0` | +| `3.1.0` | `>= 3.1.0` | `>= 3.0.0` | ## 2. PaddleOCR 产线与 PaddleX 产线注册名的对应关系 | PaddleOCR 产线 | PaddleX 产线注册名 | | --- | --- | | 通用 OCR | `OCR` | -| 通用版面解析 v3 | `PP-StructureV3` | -| 文档场景信息抽取 v4 | `PP-ChatOCRv4-doc` | +| PP-StructureV3 | `PP-StructureV3` | +| PP-ChatOCRv4 | `PP-ChatOCRv4-doc` | | 通用表格识别 v2 | `table_recognition_v2` | | 公式识别 | `formula_recognition` | | 印章文本识别 | `seal_recognition` | | 文档图像预处理 | `doc_preprocessor` | | 文档理解 | `doc_understanding` | +| PP-DocTranslation | `PP-DocTranslation` | ## 3. 使用 PaddleX 产线配置文件 diff --git a/docs/version3.x/pipeline_usage/OCR.en.md b/docs/version3.x/pipeline_usage/OCR.en.md index 0cf04d254d..899e417b9f 100644 --- a/docs/version3.x/pipeline_usage/OCR.en.md +++ b/docs/version3.x/pipeline_usage/OCR.en.md @@ -733,26 +733,26 @@ paddleocr ocr -i ./general_ocr_002.png --ocr_version PP-OCRv4 use_doc_orientation_classify -Whether to load and use the document orientation classification module. If not set, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the document orientation classification module. If not set, the pipeline's initialized value for this parameter (defaults to True) will be used. bool use_doc_unwarping -Whether to load and use the text image unwarping module. If not set, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the text image unwarping module. If not set, the pipeline's initialized value for this parameter (defaults to True) will be used. bool use_textline_orientation -Whether to load and use the text line orientation module. If not set, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the text line orientation module. If not set, the pipeline's initialized value for this parameter (defaults to True) will be used. bool text_det_limit_side_len Image side length limitation for text detection. -Any integer greater than 0. If not set, the pipeline's initialized value for this parameter (initialized to 64) will be used. +Any integer greater than 0. If not set, the pipeline's initialized value for this parameter (defaults to 64) will be used. int @@ -760,14 +760,14 @@ Any integer greater than 0. If not set, the pipeline's initialized text_det_limit_type Type of side length limit for text detection. -Supports min and max. min means ensuring the shortest side of the image is not smaller than det_limit_side_len, and max means ensuring the longest side of the image is not larger than limit_side_len. If not set, the pipeline's initialized value for this parameter (initialized to min) will be used. +Supports min and max. min means ensuring the shortest side of the image is not smaller than det_limit_side_len, and max means ensuring the longest side of the image is not larger than limit_side_len. If not set, the pipeline's initialized value for this parameter (defaults to min) will be used. str text_det_thresh -Pixel threshold for text detection. In the output probability map, pixels with scores higher than this threshold will be considered text pixels.Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (0.3) will be used. +Pixel threshold for text detection. In the output probability map, pixels with scores higher than this threshold will be considered text pixels.Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (defaults to 0.3) will be used. float @@ -775,7 +775,7 @@ Supports min and max. min means ensuring text_det_box_thresh Text detection box threshold. If the average score of all pixels within the detected result boundary is higher than this threshold, the result will be considered a text region. -Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (0.6) will be used. +Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (defaults to 0.6) will be used. float @@ -783,7 +783,7 @@ Any floating-point number greater than 0. If not set, the pipeline' text_det_unclip_ratio Text detection expansion coefficient. This method is used to expand the text region—the larger the value, the larger the expanded area. -Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (2.0) will be used. +Any floating-point number greater than 0. If not set, the pipeline's initialized value for this parameter (defaults to 2.0) will be used. float @@ -797,7 +797,7 @@ Any floating-point number greater than 0. If not set, the pipeline' text_rec_score_thresh Text recognition threshold. Text results with scores higher than this threshold will be retained.Any floating-point number greater than 0 -. If not set, the pipeline's initialized value for this parameter (0.0, i.e., no threshold) will be used. +. If not set, the pipeline's initialized value for this parameter (defaults to 0.0, i.e., no threshold) will be used. float @@ -1112,19 +1112,19 @@ In the above Python script, the following steps are performed: use_doc_orientation_classify -Whether to load and use the document orientation classification module. If set to None, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the document orientation classification module. If set to None, the pipeline's initialized value for this parameter (defaults to True) will be used. bool|None None use_doc_unwarping -Whether to load and use the text image unwarping module. If set to None, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the text image unwarping module. If set to None, the pipeline's initialized value for this parameter (defaults to True) will be used. bool|None None use_textline_orientation -Whether to load and use the text line orientation module. If set to None, the pipeline's initialized value for this parameter (initialized to True) will be used. +Whether to load and use the text line orientation module. If set to None, the pipeline's initialized value for this parameter (defaults to True) will be used. bool|None None @@ -1133,7 +1133,7 @@ In the above Python script, the following steps are performed: Image side length limitation for text detection.
  • int: Any integer greater than 0;
  • -
  • None: If set to None, the pipeline's initialized value for this parameter (initialized to 64) will be used.
  • +
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to 64) will be used.
int|None @@ -1144,7 +1144,7 @@ In the above Python script, the following steps are performed: Type of side length limit for text detection.
  • str: Supports min and max, where min means ensuring the shortest side of the image is not smaller than det_limit_side_len, and max means ensuring the longest side of the image is not larger than limit_side_len;
  • -
  • None: If set to None, the pipeline's initialized value for this parameter (initialized to min) will be used.
  • +
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to min) will be used.
str|None @@ -1155,7 +1155,7 @@ In the above Python script, the following steps are performed: Pixel threshold for text detection. Pixels with scores higher than this threshold in the output probability map will be considered text pixels.
  • float: Any floating-point number greater than 0; -
  • None: If set to None, the pipeline's initialized value for this parameter (0.3) will be used.
+
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to 0.3) will be used.
  • float|None None @@ -1165,7 +1165,7 @@ In the above Python script, the following steps are performed: Box threshold for text detection. A detection result will be considered a text region if the average score of all pixels within the bounding box is higher than this threshold.
    • float: Any floating-point number greater than 0; -
    • None: If set to None, the pipeline's initialized value for this parameter (0.6) will be used.
    +
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to 0.6) will be used.
  • float|None None @@ -1175,7 +1175,7 @@ In the above Python script, the following steps are performed: Dilation coefficient for text detection. This method is used to dilate the text region, and the larger this value, the larger the dilated area.
    • float: Any floating-point number greater than 0; -
    • None: If set to None, the pipeline's initialized value for this parameter (2.0) will be used.
    +
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to 2.0) will be used.
  • float|None None @@ -1191,7 +1191,7 @@ In the above Python script, the following steps are performed: Recognition score threshold for text. Text results with scores higher than this threshold will be retained.
    • float: Any floating-point number greater than 0; -
    • None: If set to None, the pipeline's initialized value for this parameter (0.0, i.e., no threshold) will be used.
    +
  • None: If set to None, the pipeline's initialized value for this parameter (defaults to 0.0, i.e., no threshold) will be used.
  • float|None None @@ -1616,26 +1616,6 @@ Below are the API reference for basic service deployment and examples of multi-l No -visualize -boolean | null - -Whether to return the final visualization image and intermediate images during the processing.
    -
      -
    • If true is provided: return images.
    • -
    • If false is provided: do not return any images.
    • -
    • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
    • -
    -
    -For example, adding the following setting to the pipeline config file:
    -
    Serving:
    -  visualize: False
    -
    -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
    -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Refer to the use_doc_orientation_classify parameter in the pipeline object's predict method. @@ -1690,6 +1670,26 @@ If neither the request body nor the configuration file is set (If visualiz Refer to the text_rec_score_thresh parameter in the pipeline object's predict method. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
    +
      +
    • If true is provided: return images.
    • +
    • If false is provided: do not return any images.
    • +
    • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
    • +
    +
    +For example, adding the following setting to the pipeline config file:
    +
    Serving:
    +  visualize: False
    +
    +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
    +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
      diff --git a/docs/version3.x/pipeline_usage/OCR.md b/docs/version3.x/pipeline_usage/OCR.md index 9eb35f15d1..ab2cfd14f5 100644 --- a/docs/version3.x/pipeline_usage/OCR.md +++ b/docs/version3.x/pipeline_usage/OCR.md @@ -734,33 +734,33 @@ paddleocr ocr -i ./general_ocr_002.png --ocr_version PP-OCRv4 use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_textline_orientation -是否加载并使用文本行方向模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本行方向模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool text_det_limit_side_len 文本检测的图像边长限制。 -大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 64。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 64int text_det_limit_type -文本检测的边长度限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 min。 +文本检测的边长度限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 minstr @@ -768,7 +768,7 @@ paddleocr ocr -i ./general_ocr_002.png --ocr_version PP-OCRv4 text_det_thresh 文本检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。 -大于0的任意浮点数。如果不设置,将默认使用产线初始化的该参数值 0.3。 +大于0的任意浮点数。如果不设置,将使用产线初始化的该参数值(默认为 0.3)。 float @@ -776,14 +776,14 @@ paddleocr ocr -i ./general_ocr_002.png --ocr_version PP-OCRv4 text_det_box_thresh 文本检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。 -大于 0 的任意浮点数。如果不设置,将默认使用产线初始化的该参数值 0.6。 +大于 0 的任意浮点数。如果不设置,将使用产线初始化的该参数值(默认为 0.6)。 float text_det_unclip_ratio -文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。大于0的任意浮点数。如果不设置,将默认使用产线初始化的该参数值 2.0。 +文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。大于 0 的任意浮点数。如果不设置,将使用产线初始化的该参数值(默认为 2.0)。 float @@ -797,7 +797,7 @@ paddleocr ocr -i ./general_ocr_002.png --ocr_version PP-OCRv4 text_rec_score_thresh 文本识别阈值,得分大于该阈值的文本结果会被保留。 -大于0的任意浮点数。如果不设置,将默认使用产线初始化的该参数值 0.0。即不设阈值。 +大于0的任意浮点数。如果不设置,将使用产线初始化的该参数值(默认为 0.0,即不设阈值)。 float @@ -1113,19 +1113,19 @@ for res in result: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_textline_orientation -是否加载并使用文本行方向模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本行方向模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1134,7 +1134,7 @@ for res in result: 文本检测的图像边长限制。
      • int:大于 0 的任意整数;
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 64
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 64
      • int|None @@ -1145,7 +1145,7 @@ for res in result: 文本检测的边长度限制类型。
        • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
        • -
        • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 min
        • +
        • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 min
        • str|None @@ -1156,7 +1156,7 @@ for res in result: 文本检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。
          • float:大于0的任意浮点数; -
          • None:如果设置为None,将默认使用产线初始化的该参数值 0.3
          • +
          • None:如果设置为None,将使用产线初始化的该参数值(默认为0.3)。
          • float|None None @@ -1166,7 +1166,7 @@ for res in result: 文本检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。
            • float:大于0的任意浮点数; -
            • None:如果设置为None,将默认使用产线初始化的该参数值 0.6。 +
            • None:如果设置为None,将使用产线初始化的该参数值(默认为0.6)。 float|None None @@ -1176,7 +1176,7 @@ for res in result: 文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。
              • float:大于0的任意浮点数; -
              • None:如果设置为None,将默认使用产线初始化的该参数值 2.0。 +
              • None:如果设置为None,将使用产线初始化的该参数值(默认为2.0)。 float|None @@ -1193,7 +1193,7 @@ for res in result: 文本识别阈值,得分大于该阈值的文本结果会被保留。
                • float:大于0的任意浮点数; -
                • None:如果设置为None,将默认使用产线初始化的该参数值 0.0,即不设阈值。 +
                • None:如果设置为None,将使用产线初始化的该参数值(默认为0.0,即不设阈值)。 float|None @@ -1619,23 +1619,6 @@ MKL-DNN 缓存容量。 否 -visualize -boolean | null -是否返回可视化结果图以及处理过程中的中间图像等。 -
                    -
                  • 传入 true:返回图像。
                  • -
                  • 传入 false:不返回图像。
                  • -
                  • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
                  • -
                  -
                  例如,在产线配置文件中添加如下字段:
                  -
                  Serving:
                  -  visualize: False
                  -
                  -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 - -否 - - useDocOrientationClassify boolean | null 请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 @@ -1690,6 +1673,23 @@ MKL-DNN 缓存容量。 请参阅产线对象中 predict 方法的 text_rec_score_thresh 参数相关说明。 否 + +visualize +boolean | null +是否返回可视化结果图以及处理过程中的中间图像等。 +
                    +
                  • 传入 true:返回图像。
                  • +
                  • 传入 false:不返回图像。
                  • +
                  • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
                  • +
                  +
                  例如,在产线配置文件中添加如下字段:
                  +
                  Serving:
                  +  visualize: False
                  +
                  +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 + +否 +
                    @@ -2240,7 +2240,7 @@ pipeline = PaddleOCR(text_detection_model_dir="./your_det_model_path") 1.获取产线配置文件 -可调用 PaddleOCR 中 通用OCR 产线对象的 `export_paddlex_config_to_yaml` 方法,将当前产线配置导出为 YAML 文件: +可调用 PaddleOCR 中 通用 OCR 产线对象的 `export_paddlex_config_to_yaml` 方法,将当前产线配置导出为 YAML 文件: ```Python from paddleocr import PaddleOCR @@ -2284,7 +2284,7 @@ SubModules: 3.在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash paddleocr ocr --paddlex_config PaddleOCR.yaml ... @@ -2292,7 +2292,7 @@ paddleocr ocr --paddlex_config PaddleOCR.yaml ... 4.在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python from paddleocr import PaddleOCR diff --git a/docs/version3.x/pipeline_usage/PP-ChatOCRv4.en.md b/docs/version3.x/pipeline_usage/PP-ChatOCRv4.en.md index 69e1fb81ed..5bbe7e7599 100644 --- a/docs/version3.x/pipeline_usage/PP-ChatOCRv4.en.md +++ b/docs/version3.x/pipeline_usage/PP-ChatOCRv4.en.md @@ -1133,19 +1133,19 @@ The name of the document orientation classification model. If not set, the defau use_doc_orientation_classify -Whether to load and use the document orientation classification module. If not set, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the document orientation classification module. If not set, the parameter value initialized by the pipeline will be used, which defaults to True. bool use_doc_unwarping -Whether to load and use the text image unwarping module. If not set, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the text image unwarping module. If not set, the parameter value initialized by the pipeline will be used, which defaults to True. bool use_textline_orientation -Whether to load and use the text line orientation classification module. If not set, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the text line orientation classification module. If not set, the parameter value initialized by the pipeline will be used, which defaults to True. bool @@ -1171,7 +1171,7 @@ The name of the document orientation classification model. If not set, the defau layout_nms -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will default to the value initialized in the pipeline, which is set to True by default. +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will be set to the value initialized in the pipeline, which defaults to True by default. bool @@ -1458,7 +1458,7 @@ After running, the output is as follows: The prediction process, API description, and output description for PP-ChatOCRv4 are as follows: -
                    (1) Call the PPChatOCRv4Doc method to instantiate the PP-ChatOCRv4 pipeline object. +
                    (1) Call PPChatOCRv4Doc to instantiate the PP-ChatOCRv4 pipeline object. The relevant parameter descriptions are as follows: @@ -1582,31 +1582,31 @@ The relevant parameter descriptions are as follows: use_doc_orientation_classify -Whether to load and use the document orientation classification module. If set toNone, the value initialized by the pipeline for this parameter will be used by default (initialized to True). +Whether to load and use the document orientation classification module. If set toNone, the value initialized by the pipeline for this parameter will be used (defaults to True). bool|None None use_doc_unwarping -Whether to load and use the document unwarping module. If set toNone, the value initialized by the pipeline for this parameter will be used by default (initialized to True). +Whether to load and use the document unwarping module. If set toNone, the value initialized by the pipeline for this parameter will be used (defaults to True). bool|None None use_textline_orientation -Whether to load and use the text line orientation classification function. If set toNone, the value initialized by the pipeline for this parameter will be used by default (initialized to True). +Whether to load and use the text line orientation classification function. If set toNone, the value initialized by the pipeline for this parameter will be used (defaults to True). bool|None None use_seal_recognition -Whether to load and use the seal text recognition sub-pipeline. If set toNone, the value initialized by the pipeline for this parameter will be used by default (initialized to True). +Whether to load and use the seal text recognition sub-pipeline. If set toNone, the value initialized by the pipeline for this parameter will be used (defaults to True). bool|None None use_table_recognition -Whether to load and use the table recognition sub-pipeline. If set toNone, the value initialized by the pipeline for this parameter will be used by default (initialized to True). +Whether to load and use the table recognition sub-pipeline. If set toNone, the value initialized by the pipeline for this parameter will be used (defaults to True). bool|None None @@ -1624,7 +1624,7 @@ The relevant parameter descriptions are as follows: layout_nms -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will default to the value initialized in the pipeline, which is set to True by default. +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will be set to the value initialized in the pipeline, which is set to True by default. bool|None None @@ -1647,7 +1647,7 @@ The relevant parameter descriptions are as follows:
                    • str: large,small, union, representing whether to keep the large box, small box, or both when filtering overlapping boxes;
                    • dict, where the key is of int type, representing cls_id, and the value is of str type, e.g.,{0: "large", 2: "small"}, meaning use "large" mode for class 0 detection boxes and "small" mode for class 2 detection boxes;
                    • -
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used by default (initialized to large).
                    • +
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used (defaults to large).
                    str|dict|None @@ -1658,7 +1658,7 @@ The relevant parameter descriptions are as follows: Image side length limitation for text detection.
                    • int: Any integer greater than 0;
                    • -
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used by default (initialized to 960).
                    • +
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used (defaults to 960).
                    int|None @@ -1669,7 +1669,7 @@ The relevant parameter descriptions are as follows: Type of side length limit for text detection.
                    • str: Supports min and max. min ensures the shortest side of the image is not less than det_limit_side_len. max ensures the longest side of the image is not greater than limit_side_len;
                    • -
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used by default (initialized to max).
                    • +
                    • None: If set to None, the value initialized by the pipeline for this parameter will be used (defaults to max).
                    str|None @@ -1680,7 +1680,7 @@ The relevant parameter descriptions are as follows: Detection pixel threshold. In the output probability map, pixels with scores greater than this threshold are considered text pixels.
                    • float: Any float greater than 0;
                    • -
                    • None: If set to None, the value initialized by the pipeline for this parameter (0.3) will be used by default.
                    +
                  • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.3) will be used.
                  float|None None @@ -1690,7 +1690,7 @@ The relevant parameter descriptions are as follows: Detection box threshold. If the average score of all pixels within a detection result's bounding box is greater than this threshold, the result is considered a text region.
                  • float: Any float greater than 0;
                  • -
                  • None: If set to None, the value initialized by the pipeline for this parameter (0.6) will be used by default.
                  +
                • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.6) will be used.
                float|None None @@ -1700,7 +1700,7 @@ The relevant parameter descriptions are as follows: Text detection expansion factor. This method is used to expand text regions; the larger the value, the larger the expanded area.
                • float: Any float greater than 0;
                • -
                • None: If set to None, the value initialized by the pipeline for this parameter (2.0) will be used by default.
                +
              • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 2.0) will be used.
              float|None None @@ -1710,7 +1710,7 @@ The relevant parameter descriptions are as follows: Text recognition threshold. Text results with scores greater than this threshold will be kept.
              • float: Any float greater than 0;
              • -
              • None: If set to None, the value initialized by the pipeline for this parameter (0.0, i.e., no threshold) will be used by default.
              +
            • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.0, i.e., no threshold) will be used.
            float|None None @@ -1720,7 +1720,7 @@ The relevant parameter descriptions are as follows: Image side length limit for seal text detection.
            • int: Any integer greater than 0;
            • -
            • None: If set to None, the value initialized by the pipeline for this parameter will be used by default (initialized to 736).
            • +
            • None: If set to None, the value initialized by the pipeline for this parameter will be used (defaults to 736).
            int|None @@ -1731,7 +1731,7 @@ The relevant parameter descriptions are as follows: Type of image side length limit for seal text detection.
            • str: Supports min and max. min ensures the shortest side of the image is not less than det_limit_side_len. max ensures the longest side of the image is not greater than limit_side_len;
            • -
            • None: If set to None, the value initialized by the pipeline for this parameter will be used by default (initialized to min).
            • +
            • None: If set to None, the value initialized by the pipeline for this parameter will be used (defaults to min).
            str|None @@ -1742,7 +1742,7 @@ The relevant parameter descriptions are as follows: Detection pixel threshold. In the output probability map, pixels with scores greater than this threshold are considered text pixels.
            • float: Any float greater than 0; -
            • None: If set to None, the value initialized by the pipeline for this parameter (0.2) will be used by default.
            +
          • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.2) will be used.
          float|None None @@ -1752,7 +1752,7 @@ The relevant parameter descriptions are as follows: Detection box threshold. If the average score of all pixels within a detection result's bounding box is greater than this threshold, the result is considered a text region.
          • float: Any float greater than 0; -
          • None: If set to None, the value initialized by the pipeline for this parameter (0.6) will be used by default.
          +
        • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.6) will be used.
        float|None None @@ -1762,7 +1762,7 @@ The relevant parameter descriptions are as follows: Seal text detection expansion factor. This method is used to expand text regions; the larger the value, the larger the expanded area.
        • float: Any float greater than 0; -
        • None: If set to None, the value initialized by the pipeline for this parameter (0.5) will be used by default.
        +
      • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.5) will be used.
      float|None None @@ -1772,7 +1772,7 @@ The relevant parameter descriptions are as follows: Seal text recognition threshold. Text results with scores greater than this threshold will be kept.
      • float: Any float greater than 0; -
      • None: If set to None, the value initialized by the pipeline for this parameter (0.0, i.e., no threshold) will be used by default.
      +
    • None: If set to None, the value initialized by the pipeline for this parameter (defaults to 0.0, i.e., no threshold) will be used.
    float|None None @@ -2563,26 +2563,6 @@ To remove the page limit, please add the following configuration to the pipeline No -visualize -boolean | null - -Whether to return the final visualization image and intermediate images during the processing.
    -
      -
    • If true is provided: return images.
    • -
    • If false is provided: do not return any images.
    • -
    • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
    • -
    -
    -For example, adding the following setting to the pipeline config file:
    -
    Serving:
    -  visualize: False
    -
    -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
    -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Please refer to the description of the use_doc_orientation_classify parameter of the pipeline object's visual_predict method. @@ -2702,6 +2682,26 @@ If neither the request body nor the configuration file is set (If visualiz Please refer to the description of the seal_rec_score_thresh parameter of the pipeline object's visual_predict method. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
    +
      +
    • If true is provided: return images.
    • +
    • If false is provided: do not return any images.
    • +
    • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
    • +
    +
    +For example, adding the following setting to the pipeline config file:
    +
    Serving:
    +  visualize: False
    +
    +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
    +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
      @@ -2746,7 +2746,7 @@ If neither the request body nor the configuration file is set (If visualiz prunedResult object -A simplified version of the res field in the JSON representation of the results generated by the pipeline's visual_predict method, with the input_path and the page_index fields removed. +A simplified version of the res field in the JSON representation of the layout_parsing_result generated by the pipeline object's visual_predict method, with the input_path and page_index fields removed. outputImages @@ -2786,13 +2786,13 @@ If neither the request body nor the configuration file is set (If visualiz minCharacters -integer | null -Minimum data length to enable the vector database. +integer +Please refer to the description of the min_characters parameter of the pipeline object's build_vector method. No blockSize -int | null +integer Please refer to the description of the block_size parameter of the pipeline object's build_vector method. No @@ -2911,7 +2911,7 @@ If neither the request body nor the configuration file is set (If visualiz useVectorRetrieval -boolean | null +boolean Please refer to the description of the use_vector_retrieval parameter of the pipeline object's chat method. No @@ -2924,12 +2924,12 @@ If neither the request body nor the configuration file is set (If visualiz minCharacters integer -Minimum data length to enable the vector database. +Please refer to the description of the min_characters parameter of the pipeline object's chat method. No textTaskDescription -string | null +string Please refer to the description of the text_task_description parameter of the pipeline object's chat method. No @@ -2995,7 +2995,7 @@ If neither the request body nor the configuration file is set (If visualiz mllmIntegrationStrategy -string | null +string Please refer to the description of the mllm_integration_strategy parameter of the pipeline object's chat method. No @@ -3051,7 +3051,7 @@ import sys import requests -API_BASE_URL = "http://0.0.0.0:8080" +API_BASE_URL = "http://127.0.0.1:8080" image_path = "./demo.jpg" keys = ["name"] @@ -3813,10 +3813,10 @@ If you need to use the fine-tuned model weights, simply modify the production co You can call the `export_paddlex_config_to_yaml` method of the pipeline object to export the current pipeline configuration to a YAML file. Here is an example: ```Python -from paddleocr import PPChatOCRv4 +from paddleocr import PPChatOCRv4Doc -pipeline = PPChatOCRv4() -pipeline.export_paddlex_config_to_yaml("PP-ChatOCRv4.yaml") +pipeline = PPChatOCRv4Doc() +pipeline.export_paddlex_config_to_yaml("PP-ChatOCRv4-doc.yaml") ``` 2. Editing Pipeline Configuration Files @@ -3854,7 +3854,7 @@ The exported PaddleX pipeline configuration file not only includes parameters su By specifying the path to the PaddleX pipeline configuration file using the `--paddlex_config` parameter, PaddleOCR will read its contents as the configuration for inference. Here is an example: ```bash -paddleocr pp_chatocrv4_doc --paddlex_config PP-ChatOCRv4.yaml ... +paddleocr pp_chatocrv4_doc --paddlex_config PP-ChatOCRv4-doc.yaml ... ``` 4. Loading Pipeline Configuration Files in Python API @@ -3862,7 +3862,7 @@ paddleocr pp_chatocrv4_doc --paddlex_config PP-ChatOCRv4.yaml ... When initializing the pipeline object, you can pass the path to the PaddleX pipeline configuration file or a configuration dictionary through the `paddlex_config` parameter, and PaddleOCR will use it as the configuration for inference. Here is an example: ```python -from paddleocr import PPChatOCRv4 +from paddleocr import PPChatOCRv4Doc -pipeline = PPChatOCRv4(paddlex_config="PP-ChatOCRv4.yaml") +pipeline = PPChatOCRv4Doc(paddlex_config="PP-ChatOCRv4-doc.yaml") ``` diff --git a/docs/version3.x/pipeline_usage/PP-ChatOCRv4.md b/docs/version3.x/pipeline_usage/PP-ChatOCRv4.md index 9ab663a275..f49ff44a42 100644 --- a/docs/version3.x/pipeline_usage/PP-ChatOCRv4.md +++ b/docs/version3.x/pipeline_usage/PP-ChatOCRv4.md @@ -901,7 +901,7 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 invoke_mllm -是否加载并使用多模态大模型。如果不设置,将默认使用产线初始化的该参数值,初始化为False。 +是否加载并使用多模态大模型。如果不设置,将使用产线初始化的该参数值,默认初始化为Falsebool @@ -1015,13 +1015,13 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -1033,33 +1033,33 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 use_seal_recognition -是否加载并使用印章文本识别子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用印章文本识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_table_recognition -是否加载并使用表格识别子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用表格识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool layout_threshold 版面模型得分阈值。 -0-1 之间的任意浮点数。如果不设置,将默认使用产线初始化的该参数值,初始化为 0.5。 +0-1 之间的任意浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 0.5float layout_nms -版面检测是否使用后处理NMS。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool layout_unclip_ratio -版面区域检测模型检测框的扩张系数。任意大于 0 浮点数。如果不设置,将默认使用产线初始化的该参数值,初始化为 1.0。 +版面区域检测模型检测框的扩张系数。任意大于 0 浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 1.0float @@ -1071,14 +1071,14 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数
    • large,设置为large时,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留外部最大的框,删除重叠的内部框;
    • small,设置为small,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留内部被包含的小框,删除重叠的外部框;
    • union,不进行框的过滤处理,内外框都保留;
    • -
    如果不设置,将默认使用产线初始化的该参数值,初始化为large。 +如果不设置,将使用产线初始化的该参数值,默认初始化为largestr text_det_limit_side_len -文本检测的图像边长限制。大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 960。 +文本检测的图像边长限制。大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 960int @@ -1086,7 +1086,7 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 text_det_limit_type 文本检测的边长度限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len -如果不设置,将默认使用产线初始化的该参数值,初始化为 max。 +如果不设置,将使用产线初始化的该参数值,默认初始化为 maxstr @@ -1122,14 +1122,14 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 seal_det_limit_side_len -印章文本检测的图像边长限制。大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 736。 +印章文本检测的图像边长限制。大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 736int seal_det_limit_type -印章文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 min。 +印章文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 minstr @@ -1151,7 +1151,7 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 seal_det_unclip_ratio 印章文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。大于 0 的任意浮点数 -。如果不设置,将默认使用产线初始化的该参数值 0.5。 +。如果不设置,将使用产线初始化的该参数值,默认为 0.5float @@ -1159,7 +1159,7 @@ paddleocr pp_chatocrv4_doc -i vehicle_certificate-1.png -k 驾驶室准乘人数 seal_rec_score_thresh 印章文本识别阈值,得分大于该阈值的文本结果会被保留。大于 0 的任意浮点数 -。如果不设置,将默认使用产线初始化的该参数值 0.0。即不设阈值。 +。如果不设置,将使用产线初始化的该参数值,默认为0.0,即不设阈值。 float @@ -1326,7 +1326,7 @@ print(chat_result) PP-ChatOCRv4 预测的流程、API说明、产出说明如下: -
    (1)调用 PPChatOCRv4Doc 方法实例化PP-ChatOCRv4产线对象。 +
    (1)调用 PPChatOCRv4Doc 实例化PP-ChatOCRv4产线对象。 相关参数说明如下: @@ -1450,31 +1450,31 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_textline_orientation -是否加载并使用文本行方向分类模块. 如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本行方向分类模块. 如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_seal_recognition -是否加载并使用印章文本识别子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用印章文本识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_table_recognition -是否加载并使用表格识别子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用表格识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1484,7 +1484,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下:
    • float0-1 之间的任意浮点数;
    • dict{0:0.1} key为类别ID,value为该类别的阈值;
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 0.5
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 0.5
    float|dict|None @@ -1492,7 +1492,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: layout_nms -版面检测是否使用后处理NMS。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1503,7 +1503,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下:
  • float:任意大于 0 浮点数;
  • Tuple[float,float]:在横纵两个方向各自的扩张系数;
  • dict,dict的key为int类型,代表cls_id,value为tuple类型,如{0: (1.1,2.0)},表示将模型输出的第0类别检测框中心不变,宽度扩张1.1倍,高度扩张2.0倍
  • -
  • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 1.0
  • +
  • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 1.0
  • float|Tuple[float,float]|dict|None @@ -1515,7 +1515,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下:
    • strlargesmallunion,分别表示重叠框过滤时选择保留大框,小框还是同时保留;
    • dict,dict的key为int类型,代表cls_id,value为str类型,如{0: "large",2: "small"},表示对第0类别检测框使用large模式,对第2类别检测框使用small模式;
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 large
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 large
    str|dict|None @@ -1526,7 +1526,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 文本检测的图像边长限制。
    • int:大于 0 的任意整数;
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 960
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 960
    int|None @@ -1537,7 +1537,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 文本检测的边长度限制类型。
    • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 max
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 max
    str|None @@ -1548,7 +1548,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.3
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.3
  • float|None None @@ -1558,7 +1558,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.6
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.6
  • float|None None @@ -1568,7 +1568,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 2.0
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为2.0
  • float|None None @@ -1578,7 +1578,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 文本识别阈值,得分大于该阈值的文本结果会被保留。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.0,即不设阈值。
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.0,即不设阈值。
  • float|None None @@ -1588,7 +1588,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 印章文本检测的图像边长限制。
    • int:大于0的任意整数;
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 736
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 736
    int|None @@ -1599,7 +1599,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 印章文本检测的图像边长限制类型。
    • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 min
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 min
    str|None @@ -1610,7 +1610,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.2
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.2
  • float|None None @@ -1620,7 +1620,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.6
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.6
  • float|None None @@ -1630,7 +1630,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 印章文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.5
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.5
  • float|None None @@ -1640,7 +1640,7 @@ PP-ChatOCRv4 预测的流程、API说明、产出说明如下: 印章文本识别阈值,得分大于该阈值的文本结果会被保留。
    • float:大于0的任意浮点数; -
    • None:如果设置为None,将默认使用产线初始化的该参数值 0.0,即不设阈值。
    +
  • None:如果设置为None,将使用产线初始化的该参数值,默认为0.0,即不设阈值。
  • float|None None @@ -2441,23 +2441,6 @@ for res in visual_predict_res: 否 -visualize -boolean | null -是否返回可视化结果图以及处理过程中的中间图像等。 -
      -
    • 传入 true:返回图像。
    • -
    • 传入 false:不返回图像。
    • -
    • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
    • -
    -
    例如,在产线配置文件中添加如下字段:
    -
    Serving:
    -  visualize: False
    -
    -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 - -否 - - useDocOrientationClassify boolean | null 请参阅产线对象中 visual_predict 方法的 use_doc_orientation_classify 参数相关说明。 @@ -2577,6 +2560,23 @@ for res in visual_predict_res: 请参阅产线对象中 visual_predict 方法的 seal_rec_score_thresh 参数相关说明。 否 + +visualize +boolean | null +是否返回可视化结果图以及处理过程中的中间图像等。 +
      +
    • 传入 true:返回图像。
    • +
    • 传入 false:不返回图像。
    • +
    • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
    • +
    +
    例如,在产线配置文件中添加如下字段:
    +
    Serving:
    +  visualize: False
    +
    +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 + +否 +
      @@ -2621,7 +2621,7 @@ for res in visual_predict_res: prunedResult object -产线对象的 visual_predict 方法生成结果的 JSON 表示中 res 字段的简化版本,其中去除了 input_pathpage_index 字段。 +产线对象的 visual_predict 方法生成的 layout_parsing_result 的 JSON 表示中 res 字段的简化版本,其中去除了 input_pathpage_index 字段。 outputImages @@ -2661,13 +2661,13 @@ for res in visual_predict_res: minCharacters -integer | null -启用向量数据库的最小数据长度。 +integer +请参阅产线对象中 build_vector 方法的 min_characters 参数相关说明。 否 blockSize -int | null +integer 请参阅产线对象中 build_vector 方法的 block_size 参数相关说明。 否 @@ -2718,7 +2718,7 @@ for res in visual_predict_res: image -string +string 服务器可访问的图像文件的URL或图像文件内容的Base64编码结果。 是 @@ -2787,7 +2787,7 @@ for res in visual_predict_res: useVectorRetrieval -boolean | null +boolean 请参阅产线对象中 chat 方法的 use_vector_retrieval 参数相关说明。 否 @@ -2800,7 +2800,7 @@ for res in visual_predict_res: minCharacters integer -启用向量数据库的最小数据长度 +请参阅产线对象中 chat 方法的 min_characters 参数相关说明。 否 @@ -2871,7 +2871,7 @@ for res in visual_predict_res: mllmIntegrationStrategy -string | null +string 请参阅产线对象中 chat 方法的 mllm_integration_strategy 参数相关说明。 否 @@ -2928,7 +2928,7 @@ import sys import requests -API_BASE_URL = "http://0.0.0.0:8080" +API_BASE_URL = "http://127.0.0.1:8080" image_path = "./demo.jpg" keys = ["姓名"] @@ -3689,10 +3689,10 @@ function send_post_raw($url, $data) { 可调用 PaddleOCR 中 PPChatOCRv4 产线对象的 `export_paddlex_config_to_yaml` 方法,将当前产线配置导出为 YAML 文件: ```Python -from paddleocr import PPChatOCRv4 +from paddleocr import PPChatOCRv4Doc -pipeline = PPChatOCRv4() -pipeline.export_paddlex_config_to_yaml("PP-ChatOCRv4.yaml") +pipeline = PPChatOCRv4Doc() +pipeline.export_paddlex_config_to_yaml("PP-ChatOCRv4-doc.yaml") ``` 2. 修改配置文件 @@ -3725,18 +3725,18 @@ SubModules: 3. 在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash -paddleocr pp_chatocrv4_doc --paddlex_config PP-ChatOCRv4.yaml ... +paddleocr pp_chatocrv4_doc --paddlex_config PP-ChatOCRv4-doc.yaml ... ``` 4. 在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python -from paddleocr import PPChatOCRv4 +from paddleocr import PPChatOCRv4Doc -pipeline = PPChatOCRv4(paddlex_config="PP-ChatOCRv4.yaml") +pipeline = PPChatOCRv4Doc(paddlex_config="PP-ChatOCRv4-doc.yaml") ``` diff --git a/docs/version3.x/pipeline_usage/PP-DocTranslation.en.md b/docs/version3.x/pipeline_usage/PP-DocTranslation.en.md new file mode 100644 index 0000000000..a40815a976 --- /dev/null +++ b/docs/version3.x/pipeline_usage/PP-DocTranslation.en.md @@ -0,0 +1,2874 @@ +--- +comments: true +--- + +# PP-DocTranslation Pipeline Usage Tutorial + +## 1. Introduction to PP-DocTranslation Pipeline + +PP-DocTranslation is a document intelligent translation solution provided by PaddlePaddle. It integrates advanced general layout analysis technology and large language model (LLM) capabilities to offer you efficient document intelligent translation services. This solution can accurately identify and extract various elements within documents, including text blocks, headings, paragraphs, images, tables, and other complex layout structures, and on this basis, achieve high-quality multilingual translation. PP-DocTranslation supports mutual translation among multiple mainstream languages, particularly excelling in handling documents with complex layouts and strong contextual dependencies, striving to deliver precise, natural, fluent, and professional translation results. This pipeline also provides flexible serving options, supporting the use of multiple programming languages on various hardware. Moreover, it offers the capability for secondary development, allowing you to train and fine-tune models on your own datasets based on this pipeline, and the trained models can also be seamlessly integrated. + +The PP-DocTranslation pipeline uses the PP-StructureV3 sub-pipeline, and thus has all the functions of the PP-StructureV3 pipeline. For more information on the functions and usage details of the PP-StructureV3 pipeline, you can click on the [PP-StructureV3 Pipeline Documentation](./PP-StructureV3.md) page.。 + +In this pipeline, you can select the model to use based on the benchmark data below. + +
      👉Details of model list +

      Document image orientation classification module:

      + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkTop-1 Acc (%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      PP-LCNet_x1_0_doc_oriInference model/Training model99.062.62 / 0.593.24 / 1.197A document image classification model based on PP-LCNet_x1_0, with four categories: 0 degrees, 90 degrees, 180 degrees, and 270 degrees
      +

      Text image unwarping module:

      + + + + + + + + + + + + + + + + + + +
      ModelModel download linkCERModel storage size (M)Introduction
      UVDocInference model/Training model0.17930.3 MA high-precision text image unwarping model
      +

      Layout region detection module 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
      PP-DocLayout_plus-LInference model/Training model83.253.03 / 17.23634.62 / 378.32126.01 MA higher-precision layout region localization model trained on a self-built dataset based on RT-DETR-L, covering scenarios such as Chinese and English papers, multi-column magazines, newspapers, PPTs, contracts, books, examination papers, research reports, ancient books, Japanese documents, and documents with vertical text.
      PP-DocLayout-LInference model/Training model90.433.59 / 33.59503.01 / 251.08123.76 MA high-precision layout region localization model trained on a self-built dataset based on RT-DETR-L, covering scenarios such as Chinese and English papers, magazines, contracts, books, examination papers, and research reports.
      PP-DocLayout-MInference model/Training model75.213.03 / 4.7243.39 / 24.4422.578A layout region localization model with balanced precision and efficiency trained on a self-built dataset based on PicoDet-L, covering scenarios such as Chinese and English papers, magazines, contracts, books, examination papers, and research reports.
      PP-DocLayout-SInference model/Training model70.911.54 / 3.8618.53 / 6.294.834A highly efficient layout region localization model trained on a self-built dataset based on PicoDet-S, covering scenarios such as Chinese and English papers, magazines, contracts, books, examination papers, and research reports.
      +

      Table structure recognition module:

      + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkAccuracy (%)GPU inference time (ms)
      [Normal Mode / High-Performance Mode]
      CPU inference time (ms)
      [Normal Mode / High-Performance Mode]
      Model storage size (M)Introduction
      SLANeXt_wiredInference model/Training model69.6585.92 / 85.92- / 501.66351MThe SLANeXt series is a new generation of table structure recognition models independently developed by Baidu PaddlePaddle's vision team. Compared to SLANet and SLANet_plus, SLANeXt focuses on recognizing table structures and has trained dedicated weights for wired and wireless tables separately. This has significantly improved its ability to recognize various types of tables, especially wired tables.
      SLANeXt_wirelessInference model/Training model
      +

      Table classification module model:

      + + + + + + + + + + + + + + + + +
      ModelModel download linkTop1 Acc(%)GPU inference time (ms)
      [Normal Mode / High-Performance Mode]
      CPU inference time (ms)
      [Normal Mode / High-Performance Mode]
      Model storage size (M)
      PP-LCNet_x1_0_table_clsInference model/Training model94.22.62 / 0.603.17 / 1.146.6M
      +

      Table cell detection module model:

      + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkmAP(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      RT-DETR-L_wired_table_cell_detInference model/Training model82.733.47 / 27.02402.55 / 256.56124MRT-DETR is the first real-time end-to-end object detection model. Based on RT-DETR-L as the base model, Baidu PaddlePaddle's vision team completed pre-training on a self-built table cell detection dataset, achieving table cell detection with good performance for both wired and wireless tables.
      RT-DETR-L_wireless_table_cell_detInference model/Training model
      +

      Text detection module:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkDetection Hmean (%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      PP-OCRv5_server_detInference model/Training model83.889.55 / 70.19383.15 / 383.1584.3The server-side text detection model of PP-OCRv5, with higher accuracy, suitable for deployment on servers with better performance
      PP-OCRv5_mobile_detInference model/Training model79.010.67 / 6.3657.77 / 28.154.7PP-OCRv5's mobile-end text detection model, with higher efficiency, suitable for deployment on edge devices
      PP-OCRv4_server_detInference model/Training model69.2127.82 / 98.87585.95 / 489.77109PP-OCRv4's server-end text detection model, with higher accuracy, suitable for deployment on servers with better performance
      PP-OCRv4_mobile_detInference model/Training model63.89.87 / 4.1756.60 / 20.794.7PP-OCRv4's mobile-end text detection model, with higher efficiency, suitable for deployment on edge devices
      PP-OCRv3_mobile_detInference model/Training modelAccuracy is close to PP-OCRv4_mobile_det9.90 / 3.6041.93 / 20.762.1PP-OCRv3's mobile-end text detection model, with higher efficiency, suitable for deployment on edge devices
      PP-OCRv3_server_detInference model/Training modelAccuracy is close to PP-OCRv4_server_det119.50 / 75.00379.35 / 318.35102.1Server-side text detection model of PP-OCRv3, with higher accuracy, suitable for deployment on servers with better performance
      +

      Text recognition module model:

      *Chinese recognition model + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkRecognition Avg Accuracy(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      PP-OCRv5_server_recInference model/Training model86.388.46 / 2.3631.21 / 31.2181 MPP-OCRv5_rec is a new generation of text recognition model. This model is committed to efficiently and accurately supporting four major languages, namely Simplified Chinese, Traditional Chinese, English, and Japanese, as well as complex text scenarios such as handwriting, vertical text, pinyin, and rare characters with a single model. While maintaining recognition effectiveness, it also takes into account inference speed and model robustness, providing efficient and accurate technical support for document understanding in various scenarios.
      PP-OCRv5_mobile_recInference model/Training model81.295.43 / 1.4621.20 / 5.3216 M
      PP-OCRv4_server_rec_docInference model/Training model86.588.69 / 2.7837.93 / 37.9374.7 MPP-OCRv4_server_rec_doc is trained on a mixed dataset of more Chinese document data and PP-OCR training data based on PP-OCRv4_server_rec. It has enhanced the ability to recognize some traditional Chinese characters, Japanese characters, and special characters, and can support the recognition of over 15,000 characters. In addition to improving the document-related text recognition ability, it has also enhanced the general text recognition ability.
      PP-OCRv4_mobile_recInference model/Training model78.745.26 / 1.1217.48 / 3.6110.6 MA lightweight recognition model of PP-OCRv4 with high inference efficiency, which can be deployed on various hardware devices including edge devices.
      PP-OCRv4_server_recInference model/Training model80.618.75 / 2.4936.93 / 36.9371.2 MA server-side model of PP-OCRv4 with high inference accuracy, which can be deployed on various servers.
      PP-OCRv3_mobile_recInference model/Training model72.963.89 / 1.168.72 / 3.569.2 MA lightweight recognition model of PP-OCRv3 with high inference efficiency, which can be deployed on various hardware devices including edge devices.
      + + + + + + + + + + + + + + + + + + +
      ModelModel download linkRecognition Avg Accuracy(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      ch_SVTRv2_recInference model/Training model68.8110.38 / 8.3166.52 / 30.8373.9 MSVTRv2 is a server-side text recognition model developed by the OpenOCR team of the Vision and Learning Lab (FVL) at Fudan University. It won the first prize in the PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition Task, with a 6% improvement in end-to-end recognition accuracy on Leaderboard A compared to PP-OCRv4.
      + + + + + + + + + + + + + + + + + + +
      ModelModel download linkRecognition Avg Accuracy(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      ch_RepSVTR_recInference model/Training model65.076.29 / 1.5720.64 / 5.4022.1 MRepSVTR is a mobile-side text recognition model based on SVTRv2. It won the first prize in the PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition Task, with a 2.5% improvement in end-to-end recognition accuracy on Leaderboard B compared to PP-OCRv4, while maintaining the same inference speed.
      *English recognition model + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkRecognition Avg Accuracy(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      en_PP-OCRv4_mobile_recInference model/Training model70.394.81 / 1.2317.20 / 4.186.8 MAn ultra-lightweight English recognition model trained based on the PP-OCRv4 recognition model, supporting English and number recognition
      en_PP-OCRv3_mobile_recInference model/Training model70.693.56 / 0.788.44 / 5.787.8 MAn ultra-lightweight English recognition model trained based on the PP-OCRv3 recognition model, supporting English and number recognition
      *Multilingual recognition model + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkAvg Accuracy of recognition (%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      korean_PP-OCRv3_mobile_recInference model/Training model60.213.73 / 0.988.76 / 2.918.6 MAn ultra-lightweight Korean recognition model trained based on the PP-OCRv3 recognition model, supporting Korean and digit recognition
      japan_PP-OCRv3_mobile_recInference model/Training model45.693.86 / 1.018.62 / 2.928.8 MAn ultra-lightweight Japanese recognition model trained based on the PP-OCRv3 recognition model, supporting Japanese and digit recognition
      chinese_cht_PP-OCRv3_mobile_recInference model/Training model82.063.90 / 1.169.24 / 3.189.7 MAn ultra-lightweight traditional Chinese recognition model trained based on the PP-OCRv3 recognition model, supporting traditional Chinese and digit recognition
      te_PP-OCRv3_mobile_recInference model/Training model95.883.59 / 0.818.28 / 6.217.8 MAn ultra-lightweight Telugu recognition model trained based on the PP-OCRv3 recognition model, supporting Telugu and digit recognition
      ka_PP-OCRv3_mobile_recInference model/Training model96.963.49 / 0.898.63 / 2.778.0 MAn ultra-lightweight Kannada recognition model trained based on the PP-OCRv3 recognition model, supporting Kannada and digit recognition
      ta_PP-OCRv3_mobile_recInference model/Training model76.833.49 / 0.868.35 / 3.418.0 MAn ultra-lightweight Tamil recognition model trained based on the PP-OCRv3 recognition model, supporting Tamil and digit recognition
      latin_PP-OCRv3_mobile_recInference model/Training model76.933.53 / 0.788.50 / 6.837.8 MAn ultra-lightweight Latin recognition model trained based on the PP-OCRv3 recognition model, supporting Latin and digit recognition
      arabic_PP-OCRv3_mobile_recInference model/Training model73.553.60 / 0.838.44 / 4.697.8 MAn ultra-lightweight Arabic alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Arabic alphabet and digit recognition
      cyrillic_PP-OCRv3_mobile_recInference model/Training model94.283.56 / 0.798.22 / 2.767.9 MAn ultra-lightweight Slavic alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Slavic alphabet and digit recognition
      devanagari_PP-OCRv3_mobile_recInference model/Training model96.443.60 / 0.786.95 / 2.877.9 MAn ultra-lightweight Sanskrit alphabet recognition model trained based on the PP-OCRv3 recognition model, supporting Sanskrit alphabet and digit recognition
      +

      Text line direction classification module (optional):

      + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkTop-1 Acc (%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      PP-LCNet_x0_25_textline_oriInference model/Training model95.542.16 / 0.412.37 / 0.730.32A text line classification model based on PP-LCNet_x0_25, with two categories, namely 0 degrees and 180 degrees
      +

      Formula recognition module:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkAvg-BLEU(%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      UniMERNetInference model/Training model86.132266.96/--/-1.4 GUniMERNet is a formula recognition model developed by Shanghai AI Lab. It uses Donut Swin as the encoder and MBartDecoder as the decoder. By training on a dataset of one million entries that includes simple formulas, complex formulas, scanned formulas, and handwritten formulas, the model significantly improves its recognition accuracy for formulas in real-world scenarios.PP-FormulaNet-SInference model/Training model87.121311.84 / 1311.84- / 8288.07167.9 MPP-FormulaNet is an advanced formula recognition model developed by Baidu PaddlePaddle's vision team, supporting the recognition of 50,000 common LaTeX source code vocabulary. The PP-FormulaNet-S version employs PP-HGNetV2-B4 as its backbone network. Through techniques such as parallel masking and model distillation, it significantly enhances the model's inference speed while maintaining high recognition accuracy, suitable for scenarios like simple printed formulas and simple multi-line printed formulas. The PP-FormulaNet-L version, on the other hand, is based on Vary_VIT_B as its backbone network and has undergone in-depth training on a large-scale formula dataset. It shows significant improvement in recognizing complex formulas compared to PP-FormulaNet-S and is suitable for scenarios like simple printed formulas, complex printed formulas, and handwritten formulas.PP-FormulaNet-LInference model/Training model92.131976.52/--/-535.2 MLaTeX_OCR_recInference model/Training model71.631088.89 / 1088.89- / -89.7 MLaTeX-OCR is a formula recognition algorithm based on an autoregressive large model. By adopting Hybrid ViT as the backbone network and transformer as the decoder, it significantly improves the accuracy of formula recognition.
      +

      Seal text detection module:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ModelModel download linkDetection Hmean (%)GPU inference time (ms)
      [Normal mode / High-performance mode]
      CPU inference time (ms)
      [Normal mode / High-performance mode]
      Model storage size (M)Introduction
      PP-OCRv4_server_seal_detInference model/Training model98.21124.64 / 91.57545.68 / 439.86109PP-OCRv4's server-side seal text detection model with higher accuracy, suitable for deployment on better servers
      PP-OCRv4_mobile_seal_detInference model/Training model96.479.70 / 3.5650.38 / 19.644.6PP-OCRv4's mobile-side seal text detection model with higher efficiency, suitable for deployment on the end side
      +Test environment description: +
        +
      • Performance test environment +
          +
        • Test dataset: +
            +
          • Document image orientation classification model: A self-built dataset by PaddleX, covering multiple scenarios such as certificates and documents, containing 1000 images.
          • +
          • Text image unwarping model:DocUNet.
          • +
          • Layout area detection model: The self-built layout area analysis dataset of PaddleOCR, which includes 10,000 common document images such as Chinese and English papers, magazines, and research reports.
          • +
          • PP-DocLayout_plus-L: The self-built layout area detection dataset of PaddleOCR, which includes 1,300 document images such as Chinese and English papers, magazines, newspapers, research reports, PPTs, examination papers, and textbooks.
          • +
          • Table structure recognition model: The self-built English table recognition dataset within PaddleX.
          • +
          • Text detection model: The self-built Chinese dataset of PaddleOCR, covering multiple scenarios such as street views, web images, documents, and handwriting, with 500 images for detection.
          • +
          • Chinese recognition model: The self-built Chinese dataset of PaddleOCR, covering multiple scenarios such as street views, web images, documents, and handwriting, with 11,000 images for text recognition.
          • +
          • ch_SVTRv2_rec:PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition TaskEvaluation set for Leaderboard A.
          • +
          • ch_RepSVTR_rec:PaddleOCR Algorithm Model Challenge - Task 1: OCR End-to-End Recognition TaskEvaluation set for Leaderboard B.
          • +
          • English recognition model: The self-built English dataset of PaddleX.
          • +
          • Multilingual recognition model: The self-built multilingual dataset of PaddleX.
          • +
          • Text line direction classification model: The self-built dataset of PaddleX, covering multiple scenarios such as certificates and documents, with 1,000 images.
          • +
          • Seal text detection model: The self-built dataset of PaddleX, which includes 500 images of round seals.
          • +
          +
        • +
        • Hardware configuration: +
            +
          • GPU: NVIDIA Tesla T4
          • +
          • CPU: Intel Xeon Gold 6271C @ 2.60GHz
          • +
          • Other environments: Ubuntu 20.04 / CUDA 11.8 / cuDNN 8.9 / TensorRT 8.6.1.6
          • +
          +
        • +
        +
      • +
      • Description of inference modes
      • +
      + + + + + + + + + + + + + + + + + + + + + + + +
      ModesGPU configurationCPU configurationCombination of acceleration technologies
      Regular modeFP32 precision / no TRT accelerationFP32 precision / 8 threadsPaddleInference
      High-performance modeSelect the optimal combination of prior precision type and acceleration strategyFP32 precision / 8 threadsSelect the optimal prior backend (Paddle/OpenVINO/TRT, etc.)
      +
      + +## 2. Quick Start + +Before using the PP-DocTranslation pipeline locally, please ensure that you have completed the installation of the wheel package according to the [Installation Tutorial](../installation.md). + +Please note: If you encounter issues such as the program becoming unresponsive, unexpected program termination, running out of memory resources, or extremely slow inference during execution, please try adjusting the configuration according to the documentation, such as disabling unnecessary features or using lighter-weight models. + +Before use, you need to prepare the API key for a large language model, which supports the [Baidu Cloud Qianfan Platform](https://console.bce.baidu.com/qianfan/ais/console/onlineService) or local large model services that comply with the OpenAI interface standards. + +### 2.1 Experience via Command Line + +You can download the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png) and quickly experience the pipeline effect with a single command: + +```bash +paddleocr pp_doctranslation -i vehicle_certificate-1.png --target_language en --qianfan_api_key your_api_key +``` + +
      The command line supports more parameter settings. Click to expand for detailed descriptions of command line parameters. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ParameterDescriptionParameter TypeDefault Value
      inputData to be predicted, required. For example, the local path of an image file or PDF file:/root/data/img.jpg;Or a URL link, such as the network URL of an image file or PDF file:Example;Or a local directory, which should contain the images to be predicted, such as the local path:/root/data/(Currently, prediction for PDF files within a directory is not supported. PDF files need to be specified to a specific file path).str
      save_pathSpecify the path where the inference result file will be saved. If not set, the inference result will not be saved locally.str
      target_languageTarget language (ISO 639-1 language code).strzh
      layout_detection_model_nameThe model name for layout area detection. If not set, the default model of the pipeline will be used.str
      layout_detection_model_dirThe directory path of the layout area detection model. If not set, the official model will be downloaded.str
      layout_thresholdThe score threshold for the layout model.Any floating-point number between 0-1. If not set, the parameter value initialized by the pipeline will be used, which is initialized to 0.5 by default.
      floatWhether to use post-processing NMS for layout detection. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool
      layout_unclip_ratioThe expansion coefficient of the detection box for the layout area detection model. Any floating-point number greater than 0. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is 1.0.
      floatlayout_merge_bboxes_mode
        +
      • The merging processing mode for the detection boxes output by the model in layout detection.large
      • +
      • , when set to large, it means that among the detection boxes output by the model, for the detection boxes that overlap and contain each other, only the largest outer box is retained, and the overlapping inner boxes are deleted;small
      • +
      • , when set to small, it means that among the detection boxes output by the model, for the detection boxes that overlap and contain each other, only the small inner box that is contained is retained, and the overlapping outer boxes are deleted;union
      • +
      , no filtering processing is performed on the boxes, and both inner and outer boxes are retained;If not set, the parameter value initialized by the pipeline will be used, and the default initialization is large
      .
      strchart_recognition_model_nameThe model name for chart parsing. If not set, the default model of the pipeline will be used.
      strchart_recognition_model_dirThe directory path for the chart parsing model. If not set, the official model will be downloaded.
      strchart_recognition_batch_sizeThe batch size for the chart parsing model. If not set, the batch size will be set to int
      region_detection_model_nameName of the model for detecting submodules of document image layout. If not set, the default model in the pipeline will be used.str
      region_detection_model_dirDirectory path of the model for detecting submodules of document image layout. If not set, the official model will be downloaded.str
      doc_orientation_classify_model_nameName of the model for document orientation classification. If not set, the default model in the pipeline will be used.str
      doc_orientation_classify_model_dirDirectory path of the model for document orientation classification. If not set, the official model will be downloaded.str
      doc_unwarping_model_nameName of the model for text image unwarping. If not set, the default model in the pipeline will be used.str
      doc_unwarping_model_dirDirectory path of the model for text image unwarping. If not set, the official model will be downloaded.str
      text_detection_model_nameName of the model for text detection. If not set, the default model in the pipeline will be used.str
      text_detection_model_dirDirectory path of the model for text detection. If not set, the official model will be downloaded.str
      text_det_limit_side_lenLimit on the side length of the image for text detection. +Any integer greater than 0. If not set, the parameter value initialized in the pipeline will be used, and the default initialization value is 960int
      text_det_limit_typeType of image side length limit for text detection. It supportsminandmax,minmeans ensuring that the shortest side of the image is not less thandet_limit_side_len,maxmeans ensuring that the longest side of the image is not greater thanlimit_side_len. If not set, the parameter value initialized by the pipeline will be used, and the default initialization ismax.str
      text_det_threshDetection pixel threshold. Only pixels with scores greater than this threshold in the output probability map will be considered as text pixels. +Any floating-point number greater than0. If not set, the parameter value initialized by the pipeline will be used by default,0.3.float
      text_det_box_threshDetection box threshold. When the average score of all pixels within the detection result border is greater than this threshold, the result will be considered as a text area. Any floating-point number greater than0. If not set, the parameter value initialized by the pipeline will be used by default,0.6.float
      text_det_unclip_ratioText detection expansion coefficient. This method is used to expand the text area. The larger the value, the larger the expanded area. +Any floating-point number greater than0. If not set, the parameter value initialized by the pipeline will be used by default,2.0.float
      textline_orientation_model_nameName of the text line orientation model. If not set, the default model in the pipeline will be used.str
      textline_orientation_model_dirDirectory path of the text line orientation model. If not set, the official model will be downloaded.str
      textline_orientation_batch_sizeBatch size of the text line orientation model. If not set, the batch size will be set to 1 by default.int
      text_recognition_model_nameName of the text recognition model. If not set, the default model in the pipeline will be used.str
      text_recognition_model_dirDirectory path of the text recognition model. If not set, the official model will be downloaded.str
      text_recognition_batch_sizeBatch size of the text recognition model. If not set, the batch size will be set to 1 by default.int
      text_rec_score_threshText recognition threshold. Text results with scores greater than this threshold will be retained. Any floating-point number greater than 0. If not set, the parameter value initialized in the pipeline, 0.0, will be used by default. That is, no threshold is set.
      floattable_classification_model_nameName of the table classification model. If not set, the default model in the pipeline will be used.
      table_classification_model_dirThe directory path of the table classification model. If not set, the official model will be downloaded.str
      wired_table_structure_recognition_model_nameThe name of the wired table structure recognition model. If not set, the default model in the pipeline will be used.str
      wired_table_structure_recognition_model_dirThe directory path of the wired table structure recognition model. If not set, the official model will be downloaded.str
      wireless_table_structure_recognition_model_nameThe name of the wireless table structure recognition model. If not set, the default model in the pipeline will be used.str
      wireless_table_structure_recognition_model_dirThe directory path of the wireless table structure recognition model. If not set, the official model will be downloaded.str
      wired_table_cells_detection_model_nameThe name of the wired table cells detection model. If not set, the default model in the pipeline will be used.str
      wired_table_cells_detection_model_dirThe directory path of the wired table cells detection model. If not set, the official model will be downloaded.str
      wireless_table_cells_detection_model_nameThe name of the wireless table cells detection model. If not set, the default model in the pipeline will be used.str
      wireless_table_cells_detection_model_dirDirectory path of the wireless table cell detection model. If not set, the official model will be downloaded.str
      table_orientation_classify_model_nameName of the table orientation classification model. If not set, the default model in the pipeline will be used.str
      table_orientation_classify_model_dirDirectory path of the table orientation classification model. If not set, the official model will be downloaded.str
      seal_text_detection_model_nameName of the seal text detection model. If not set, the default model in the pipeline will be used.str
      seal_text_detection_model_dirDirectory path of the seal text detection model. If not set, the official model will be downloaded.str
      seal_det_limit_side_lenLimit on the side length of the image for seal text detection. Any integer greater than 0. If not set, the parameter value initialized in the pipeline will be used, which is initialized to 736 by default.
      intseal_det_limit_typeType of the side length limit for seal text detection image. Supports min and max, where min means ensuring that the shortest side of the image is not less than det_limit_side_len, and maxlimit_side_len. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is min.str
      seal_det_threshDetection pixel threshold. Only pixels with scores greater than this threshold in the output probability map will be considered as text pixels. +Any floating-point number greater than 0. If not set, the parameter value initialized by the pipeline will be used by default, which is 0.2.float
      seal_det_box_threshDetection box threshold. When the average score of all pixels within the bounding box of the detection result is greater than this threshold, the result will be considered as a text region. +Any floating-point number greater than 0. If not set, the parameter value initialized by the pipeline will be used by default, which is 0.6.float
      seal_det_unclip_ratioExpansion coefficient for seal text detection. This method is used to expand the text region. The larger the value, the larger the expanded area. +Any floating-point number greater than 0. If not set, the parameter value initialized by the pipeline will be used by default, which is 0.5.float
      seal_text_recognition_model_nameName of the seal text recognition model. If not set, the default model of the pipeline will be used.str
      seal_text_recognition_model_dirDirectory path of the seal text recognition model. If not set, the official model will be downloaded.str
      seal_text_recognition_batch_sizeThe batch size of the seal text recognition model. If not set, the batch size will be set to 1 by default.int
      seal_rec_score_threshText recognition threshold. Text results with scores greater than this threshold will be retained. Any floating-point number greater than 0. If not set, the parameter value initialized by the pipeline will be used by default, which is 0.0. That is, no threshold is set.
      floatformula_recognition_model_nameThe name of the formula recognition model. If not set, the default model of the pipeline will be used.
      strformula_recognition_model_dirThe directory path of the formula recognition model. If not set, the official model will be downloaded.
      strformula_recognition_batch_sizeThe batch size of the formula recognition model. If not set, the batch size will be set to 1 by default.
      intuse_doc_orientation_classifyWhether to use the document orientation classification module.bool
      Falseuse_doc_unwarpingWhether to use the text image unwarping module.bool
      Falseuse_textline_orientationWhether to load and use the text line orientation classification module. If not set, the parameter value initialized by the pipeline will be used, which is initialized to True by default.
      use_seal_recognitionWhether to load and use the seal text recognition sub-pipeline. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool
      use_table_recognitionWhether to load and use the table recognition sub-pipeline. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool
      use_formula_recognitionWhether to load and use the formula recognition sub-pipeline. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool
      use_chart_recognitionWhether to use the chart parsing module.boolFalse
      use_region_detectionWhether to load and use the document region detection sub-pipeline. If not set, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool
      deviceThe device used for inference. It supports specifying a specific card number:
        +
      • CPU: For example, cpu means using CPU for inference;
      • +
      • GPU: For example, gpu:0 means using the first GPU for inference;
      • +
      • NPU: For example, npu:0 means using the first NPU for inference;
      • +
      • XPU: For example, xpu:0Indicates the use of the first XPU for inference;
      • +
      • MLU: e.g.,mlu:0Indicates the use of the first MLU for inference;
      • +
      • DCU: e.g.,dcu:0Indicates the use of the first DCU for inference;
      • +
      If not set, the parameter value initialized by the pipeline will be used by default. During initialization, the local GPU device 0 will be used preferentially. If not available, the CPU device will be used.
      str
      enable_hpiWhether to enable high-performance inference.boolFalse
      use_tensorrtWhether to enable the TensorRT subgraph engine of Paddle Inference. If the model does not support acceleration via TensorRT, acceleration will not be used even if this flag is set.
      For PaddlePaddle with CUDA 11.8, the compatible TensorRT version is 8.x (x>=6), and it is recommended to install TensorRT 8.6.1.6.
      For PaddlePaddle with CUDA 12.6, the compatible TensorRT version is 10.x (x>=5), and it is recommended to install TensorRT 10.5.0.18.
      boolFalse
      precisionComputational precision, such as fp32, fp16.strfp32
      enable_mkldnnWhether to enable MKL-DNN accelerated inference. If MKL-DNN is not available or the model does not support acceleration via MKL-DNN, acceleration will not be used even if this flag is set.boolTrue
      mkldnn_cache_capacityMKL-DNN cache capacity.int10
      cpu_threadsNumber of threads used for inference on CPU.int8
      paddlex_configPath to the PaddleX pipeline configuration file.str
      +
      +
      + +The execution results will be printed to the terminal. + +### 2.2 Integration via Python Script + +The command-line method is for quickly experiencing and viewing the results. Generally, in projects, integration via code is often required. You can download the [test file](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png) and use the following sample code for inference: + +```python +from paddlex import create_pipeline +# Create a translation pipeline +pipeline = create_pipeline(pipeline="PP-DocTranslation") + +# Document path +input_path = "document_sample.pdf" + +# Output directory +output_path = "./output" + +# Large model configuration +chat_bot_config = { + "module_name": "chat_bot", + "model_name": "ernie-3.5-8k", + "base_url": "https://qianfan.baidubce.com/v2", + "api_type": "openai", + "api_key": "api_key", # your api_key +} + +if input_path.lower().endswith(".md"): + # Read markdown documents, supporting passing in directories and url links with the .md suffix + ori_md_info_list = pipeline.load_from_markdown(input_path) +else: + # Use PP-StructureV3 to perform layout parsing on PDF/image documents to obtain markdown information + visual_predict_res = pipeline.visual_predict( + input_path, + use_doc_orientation_classify=False, + use_doc_unwarping=False, + use_common_ocr=True, + use_seal_recognition=True, +use_table_recognition=True, + ) + + ori_md_info_list = [] + for res in visual_predict_res: + layout_parsing_result = res["layout_parsing_result"] + ori_md_info_list.append(layout_parsing_result.markdown) + layout_parsing_result.save_to_img(output_path) + layout_parsing_result.save_to_markdown(output_path) + + # Concatenate the markdown information of multi-page documents into a single markdown file, and save the merged original markdown text + if input_path.lower().endswith(".pdf"): + ori_md_info = pipeline.concatenate_markdown_pages(ori_md_info_list) + ori_md_info.save_to_markdown(output_path) + +# Perform document translation (target language: English) +tgt_md_info_list = pipeline.translate( + ori_md_info_list=ori_md_info_list, + target_language="en", + chunk_size=5000, + chat_bot_config=chat_bot_config, +) +# Save the translation results +for tgt_md_info in tgt_md_info_list: + tgt_md_info.save_to_markdown(output_path) +``` + +After executing the above code, you will obtain the parsed results of the original document to be translated, the Markdown file of the original text to be translated, and the Markdown file of the translated document, all saved in the `output` directory. + +The process, API description, and output description of PP-DocTranslation prediction are as follows: + +
      (1) CallPPDocTranslationInstantiate a PP-DocTranslation pipeline object.The descriptions of relevant parameters are as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ParameterDescriptionParameter TypeDefault Value
      layout_detection_model_nameThe model name for layout area detection. If set to None, the default model of the pipeline will be used.str|NoneNone
      layout_detection_model_dirThe directory path of the layout area detection model. If set to None, the official model will be downloaded.str|NoneNone
      layout_thresholdThe score threshold for the layout model.
        +
      • float:Any floating-point number between 0-1
      • +
      • ;dict:{0:0.1}
      • +
      • where the key is the class ID and the value is the threshold for that class;None: If set to None, the parameter value initialized by the pipeline will be used, which is initialized to 0.5
      • +
      +
      by default.float|dict|None
      Nonelayout_nmsWhether to use post-processing NMS for layout detection. If set to None, the parameter value initialized by the pipeline will be used, which is initialized to True by default.bool|None
      layout_unclip_ratioExpansion coefficient of the detection box for the layout area detection model.
        +
      • float: any floating-point number greater than 0;
      • +
      • Tuple[float,float]: expansion coefficients in the horizontal and vertical directions respectively;
      • +
      • dict, where the key of the dict is of int type, representing cls_id, and the value is of tuple type, such as {0: (1.1, 2.0)}, indicating that the center of the detection box for category 0 output by the model remains unchanged, with the width expanded by 1.1 times and the height expanded by 2.0 times;
      • +
      • None: if set to None, the parameter value initialized by the pipeline will be used, which is initialized to 1.0 by default.
      • +
      +
      float|Tuple[float,float]|dict|NoneNone
      layout_merge_bboxes_modeFiltering method for overlapping boxes in layout area detection.
        +
      • str: large, small, union, indicating whether to retain the large box, small box, or both during overlapping box filtering, respectively;
      • +
      • dict: the key of the dict is of int type, representing cls_id, and the value is of str type, such as {0: "large", 2: "small"}, which means using the large mode for detection boxes of category 0 and the small mode for detection boxes of category 2;
      • +
      • None: If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is large.
      • +
      +
      str|dict|NoneNone
      chart_recognition_model_nameThe model name for chart parsing. If set to None, the default model of the pipeline will be used.str|NoneNone
      chart_recognition_model_dirThe directory path of the model for chart parsing. If set to None, the official model will be downloaded.str|NoneNone
      chart_recognition_batch_sizeThe batch size of the model for chart parsing. If set to None, the batch size will be set to 1 by default.int|NoneNone
      region_detection_model_nameThe model name for detecting submodules of document image layout. If set to None, the default model of the pipeline will be used.str|NoneNone
      region_detection_model_dirThe directory path of the model for detecting submodules of document image layout. If set to None, the official model will be downloaded.str|NoneNone
      doc_orientation_classify_model_nameName of the document orientation classification model. If set to None, the default model in the pipeline will be used.str|NoneNone
      doc_orientation_classify_model_dirDirectory path of the document orientation classification model. If set to None, the official model will be downloaded.str|NoneNone
      doc_unwarping_model_nameName of the text image unwarping model. If set to None, the default model in the pipeline will be used.str|NoneNone
      doc_unwarping_model_dirDirectory path of the text image unwarping model. If set to None, the official model will be downloaded.str|NoneNone
      text_detection_model_nameName of the text detection model. If set to None, the default model in the pipeline will be used.str|NoneNone
      text_detection_model_dirDirectory path of the text detection model. If set to None, the official model will be downloaded.str|NoneNone
      text_det_limit_side_lenLimit on the side length of the image for text detection.
        +
      • int: greater than0, any integer;
      • +
      • None: if set toNone, the parameter value initialized by the pipeline will be used, and the default initialization value is960.
      • +
      +
      int|NoneNone
      text_det_limit_typeThe type of image side length limit for text detection.
        +
      • str: supportsminandmax, whereminmeans ensuring that the shortest side of the image is not less thandet_limit_side_len, andmaxmeans ensuring that the longest side of the image is not greater thanlimit_side_len;
      • +
      • None: if set toNone, the parameter value initialized by the pipeline will be used, and the default initialization value ismax.
      • +
      +
      str|NoneNone
      text_det_threshDetection pixel threshold. Only pixels with scores greater than this threshold in the output probability map will be considered as text pixels.
        +
      • float: any floating-point number greater than0;
      • None: if set toNone, the parameter value initialized by the pipeline will be used by default,0.3.
      +
      float|NoneNone
      text_det_box_threshDetection box threshold: When the average score of all pixels within the detected bounding box is greater than this threshold, the result is considered a text region.
        +
      • float: any floating-point number greater than0;
      • None: If set toNone, the parameter value initialized by the pipeline, 0.6, will be used by default.
      +
      float|NoneNone
      text_det_unclip_ratioText detection expansion coefficient. This method is used to expand the text region. The larger the value, the larger the expanded area.
        +
      • float: any floating-point number greater than0;
      • None: If set toNone, the parameter value initialized by the pipeline, 2.0, will be used by default.
      +
      float|NoneNone
      textline_orientation_model_nameName of the text line orientation model. If set toNone, the default model of the pipeline will be used.str|NoneNone
      textline_orientation_model_dirDirectory path of the text line orientation model. If set toNone, the official model will be downloaded.str|NoneNone
      textline_orientation_batch_sizeBatch size of the text line orientation model. If set toNoneSet the default batch size to 1.int|NoneNone
      text_recognition_model_nameThe name of the text recognition model. If set to None, the default model in the pipeline will be used.str|NoneNone
      text_recognition_model_dirThe directory path of the text recognition model. If set to None, the official model will be downloaded.str|NoneNone
      text_recognition_batch_sizeThe batch size of the text recognition model. If set to None, the default batch size will be set to 1.int|NoneNone
      text_rec_score_threshThe threshold for text recognition. Text results with scores higher than this threshold will be retained.
        +
      • float: Any floating-point number greater than 0;
      • None: If set to None, the parameter value initialized by the pipeline, 0.0, will be used by default, meaning no threshold will be set.
      +
      float|NoneNone
      table_classification_model_nameThe name of the table classification model. If set to None, the default model in the pipeline will be used.str|NoneNone
      table_classification_model_dirThe directory path of the table classification model. If set to None, the official model will be downloaded.str|NoneNone
      wired_table_structure_recognition_model_nameThe name of the wired table structure recognition model. If set to None, the default model in the pipeline will be used.str|NoneNone
      wired_table_structure_recognition_model_dirThe directory path of the wired table structure recognition model. If set to None, the official model will be downloaded.str|NoneNone
      wireless_table_structure_recognition_model_nameThe name of the wireless table structure recognition model. If set to None, the default model in the pipeline will be used.str|NoneNone
      wireless_table_structure_recognition_model_dirThe directory path of the wireless table structure recognition model. If set to None, the official model will be downloaded.str|NoneNone
      wired_table_cells_detection_model_nameThe name of the wired table cell detection model. If set to None, the default model in the pipeline will be used.str|NoneNone
      wired_table_cells_detection_model_dirThe directory path of the wired table cell detection model. If set to None, the official model will be downloaded.str|NoneNone
      wireless_table_cells_detection_model_nameThe name of the wireless table cell detection model. If set to None, the default model in the pipeline will be used.str|NoneNone
      wireless_table_cells_detection_model_dirThe directory path of the wireless table cell detection model. If set to None, the official model will be downloaded.str|NoneNone
      table_orientation_classify_model_nameThe name of the table orientation classification model. If set to None, the default model in the pipeline will be used.str|NoneNone
      table_orientation_classify_model_dirThe directory path of the table orientation classification model. If set to None, the official model will be downloaded.str|NoneNone
      seal_text_detection_model_nameThe name of the seal text detection model. If set to None, the default model in the pipeline will be used.str|NoneNone
      seal_text_detection_model_dirThe directory path of the seal text detection model. If set to None, the official model will be downloaded.str|NoneNone
      seal_det_limit_side_lenThe image side length limit for seal text detection.
        +
      • int: any integer greater than 0;
      • +
      • None: If set to None, the parameter value initialized by the pipeline will be used, and the default initialization value is 736.
      • +
      +
      int|NoneNone
      seal_det_limit_typeThe image side length limit type for seal text detection.
        +
      • str: supports min and max, where min indicates that the shortest side of the image is guaranteed to be no less than det_limit_side_len, and max indicates that the longest side of the image is guaranteed to be no greater than limit_side_len;
      • +
      • None: If set to None, the parameter value initialized by the pipeline will be used, and the default initialization value is min.
      • +
      +
      str|NoneNone
      seal_det_threshThe detection pixel threshold. Only pixels with scores greater than this threshold in the output probability map will be considered as text pixels.
        +
      • float: any floating-point number greater than 0;
      • None: if set to None, the parameter value initialized by the pipeline will be used by default, which is 0.2.
      +
      float|NoneNone
      seal_det_box_threshDetection box threshold. When the average score of all pixels within the detected bounding box is greater than this threshold, the result is considered a text region.
        +
      • float: any floating-point number greater than 0;
      • None: if set to None, the parameter value initialized by the pipeline will be used by default, which is 0.6.
      +
      float|NoneNone
      seal_det_unclip_ratioExpansion coefficient for seal text detection. This method is used to expand the text region. The larger the value, the larger the expanded area.
        +
      • float: any floating-point number greater than 0;
      • None: if set to None, the parameter value initialized by the pipeline will be used by default, which is 0.5.
      +
      float|NoneNone
      seal_text_recognition_model_nameName of the seal text recognition model. If set to None, the default model of the pipeline will be used.str|NoneNone
      seal_text_recognition_model_dirDirectory path of the seal text recognition model. If set to None, the official model will be downloaded.str|NoneNone
      seal_text_recognition_batch_sizeBatch size of the seal text recognition model. If set to None, the batch size will be set to 1 by default.int|NoneNone
      seal_rec_score_threshThreshold for seal text recognition. Text results with scores higher than this threshold will be retained.
        +
      • float: any floating-point number greater than 0;
      • None: if set to None, the parameter value initialized by the pipeline, 0.0, will be used by default, meaning no threshold is set.
      +
      float|NoneNone
      formula_recognition_model_nameName of the formula recognition model. If set to None, the default model of the pipeline will be used.str|NoneNone
      formula_recognition_model_dirDirectory path of the formula recognition model. If set to None, the official model will be downloaded.str|NoneNone
      formula_recognition_batch_sizeThe batch size of the formula recognition model. If set to None, the batch size will be set to 1 by default.int|NoneNone
      use_doc_orientation_classifyWhether to load and use the document orientation classification module. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_doc_unwarpingWhether to load and use the text image unwarping module. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_textline_orientationWhether to load and use the text line orientation classification module. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_seal_recognitionWhether to load and use the sub-pipeline for seal text recognition. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_table_recognitionWhether to load and use the sub-pipeline for table recognition. If set to NoneThe parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_formula_recognitionWhether to load and use the sub-pipeline for formula recognition. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_chart_recognitionWhether to load and use the chart parsing module. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      use_region_detectionWhether to load and use the sub-pipeline for document region detection. If set to None, the parameter value initialized by the pipeline will be used, and the default initialization is True.bool|NoneNone
      chat_bot_configConfiguration information for the large language model. The configuration content is the following dict:
      {
      +"module_name": "chat_bot",
      +"model_name": "ernie-3.5-8k",
      +"base_url": "https://qianfan.baidubce.com/v2",
      +"api_type": "openai",
      +"api_key": "api_key"  # Please set this to the actual API key
      +}
      +
      dict|NoneNone
      deviceDevice for inference. Support specifying a specific card number:
        +
      • CPU: e.g.,cpumeans using CPU for inference;
      • +
      • GPU: e.g.,gpu:0means using the 1st GPU for inference;
      • +
      • NPU: e.g.,npu:0means using the 1st NPU for inference;
      • +
      • XPU: e.g.,xpu:0means using the 1st XPU for inference;
      • +
      • MLU: e.g.,mlu:0means using the 1st MLU for inference;
      • +
      • DCU: e.g.,dcu:0means using the 1st DCU for inference;
      • +
      • None: If set toNone, during initialization, the local GPU device 0 will be used preferentially. If not available, the CPU device will be used.
      • +
      +
      str|NoneNone
      enable_hpiWhether to enable high-performance inference.boolFalse
      use_tensorrtWhether to enable the TensorRT subgraph engine of Paddle Inference. If the model does not support acceleration via TensorRT, acceleration will not be used even if this flag is set.
      For PaddlePaddle with CUDA 11.8, the compatible TensorRT version is 8.x (x>=6), and it is recommended to install TensorRT 8.6.1.6.
      For PaddlePaddle with CUDA 12.6, the compatible TensorRT version is 10.x (x>=5), and it is recommended to install TensorRT 10.5.0.18.
      boolFalse
      precisionComputational precision, such as fp32, fp16.str"fp32"
      enable_mkldnnWhether to enable MKL-DNN for accelerated inference. If MKL-DNN is not available or the model does not support acceleration via MKL-DNN, acceleration will not be used even if this flag is set.boolTrue
      mkldnn_cache_capacityMKL-DNN cache capacity.int10
      cpu_threadsThe number of threads used for inference on the CPU.int8
      paddlex_configPath to the PaddleX pipeline configuration file.str|NoneNone
      +
      +
      (2) Call the visual_predict()method of the PP-DocTranslation pipeline object to obtain visual prediction results. This method returns a list of results. Additionally, the pipeline also provides the visual_predict_iter()method. Both methods are identical in terms of parameter acceptance and result return. The difference is that visual_predict_iter()returns a generatorthat can process and obtain prediction results step by step, which is suitable for scenarios involving large datasets or where memory conservation is desired. Either of these two methods can be chosen based on actual needs. Below is visual_predict()Parameters of the method and their descriptions: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ParameterDescriptionParameter TypeDefault Value
      inputData to be predicted, supporting multiple input types, required.
        +
      • Python Var: such asnumpy.ndarrayrepresenting image data;
      • +
      • str: such as the local path of an image file or PDF file:/root/data/img.jpg;such as URL links, such as the network URL of an image file or PDF file:Example;such as local directories, which should contain images to be predicted, such as the local path:/root/data/(Currently, prediction for PDF files within directories is not supported. PDF files need to be specified to their exact file paths);
      • +
      • list: List elements should be of the aforementioned data types, such as[numpy.ndarray, numpy.ndarray],["/root/data/img1.jpg", "/root/data/img2.jpg"],["/root/data1", "/root/data2"].
      • +
      +
      Python Var|str|list
      use_doc_orientation_classifyWhether to use the document orientation classification module during inference. Setting it toNonemeans using the instantiation parameter; otherwise, this parameter takes precedence.bool|NoneFalse
      use_doc_unwarpingWhether to use the text image unwarping module during inference. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneFalse
      use_textline_orientationWhether to use the text line orientation classification module during inference. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneNone
      use_seal_recognitionWhether to use the seal text recognition sub-pipeline during inference. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneNone
      use_table_recognitionWhether to use the table recognition sub-pipeline during inference. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneNone
      use_formula_recognitionWhether to use the formula recognition sub-pipeline during inference. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneNone
      use_chart_recognitionWhether to use the chart parsing module. Set to None to use the instantiated parameter; otherwise, this parameter takes precedence.bool|NoneFalse
      use_region_detectionWhether to use the sub-pipeline for document region detection. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.bool|NoneNone
      layout_thresholdThe parameter meaning is basically the same as the instantiation parameter. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.float|dict|NoneNone
      layout_nmsThe parameter meaning is basically the same as the instantiation parameter. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.bool|NoneNone
      layout_unclip_ratioThe parameter meaning is basically the same as the instantiation parameter. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.float|Tuple[float,float]|dict|NoneNone
      layout_merge_bboxes_modeThe parameter meaning is basically the same as the instantiation parameter. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.str|dict|NoneNone
      text_det_limit_side_lenThe parameter meaning is basically the same as the instantiation parameter. Set to None to use the instantiation parameter; otherwise, this parameter takes precedence.int|NoneNone
      text_det_limit_typeThe parameter meaning is basically the same as the instantiation parameter. Set to NoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.str|NoneNone
      text_det_threshThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.float|NoneNone
      text_det_box_threshThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.float|NoneNone
      text_det_unclip_ratioThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.float|NoneNone
      text_rec_score_threshThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.float|NoneNone
      seal_det_limit_side_lenThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.int|NoneNone
      seal_det_limit_typeThe parameter meaning is basically the same as the instantiation parameter. Set toNoneIt indicates the use of instantiation parameters; otherwise, this parameter takes precedence.str|NoneNone
      seal_det_threshThe parameter meaning is basically the same as the instantiation parameter. Set to Noneto use the instantiation parameter; otherwise, this parameter takes precedence.float|NoneNone
      seal_det_box_threshThe parameter meaning is basically the same as the instantiation parameter. Set to Noneto use the instantiation parameter; otherwise, this parameter takes precedence.float|NoneNone
      seal_det_unclip_ratioThe parameter meaning is basically the same as the instantiation parameter. Set to Noneto use the instantiation parameter; otherwise, this parameter takes precedence.float|NoneNone
      seal_rec_score_threshThe parameter meaning is basically the same as the instantiation parameter. Set to Noneto use the instantiation parameter; otherwise, this parameter takes precedence.float|NoneNone
      use_wired_table_cells_trans_to_htmlWhether to enable direct conversion of wired table cell detection results to HTML. If enabled, HTML is constructed directly based on the geometric relationships of wired table cell detection results.boolFalse
      use_wireless_table_cells_trans_to_htmlWhether to enable direct conversion of wireless table cell detection results to HTML. If enabled, HTML is constructed directly based on the geometric relationships of wireless table cell detection results.boolFalse
      use_table_orientation_classifyWhether to enable table orientation classification. When enabled, if the table in the image is rotated by 90/180/270 degrees, the orientation can be corrected and table recognition can be completed correctly.boolTrue
      use_ocr_results_with_table_cellsWhether to enable cell-segmented OCR. When enabled, OCR detection results will be segmented and re-recognized based on cell prediction results to avoid missing text.boolTrue
      use_e2e_wired_table_rec_modelWhether to enable the end-to-end wired table recognition mode. If enabled, the cell detection model will not be used, and only the table structure recognition model will be used.boolFalse
      use_e2e_wireless_table_rec_modelWhether to enable the end-to-end wireless table recognition mode. If enabled, the cell detection model will not be used, and only the table structure recognition model will be used.boolTrue
      +
      +
      (3) Processing visual prediction results: The prediction result for each sample is a corresponding Result object, and it supports operations such as printing, saving as an image, and saving as a json file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      MethodMethod DescriptionParameterParameter TypeParameter DescriptionDefault Value
      print()Print the result to the terminalformat_jsonboolWhether to use indentation formatting for the output content in JSON formatTrue
      indentintSpecify the indentation level to beautify the outputJSONdata to make it more readable, valid only whenformat_jsonisTrue.4
      ensure_asciiboolcontrols whether non-ASCIIcharacters are escaped toUnicode. When set toTrue, all non-ASCIIcharacters will be escaped;Falsewill retain the original characters, valid only whenformat_jsonisTrue.False
      save_to_json()Saves the result as a file in json formatsave_pathstrThe path where the file is saved. When it is a directory, the saved file name is consistent with the input file type name.None
      indentintSpecifies the indentation level to beautify the outputJSONdata to make it more readable, valid only whenformat_jsonisTrue.4
      ensure_asciiboolcontrols whether non-ASCIIcharacters are escaped toUnicode. When set toTrue, all non-ASCIIcharacters will be escaped;Falsewill retain the original characters, valid only whenformat_jsonValid whenTrueis setFalse
      save_to_img()Saves the visualized images of each intermediate module in PNG formatsave_pathstrThe file path for saving, which supports directory or file pathNone
      save_to_markdown()Saves each page of an image or PDF file as a separate file in markdown formatsave_pathstrThe file path for saving, which supports directory or file pathNone
      save_to_html()Saves tables in a file as a file in html formatsave_pathstrThe file path for saving, which supports directory or file pathNone
      save_to_xlsx()Saves tables in a file as a file in xlsx formatsave_pathstrThe file path for saving, which supports directory or file pathNone
      - Calling the `print()` method will print the results to the terminal, and the content printed to the terminal is explained as follows: + - `input_path`: `(str)` The input path of the image or PDF to be predicted + + - `page_index`: `(Union[int, None])` If the input is a PDF file, it indicates which page of the PDF it is; otherwise, it is `None` + + - `model_settings`: `(Dict[str, bool])` Configure the model parameters required for the pipeline + + - `use_doc_preprocessor`: `(bool)` Controls whether to enable the document preprocessing sub-pipeline + - `use_general_ocr`: `(bool)` Controls whether to enable the OCR sub-pipeline + - `use_seal_recognition`: `(bool)` Controls whether to enable the seal recognition sub-pipeline + - `use_table_recognition`: `(bool)` Controls whether to enable the table recognition sub-pipeline + - `use_formula_recognition`: `(bool)` Controls whether to enable the formula recognition sub-pipeline + + - `doc_preprocessor_res`: `(Dict[str, Union[List[float], str]])` A dictionary of document preprocessing results, which only exists when `use_doc_preprocessor=True` + - `input_path`: `(str)` The image path accepted by the document preprocessing sub-pipeline. When the input is `numpy.ndarray`, it is saved as `None`, and it is `None` here + - `page_index`: `None`, as the input here is `numpy.ndarray`, so the value is `None` + - `model_settings`: `(Dict[str, bool])` The model configuration parameters for the document preprocessing sub-pipeline +- `use_doc_orientation_classify`: `(bool)` Controls whether to enable the document image orientation classification submodule. + - `use_doc_unwarping`: `(bool)` Controls whether to enable the text image unwarping submodule. + - `angle`: `(int)` The prediction result of the document image orientation classification submodule. Returns the actual angle value when enabled. + + - `parsing_res_list`: `(List[Dict])` A list of parsing results, where each element is a dictionary. The list is in the reading order after parsing. + - `block_bbox`: `(np.ndarray)` The bounding box of the layout area. + - `block_label`: `(str)` The label of the layout area, such as `text`, `table`, etc. + - `block_content`: `(str)` The content within the layout area. + - `seg_start_flag`: `(bool)` Indicates whether this layout area is the start of a paragraph. + - `seg_end_flag`: `(bool)` Indicates whether this layout area is the end of a paragraph. + - `sub_label`: `(str)` The sub-label of the layout area. For example, the sub-label of `text` might be `title_text`. + - `sub_index`: `(int)` The sub-index of the layout area, used for restoring Markdown. + - `index`: `(int)` The index of the layout area, used for displaying the layout sorting results. + + - `overall_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` A dictionary of global OCR results. +- `input_path`: `(Union[str, None])` The image path accepted by the image OCR sub-pipeline. When the input is `numpy.ndarray`, it is saved as `None`. + - `page_index`: `None`. The input here is `numpy.ndarray`, so the value is `None`. + - `model_settings`: `(Dict)` Model configuration parameters for the OCR sub-pipeline. + - `dt_polys`: `(List[numpy.ndarray])` List of polygon bounding boxes for text detection. Each bounding box is represented by a numpy array consisting of 4 vertex coordinates, with an array shape of (4, 2) and a data type of int16. + - `dt_scores`: `(List[float])` List of confidence scores for text detection bounding boxes. + - `text_det_params`: `(Dict[str, Dict[str, int, float]])` Configuration parameters for the text detection module. + - `limit_side_len`: `(int)` The side length limit value during image preprocessing. + - `limit_type`: `(str)` The processing method for the side length limit. + - `thresh`: `(float)` The confidence threshold for text pixel classification. + - `box_thresh`: `(float)` The confidence threshold for text detection bounding boxes. + - `unclip_ratio`: `(float)` The dilation coefficient for text detection bounding boxes. + - `text_type`: `(str)` The type of text detection, currently fixed as "general". + + - `text_type`: `(str)` The type of text detection, currently fixed as "general". + - `textline_orientation_angles`: `(List[int])` The prediction results for text line orientation classification. +Returns the actual angle value when enabled (e.g., [0,0,1]) + - `text_rec_score_thresh`: `(float)` The filtering threshold for text recognition results + - `rec_texts`: `(List[str])` A list of text recognition results, containing only texts with confidence scores exceeding `text_rec_score_thresh` + - `rec_scores`: `(List[float])` A list of confidence scores for text recognition, filtered by `text_rec_score_thresh` + - `rec_polys`: `(List[numpy.ndarray])` A list of text detection bounding boxes filtered by confidence scores, with the same format as `dt_polys` + + - `formula_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` A list of formula recognition results, with each element being a dictionary + - `rec_formula`: `(str)` The recognized formula result + - `rec_polys`: `(numpy.ndarray)` The bounding box of the recognized formula, with a shape of (4, 2) and a dtype of int16 + - `formula_region_id`: `(int)` The region number where the formula is located + + - `seal_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` A list of seal recognition results, with each element being a dictionary + - `input_path`: `(str)` The input path of the seal image + - `page_index`: `None`, as the input here is `numpy.ndarray`, so the value is `None` + - `model_settings`: `(Dict)` Model configuration parameters for the seal recognition sub-pipeline +- `dt_polys`: `(List[numpy.ndarray])` A list of detected bounding boxes for seals, with the same format as `dt_polys` + - `text_det_params`: `(Dict[str, Dict[str, int, float]])` Configuration parameters for the seal detection module, with the same parameter meanings as above + - `text_type`: `(str)` The type of seal detection, currently fixed as "seal" + - `text_rec_score_thresh`: `(float)` The filtering threshold for seal recognition results + - `rec_texts`: `(List[str])` A list of seal recognition results, containing only texts with confidence scores exceeding `text_rec_score_thresh` + - `rec_scores`: `(List[float])` A list of confidence scores for seal recognition, filtered by `text_rec_score_thresh` + - `rec_polys`: `(List[numpy.ndarray])` A list of detected bounding boxes for seals after confidence filtering, with the same format as `dt_polys` + - `rec_boxes`: `(numpy.ndarray)` An array of rectangular bounding boxes for detected boxes, with a shape of (n, 4) and dtype of int16. Each row represents a rectangle + + - `table_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` A list of table recognition results, with each element being a dictionary + - `cell_box_list`: `(List[numpy.ndarray])` A list of bounding boxes for table cells + - `pred_html`: `(str)` An HTML-formatted string for the table + - `table_ocr_pred`: `(dict)` OCR recognition results for the table +- `rec_polys`: `(List[numpy.ndarray])` A list of detection bounding boxes for cells + - `rec_texts`: `(List[str])` Recognition results for cells + - `rec_scores`: `(List[float])` Recognition confidence scores for cells + - `rec_boxes`: `(numpy.ndarray)` An array of rectangular bounding boxes for detection boxes, with a shape of (n, 4) and a dtype of int16. Each row represents a rectangle + +- Calling the `save_to_json()` method will save the above content to the specified `save_path`. If a directory is specified, the saved path will be `save_path/{your_img_basename}_res.json`. If a file is specified, it will be saved directly to that file. Since JSON files do not support saving numpy arrays, the `numpy.array` types within will be converted to list form. +- Calling the `save_to_img()` method will save the visualization results to the specified `save_path`. If a directory is specified, it will save the visualization images for layout region detection, global OCR, layout reading order, etc. If a file is specified, it will be saved directly to that file. +(The pipeline usually contains many result images, and it is not recommended to directly specify a specific file path; otherwise, multiple images will be overwritten, and only the last image will be retained.) +- Calling the `save_to_markdown()` method will save the converted Markdown file to the specified `save_path`, with the saved file path being `save_path/{your_img_basename}.md`. If the input is a PDF file, it is recommended to directly specify a directory; otherwise, multiple Markdown files will be overwritten. +- Calling the `concatenate_markdown_pages()` method combines the multi-page Markdown content `markdown_list` output by the PP-DocTranslation pipeline into a single complete document and returns the combined Markdown content.
      +
      (4) Calltranslate()method to perform document translation. This method returns the original markdown text and the translated text as a markdown object. You can save the required parts locally by executing thesave_to_markdown()method. Below are the parameter descriptions for thetranslate()method: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ParameterDescriptionParameter TypeDefault Value
      ori_md_info_listA data list in the original Markdown format, containing the content to be translated. It must be a list composed of dictionaries, with each dictionary representing a document block.List[Dict]No default value (required)
      target_languageTarget language (ISO 639-1 language code, such as "en"/"ja"/"fr").str"zh"
      chunk_sizeThe character count threshold for chunking the text to be translated.int5000
      task_descriptionCustom task description prompt.str|NoneNone
      output_formatSpecify the output format requirements, such as "maintain the original Markdown structure".str|NoneNone
      rules_strCustom translation rule description.str|NoneNone
      few_shot_demo_text_contentExample text content for few-shot learning.str|NoneNone
      few_shot_demo_key_value_listStructured few-shot example data. Example data in key-value pair format, which can include a glossary of technical terms.str|NoneNone
      chat_bot_configLarge language model configuration. Set to None to use instantiation parameters; otherwise, this parameter takes precedence.dict|NoneNone
      llm_request_intervalThe time interval, in seconds, for sending requests to the large language model. This parameter can be used to prevent overly frequent calls to the large language model.float0
      +
      + +## 3. Development Integration/Deployment + +If the pipeline can meet your requirements for inference speed and accuracy, you can proceed directly with development integration/deployment. + +If you need to directly apply the pipeline in your Python project, you can refer to the sample code in [2.2 Python Script Approach](#22-python脚本方式集成). + +In addition, PaddleOCR also offers two other deployment methods, detailed as follows: + +🚀 High-Performance Inference: In real-world production environments, many applications have stringent performance criteria (especially response speed) for deployment strategies to ensure efficient system operation and a smooth user experience. To this end, PaddleOCR provides high-performance inference capabilities, aiming to deeply optimize model inference and pre/post-processing, achieving significant acceleration in the end-to-end process. For detailed information on the high-performance inference process, please refer to [High-Performance Inference](../deployment/high_performance_inference.md). + +☁️ Serving: Serving is a common deployment form in real-world production environments. By encapsulating inference functions as services, clients can access these services through network requests to obtain inference results. For detailed information on the pipeline serving process, please refer to [Serving](../deployment/serving.md). + +Below are the API references for basic serving and examples of multilingual service invocation: + +
      API reference +

      Main operations provided by the service:

      +
        +
      • The HTTP request method is POST.
      • +
      • Both the request body and response body are JSON data (JSON objects).
      • +
      • When the request is processed successfully, the response status code is200, and the properties of the response body are as follows:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaning
      logIdstringThe UUID of the request.
      errorCodeintegerError code. Fixed as0.
      errorMsgstringError description. Fixed as"Success".
      resultobjectOperation result.
      +
        +
      • When the request is not processed successfully, the properties of the response body are as follows:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaning
      logIdstringThe UUID of the request.
      errorCodeintegerError code. Same as the response status code.
      errorMsgstringError description.
      +

      The main operations provided by the service are as follows:

      +
        +
      • analyzeImages
      • +
      +

      Analyze images using computer vision models to obtain OCR, table recognition results, etc.

      +

      POST /doctrans-visual

      +
        +
      • The properties of the request body are as follows:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaningRequired
      filestringThe URL of an image file or PDF file accessible to the server, or the Base64-encoded result of the content of the aforementioned file types. By default, for PDF files with more than 10 pages, only the first 10 pages will be processed.
      To remove the page limit, add the following configuration to the pipeline configuration file:
      Serving:
      +  extra:
      +    max_num_input_imgs: null
      +
      Yes
      fileTypeinteger|nullFile type.0indicates a PDF file,1indicates an image file. If this property is not present in the request body, the file type will be inferred from the URL.No
      useDocOrientationClassifyboolean|nullRefer to the description of the use_doc_orientation_classifyparameter in the predictmethod of the pipeline object.No
      useDocUnwarpingboolean|nullRefer to the description of the use_doc_unwarpingparameter in the predictmethod of the pipeline object.No
      useTextlineOrientationboolean|nullRefer to the description of the use_textline_orientationparameter in the predictParameter description.No
      useSealRecognitionboolean|nullRefer to the parameter description of use_seal_recognition in the predict method of the pipeline object.No
      useTableRecognitionboolean|nullRefer to the parameter description of use_table_recognition in the predict method of the pipeline object.No
      useFormulaRecognitionboolean|nullRefer to the parameter description of use_formula_recognition in the predict method of the pipeline object.No
      useChartRecognitionboolean|nullRefer to the parameter description of use_chart_recognition in the predict method of the pipeline object.No
      useRegionDetectionboolean|nullRefer to the parameter description in the predict method of the pipeline object.use_region_detectionParameter description.No
      layoutThresholdnumber|object|nullRefer to the parameter description of layout_threshold in the predict method of the pipeline object.No
      layoutNmsboolean|nullRefer to the parameter description of layout_nms in the predict method of the pipeline object.No
      layoutUnclipRationumber|array|object|nullRefer to the parameter description of layout_unclip_ratio in the predict method of the pipeline object.No
      layoutMergeBboxesModestring|object|nullRefer to the parameter description of layout_merge_bboxes_mode in the predict method of the pipeline object.No
      textDetLimitSideLeninteger|nullRefer to the description of the predict method's text_det_limit_side_len parameter in the pipeline object.No
      textDetLimitTypestring|nullRefer to the description of the predict method's text_det_limit_type parameter in the pipeline object.No
      textDetThreshnumber|nullRefer to the description of the predict method's text_det_thresh parameter in the pipeline object.No
      textDetBoxThreshnumber|nullRefer to the description of the predict method's text_det_box_thresh parameter in the pipeline object.No
      textDetUnclipRationumber|nullRefer to the description of the predict method's text_det_unclip_ratio parameter in the pipeline object.No
      textRecScoreThreshnumber|nullRefer to the description of the predict method's text_rec_score_thresh parameter in the pipeline object.No
      sealDetLimitSideLeninteger|nullRefer to the description of the predict method's seal_det_limit_side_len parameter in the pipeline object.No
      sealDetLimitTypestring|nullRefer to the description of the predict method's seal_det_limit_type parameter in the pipeline object.No
      sealDetThreshnumber|nullRefer to the description of the predict method's seal_det_thresh parameter in the pipeline object.No
      sealDetBoxThreshnumber|nullRefer to the description of the predict method's seal_det_box_thresh parameter in the pipeline object.No
      sealDetUnclipRationumber|nullRefer to the description of the predict method's seal_det_unclip_ratio parameter in the pipeline object.No
      sealRecScoreThreshnumber|nullRefer to the description of the predict method's seal_rec_score_thresh parameter in the pipeline object.No
      useWiredTableCellsTransToHtmlbooleanRefer to the description of the predict method's use_wired_table_cells_trans_to_html parameter in the pipeline object.No
      useWirelessTableCellsTransToHtmlbooleanRefer to the description of the predict method's use_wireless_table_cells_trans_to_html parameter in the pipeline object.No
      useTableOrientationClassifybooleanRefer to the description of the predict method's use_table_orientation_classify parameter in the pipeline object.No
      useOcrResultsWithTableCellsbooleanSee the description of the use_ocr_results_with_table_cellsparameter for the predictmethod in the pipeline object.No
      useE2eWiredTableRecModelbooleanSee the description of the use_e2e_wired_table_rec_modelparameter for the predictmethod in the pipeline object.No
      useE2eWirelessTableRecModelbooleanSee the description of the use_e2e_wireless_table_rec_modelparameter for the predictmethod in the pipeline object.No
      visualizeboolean|nullWhether to return visualization result charts and intermediate images during processing, etc.
        +
      • Pass in true: Return images.
      • +
      • Pass in false: Do not return images.
      • +
      • If this parameter is not provided in the request body or nullis passed in: Follow the setting in the pipeline configuration file Serving.visualize.
      • +
      +
      For example, add the following field in the pipeline configuration file:
      +
      Serving:
      +  visualize: False
      Images will not be returned by default, and can be controlled by the visualizeParameters can override the default behavior. If neither the request body nor the configuration file is set (or null is passed in the request body and the configuration file is not set), the image is returned by default.
      No
      +
        +
      • When the request is processed successfully, the result in the response body has the following properties:
      • +
      + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaning
      layoutParsingResultsarrayLayout parsing results. The array length is 1 (for image input) or the actual number of processed document pages (for PDF input). For PDF input, each element in the array represents the result of each actual processed page in the PDF file in sequence.
      dataInfoobjectInput data information.
      +

      Each element in layoutParsingResults is an object

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      with the following properties:NameType
      MeaningprunedResultobjectA simplified version of the res field in the JSON representation of the layout_parsing_result generated by the visual_predict method of the pipeline object, where the input_path
      and page_index fields are removed.
      markdownobjectMarkdown results.outputImagesobjectimgproperty description. The image is in JPEG format and encoded with Base64.
      inputImagestring|nullInput image. The image is in JPEG format and encoded with Base64.
      +

      markdownis anobjectwith the following properties:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaning
      textstringMarkdown text.
      imagesobjectKey-value pairs of relative paths of Markdown images and Base64-encoded images.
      isStartbooleanWhether the first element on the current page is the start of a paragraph.
      isEndbooleanWhether the last element on the current page is the end of a paragraph.
      +
        +
      • translate
      • +
      +

      Translate documents using a large model.

      +

      POST /doctrans-translate

      +
        +
      • The properties of the request body are as follows:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      NameTypeMeaningRequired
      markdownListarrayList of Markdown documents to be translated. Can be obtained from the results of the analyzeImagesoperation.The imagesproperty will not be used.
      YestargetLanguagestringPlease refer to the translatetarget_languageParameter description.No
      chunkSizeintegerSee the parameter description of chunk_sizefor the translatemethod in the pipeline object.No
      taskDescriptionstring|nullSee the parameter description of task_descriptionfor the translatemethod in the pipeline object.No
      outputFormatstring|nullSee the parameter description of output_formatfor the translatemethod in the pipeline object.No
      rulesStrstring|nullSee the parameter description of rules_strfor the translatemethod in the pipeline object.No
      fewShotDemoTextContentstring|nullSee the parameter description of few_shot_demo_text_contentfor the translatemethod in the pipeline object.No
      fewShotDemoKeyValueListstring|nullRefer to the description of the few_shot_demo_key_value_list parameter in the translate method of the pipeline object.No
      chatBotConfigobject|nullRefer to the description of the chat_bot_config parameter in the translate method of the pipeline object.No
      llmRequestIntervalnumber|nullRefer to the description of the llm_request_interval parameter in the translate method of the pipeline object.No
      +
        +
      • When the request is processed successfully, the result in the response body has the following properties:
      • +
      + + + + + + + + + + + + + + + +
      NameTypeMeaning
      translationResultsarrayTranslation results.
      +

      Each element in translationResults is an object

      + + + + + + + + + + + + + + + + + + + + +
      with the following properties:NameType
      Meaninglanguagestring
      Target language.markdownMarkdown results. The object definition is consistent with the analyzeImages operation's returned markdown.
      +
    • Note:
    • Including sensitive parameters such as the API key for large model calls in the request body may pose security risks. If not necessary, set these parameters in the configuration file and do not pass them during the request.

      +
      +
      Example of multilingual service invocation +
      +Python +
      import base64
      +import pathlib
      +import pprint
      +import sys
      +
      +import requests
      +
      +
      +API_BASE_URL = "http://127.0.0.1:8080"
      +
      +file_path = "./demo.jpg"
      +target_language = "en"
      +
      +with open(file_path, "rb") as file:
      +    file_bytes = file.read()
      +    file_data = base64.b64encode(file_bytes).decode("ascii")
      +
      +payload = {
      +    "file": file_data,
      +    "fileType": 1,
      +}
      +resp_visual = requests.post(url=f"{API_BASE_URL}/doctrans-visual", json=payload)
      +if resp_visual.status_code != 200:
      +    print(
      +        f"Request to doctrans-visual failed with status code {resp_visual.status_code}."
      +    )
      +    pprint.pp(resp_visual.json())
      +    sys.exit(1)
      +result_visual = resp_visual.json()["result"]
      +
      +markdown_list = []
      +for i, res in enumerate(result_visual["layoutParsingResults"]):
      +    md_dir = pathlib.Path(f"markdown_{i}")
      +    md_dir.mkdir(exist_ok=True)
      +    (md_dir / "doc.md")
      +write_text(res["markdown"]["text"])
      +    for img_path, img in res["markdown"]["images"].items():
      +        img_path = md_dir / img_path
      +        img_path.parent.mkdir(parents=True, exist_ok=True)
      +        img_path.write_bytes(base64.b64decode(img))
      +    print(f"The Markdown document to be translated is saved at {md_dir / 'doc.md'}")
      +    del res["markdown"]["images"]
      +    markdown_list.append(res["markdown"])
      +    for img_name, img in res["outputImages"].items():
      +        img_path = f"{img_name}_{i}.jpg"
      +        with open(img_path, "wb") as f:
      +            f.write(base64.b64decode(img))
      +        print(f"Output image saved at {img_path}")
      +
      +payload = {
      +    "markdownList": markdown_list,
      +"targetLanguage": target_language,
      +}
      +resp_translate = requests.post(url=f"{API_BASE_URL}/doctrans-translate", json=payload)
      +if resp_translate.status_code != 200:
      +    print(
      +        f"Request to doctrans-translate failed with status code {resp_translate.status_code}."
      +    )
      +    pprint.pprint(resp_translate.json())  # Corrected 'pp' to 'pprint' for proper function call
      +    sys.exit(1)
      +result_translate = resp_translate.json()["result"]
      +
      +for i, res in enumerate(result_translate["translationResults"]):
      +    md_dir = pathlib.Path(f"markdown_{i}")
      +    (md_dir / "doc_translated.md").write_text(res["markdown"]["text"])
      +    print(f"Translated markdown document saved at {md_dir / 'doc_translated.md'}")
      +
      +
      + +## 4. Secondary Development +If the default model weights provided by the PP-DocTranslation pipeline do not meet your accuracy or speed requirements in your scenario, you can try to useyour own data from specific domains or application scenariosto furtherfine-tunethe existing model to improve the recognition effect in your scenario. + +### 4.1 Model Fine-tuning +Since the PP-DocTranslation pipeline contains several modules, if the performance of the model pipeline does not meet expectations, the issue may originate from any one of these modules. You can analyze cases with poor extraction results, use visualized images to determine which module has the problem, and refer to the corresponding fine-tuning tutorial links in the following table to fine-tune the model. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      ScenarioFine-tuning moduleFine-tuning reference link
      Inaccurate detection of layout areas, such as failure to detect seals and tablesLayout area detection moduleLink
      Inaccurate recognition of table structuresTable structure recognition moduleLink
      Inaccurate recognition of formulasFormula recognition moduleLink
      Omission in detecting seal textsSeal text detection moduleLink
      Omission in detecting textsText detection moduleLink
      Inaccurate text contentText recognition moduleLink
      Inaccurate correction of vertical or rotated text linesText line orientation classification moduleLink
      Inaccurate correction of whole image rotationDocument image orientation classification moduleLink
      Inaccurate correction of image distortionText image unwarping moduleFine-tuning is temporarily not supported
      + +### 4.2 Model Application +After completing fine-tuning training with your private dataset, you can obtain a local model weight file. Then, you can use the fine-tuned model weights by customizing the pipeline configuration file. + +1. Obtain the pipeline configuration file + +You can call the `export_paddlex_config_to_yaml` method of the PP-DocTranslation pipeline object in PaddleOCR to export the current pipeline configuration to a YAML file: + +```Python +from paddleocr import PPDocTranslation + +pipeline = PPDocTranslation() +pipeline.export_paddlex_config_to_yaml("PP-DocTranslation.yaml") +``` + +2. Modify the configuration file + +After obtaining the default pipeline configuration file, replace the local path of the fine-tuned model weights with the corresponding location in the pipeline configuration file. For example, + +```yaml +...... +SubModules: + TextDetection: + module_name: text_detection + model_name: PP-OCRv5_server_det + model_dir: null # Replace with the path to the weights of the fine-tuned text detection model + limit_side_len: 960 + limit_type: max + thresh: 0.3 + box_thresh: 0.6 + unclip_ratio: 1.5 + + TextRecognition: + module_name: text_recognition + model_name: PP-OCRv5_server_rec + model_dir: null # Replace with the path to the weights of the fine-tuned text recognition model + batch_size: 1 + score_thresh: 0 +...... +``` + +The pipeline configuration file not only includes parameters supported by PaddleOCR CLI and Python API but also allows for more advanced configurations. Detailed information can be found in the corresponding pipeline usage tutorial in the [Overview of PaddleX Model Pipeline Usage](https://paddlepaddle.github.io/PaddleX/3.0/pipeline_usage/pipeline_develop_guide.html). Refer to the detailed instructions therein and adjust the configurations according to your needs. + +3. Load the pipeline configuration file in CLI + +After modifying the configuration file, specify the path to the modified pipeline configuration file using the `--paddlex_config` parameter in the command line. PaddleOCR will then read its contents as the pipeline configuration. Here is an example: + +```bash +paddleocr pp_doctranslation --paddlex_config PP-DocTranslation.yaml ... +``` + +4. Load the pipeline configuration file in the Python API + +When initializing the pipeline object, you can pass the path of the PaddleX pipeline configuration file or a configuration dict through the `paddlex_config` parameter, and PaddleOCR will read its content as the pipeline configuration. The example is as follows: + +```python +from paddleocr import PPDocTranslation + +pipeline = PPDocTranslation(paddlex_config="PP-DocTranslation.yaml") +``` diff --git a/docs/version3.x/pipeline_usage/PP-DocTranslation.md b/docs/version3.x/pipeline_usage/PP-DocTranslation.md new file mode 100644 index 0000000000..4fb670684c --- /dev/null +++ b/docs/version3.x/pipeline_usage/PP-DocTranslation.md @@ -0,0 +1,2993 @@ +--- +comments: true +--- + +# PP-DocTranslation 产线使用教程 + +## 1. PP-DocTranslation 产线介绍 + +PP-DocTranslation 是飞桨提供的文档智能翻译解决方案,融合了先进的通用版面解析技术与大语言模型(LLM)能力,为您提供高效的文档智能翻译服务。该解决方案能够精准识别并提取文档中的各类元素,包括文本块、标题、段落、图片、表格及其他复杂版面结构,并在此基础之上实现高质量的多语种互译。PP-DocTranslation 支持多种主流语言间的相互翻译,尤其擅长处理排版复杂、上下文依赖性强的文档场景,力求输出精准自然、流畅专业的翻译结果。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。 + +PP-DocTranslation 产线中使用了 PP-StructureV3 子产线,因此具有 PP-StructureV3 产线的所有功能,更多关于 PP-StructureV3 产线的功能介绍和使用细节,可以点击 [PP-StructureV3 产线文档](./PP-StructureV3.md) 页面查看。 + +在本产线中,您可以根据下方的基准测试数据选择使用的模型。 + +
      👉模型列表详情 +

      文档图像方向分类模块:

      + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接Top-1 Acc(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-LCNet_x1_0_doc_ori推理模型/训练模型99.062.62 / 0.593.24 / 1.197基于PP-LCNet_x1_0的文档图像分类模型,含有四个类别,即0度,90度,180度,270度
      +

      文本图像矫正模块:

      + + + + + + + + + + + + + + + + + + +
      模型模型下载链接CER 模型存储大小(M)介绍
      UVDoc推理模型/训练模型0.17930.3 M高精度文本图像矫正模型
      +

      版面区域检测模块模型:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接mAP(0.5)(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-DocLayout_plus-L推理模型/训练模型83.253.03 / 17.23634.62 / 378.32126.01 M基于RT-DETR-L在包含中英文论文、多栏杂志、报纸、PPT、合同、书本、试卷、研报、古籍、日文文档、竖版文字文档等场景的自建数据集训练的更高精度版面区域定位模型
      PP-DocLayout-L推理模型/训练模型90.433.59 / 33.59503.01 / 251.08123.76 M基于RT-DETR-L在包含中英文论文、杂志、合同、书本、试卷和研报等场景的自建数据集训练的高精度版面区域定位模型
      PP-DocLayout-M推理模型/训练模型75.213.03 / 4.7243.39 / 24.4422.578基于PicoDet-L在包含中英文论文、杂志、合同、书本、试卷和研报等场景的自建数据集训练的精度效率平衡的版面区域定位模型
      PP-DocLayout-S推理模型/训练模型70.911.54 / 3.8618.53 / 6.294.834基于PicoDet-S在中英文论文、杂志、合同、书本、试卷和研报等场景上自建数据集训练的高效率版面区域定位模型
      +

      表格结构识别模块:

      + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接精度(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小 (M)介绍
      SLANeXt_wired推理模型/训练模型69.6585.92 / 85.92- / 501.66351MSLANeXt 系列是百度飞桨视觉团队自研的新一代表格结构识别模型。相较于 SLANet 和 SLANet_plus,SLANeXt 专注于对表格结构进行识别,并且对有线表格(wired)和无线表格(wireless)的识别分别训练了专用的权重,对各类型表格的识别能力都得到了明显提高,特别是对有线表格的识别能力得到了大幅提升。
      SLANeXt_wireless推理模型/训练模型
      + +

      表格分类模块模型:

      + + + + + + + + + + + + + + + + +
      模型模型下载链接Top1 Acc(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小 (M)
      PP-LCNet_x1_0_table_cls推理模型/训练模型94.22.62 / 0.603.17 / 1.146.6M
      + +

      表格单元格检测模块模型:

      + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接mAP(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小 (M)介绍
      RT-DETR-L_wired_table_cell_det推理模型/训练模型82.733.47 / 27.02402.55 / 256.56124MRT-DETR 是第一个实时的端到端目标检测模型。百度飞桨视觉团队基于 RT-DETR-L 作为基础模型,在自建表格单元格检测数据集上完成预训练,实现了对有线表格、无线表格均有较好性能的表格单元格检测。 +
      RT-DETR-L_wireless_table_cell_det推理模型/训练模型
      + +

      文本检测模块:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接检测Hmean(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-OCRv5_server_det推理模型/训练模型83.889.55 / 70.19383.15 / 383.1584.3PP-OCRv5 的服务端文本检测模型,精度更高,适合在性能较好的服务器上部署
      PP-OCRv5_mobile_det推理模型/训练模型79.010.67 / 6.3657.77 / 28.154.7PP-OCRv5 的移动端文本检测模型,效率更高,适合在端侧设备部署
      PP-OCRv4_server_det推理模型/训练模型69.2127.82 / 98.87585.95 / 489.77109PP-OCRv4 的服务端文本检测模型,精度更高,适合在性能较好的服务器上部署
      PP-OCRv4_mobile_det推理模型/训练模型63.89.87 / 4.1756.60 / 20.794.7PP-OCRv4 的移动端文本检测模型,效率更高,适合在端侧设备部署
      PP-OCRv3_mobile_det推理模型/训练模型精度接近 PP-OCRv4_mobile_det9.90 / 3.6041.93 / 20.762.1PP-OCRv3 的移动端文本检测模型,效率更高,适合在端侧设备部署
      PP-OCRv3_server_det推理模型/训练模型精度接近 PP-OCRv4_server_det119.50 / 75.00379.35 / 318.35102.1PP-OCRv3 的服务端文本检测模型,精度更高,适合在性能较好的服务器上部署
      + +

      文本识别模块模型:

      + +* 中文识别模型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接识别 Avg Accuracy(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-OCRv5_server_rec推理模型/训练模型86.388.46 / 2.3631.21 / 31.2181 MPP-OCRv5_rec 是新一代文本识别模型。该模型致力于以单一模型高效、精准地支持简体中文、繁体中文、英文、日文四种主要语言,以及手写、竖版、拼音、生僻字等复杂文本场景的识别。在保持识别效果的同时,兼顾推理速度和模型鲁棒性,为各种场景下的文档理解提供高效、精准的技术支撑。
      PP-OCRv5_mobile_rec推理模型/训练模型81.295.43 / 1.4621.20 / 5.3216 M
      PP-OCRv4_server_rec_doc推理模型/训练模型86.588.69 / 2.7837.93 / 37.9374.7 MPP-OCRv4_server_rec_doc是在PP-OCRv4_server_rec的基础上,在更多中文文档数据和PP-OCR训练数据的混合数据训练而成,增加了部分繁体字、日文、特殊字符的识别能力,可支持识别的字符为1.5万+,除文档相关的文字识别能力提升外,也同时提升了通用文字的识别能力
      PP-OCRv4_mobile_rec推理模型/训练模型78.745.26 / 1.1217.48 / 3.6110.6 MPP-OCRv4的轻量级识别模型,推理效率高,可以部署在包含端侧设备的多种硬件设备中
      PP-OCRv4_server_rec 推理模型/训练模型80.61 8.75 / 2.4936.93 / 36.9371.2 MPP-OCRv4的服务器端模型,推理精度高,可以部署在多种不同的服务器上
      PP-OCRv3_mobile_rec推理模型/训练模型72.963.89 / 1.168.72 / 3.569.2 MPP-OCRv3的轻量级识别模型,推理效率高,可以部署在包含端侧设备的多种硬件设备中
      + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接识别 Avg Accuracy(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      ch_SVTRv2_rec推理模型/训练模型68.8110.38 / 8.3166.52 / 30.8373.9 M +SVTRv2 是一种由复旦大学视觉与学习实验室(FVL)的OpenOCR团队研发的服务端文本识别模型,其在PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务中荣获一等奖,A榜端到端识别精度相比PP-OCRv4提升6%。 +
      + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接识别 Avg Accuracy(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      ch_RepSVTR_rec推理模型/训练模型65.076.29 / 1.5720.64 / 5.4022.1 M RepSVTR 文本识别模型是一种基于SVTRv2 的移动端文本识别模型,其在PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务中荣获一等奖,B榜端到端识别精度相比PP-OCRv4提升2.5%,推理速度持平。
      + +* 英文识别模型 + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接识别 Avg Accuracy(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      en_PP-OCRv4_mobile_rec推理模型/训练模型 70.394.81 / 1.2317.20 / 4.186.8 M基于PP-OCRv4识别模型训练得到的超轻量英文识别模型,支持英文、数字识别
      en_PP-OCRv3_mobile_rec推理模型/训练模型70.693.56 / 0.788.44 / 5.787.8 M 基于PP-OCRv3识别模型训练得到的超轻量英文识别模型,支持英文、数字识别
      + +* 多语言识别模型 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接识别 Avg Accuracy(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      korean_PP-OCRv3_mobile_rec推理模型/训练模型60.213.73 / 0.988.76 / 2.918.6 M基于PP-OCRv3识别模型训练得到的超轻量韩文识别模型,支持韩文、数字识别
      japan_PP-OCRv3_mobile_rec推理模型/训练模型45.693.86 / 1.018.62 / 2.928.8 M 基于PP-OCRv3识别模型训练得到的超轻量日文识别模型,支持日文、数字识别
      chinese_cht_PP-OCRv3_mobile_rec推理模型/训练模型82.063.90 / 1.169.24 / 3.189.7 M 基于PP-OCRv3识别模型训练得到的超轻量繁体中文识别模型,支持繁体中文、数字识别
      te_PP-OCRv3_mobile_rec推理模型/训练模型95.883.59 / 0.818.28 / 6.217.8 M 基于PP-OCRv3识别模型训练得到的超轻量泰卢固文识别模型,支持泰卢固文、数字识别
      ka_PP-OCRv3_mobile_rec推理模型/训练模型96.963.49 / 0.898.63 / 2.778.0 M 基于PP-OCRv3识别模型训练得到的超轻量卡纳达文识别模型,支持卡纳达文、数字识别
      ta_PP-OCRv3_mobile_rec推理模型/训练模型76.833.49 / 0.868.35 / 3.418.0 M 基于PP-OCRv3识别模型训练得到的超轻量泰米尔文识别模型,支持泰米尔文、数字识别
      latin_PP-OCRv3_mobile_rec推理模型/训练模型76.933.53 / 0.788.50 / 6.837.8 M基于PP-OCRv3识别模型训练得到的超轻量拉丁文识别模型,支持拉丁文、数字识别
      arabic_PP-OCRv3_mobile_rec推理模型/训练模型73.553.60 / 0.838.44 / 4.697.8 M基于PP-OCRv3识别模型训练得到的超轻量阿拉伯字母识别模型,支持阿拉伯字母、数字识别
      cyrillic_PP-OCRv3_mobile_rec推理模型/训练模型94.283.56 / 0.798.22 / 2.767.9 M 基于PP-OCRv3识别模型训练得到的超轻量斯拉夫字母识别模型,支持斯拉夫字母、数字识别
      devanagari_PP-OCRv3_mobile_rec推理模型/训练模型96.443.60 / 0.786.95 / 2.877.9 M基于PP-OCRv3识别模型训练得到的超轻量梵文字母识别模型,支持梵文字母、数字识别
      + +

      文本行方向分类模块(可选):

      + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接Top-1 Acc(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-LCNet_x0_25_textline_ori推理模型/训练模型95.542.16 / 0.412.37 / 0.730.32基于PP-LCNet_x0_25的文本行分类模型,含有两个类别,即0度,180度
      + +

      公式识别模块:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接Avg-BLEU(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小 (M)介绍
      UniMERNet推理模型/训练模型86.132266.96/--/-1.4 GUniMERNet是由上海AI Lab研发的一款公式识别模型。该模型采用Donut Swin作为编码器,MBartDecoder作为解码器,并通过在包含简单公式、复杂公式、扫描捕捉公式和手写公式在内的一百万数据集上进行训练,大幅提升了模型对真实场景公式的识别准确率PP-FormulaNet-S推理模型/训练模型87.121311.84 / 1311.84- / 8288.07167.9 MPP-FormulaNet 是由百度飞桨视觉团队开发的一款先进的公式识别模型,支持5万个常见LateX源码词汇的识别。PP-FormulaNet-S 版本采用了 PP-HGNetV2-B4 作为其骨干网络,通过并行掩码和模型蒸馏等技术,大幅提升了模型的推理速度,同时保持了较高的识别精度,适用于简单印刷公式、跨行简单印刷公式等场景。而 PP-FormulaNet-L 版本则基于 Vary_VIT_B 作为骨干网络,并在大规模公式数据集上进行了深入训练,在复杂公式的识别方面,相较于PP-FormulaNet-S表现出显著的提升,适用于简单印刷公式、复杂印刷公式、手写公式等场景。
      PP-FormulaNet-L推理模型/训练模型92.131976.52/--/-535.2 MLaTeX_OCR_rec推理模型/训练模型71.631088.89 / 1088.89- / -89.7 MLaTeX-OCR是一种基于自回归大模型的公式识别算法,通过采用 Hybrid ViT 作为骨干网络,transformer作为解码器,显著提升了公式识别的准确性。
      + +

      印章文本检测模块:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      模型模型下载链接检测Hmean(%)GPU推理耗时(ms)
      [常规模式 / 高性能模式]
      CPU推理耗时(ms)
      [常规模式 / 高性能模式]
      模型存储大小(M)介绍
      PP-OCRv4_server_seal_det推理模型/训练模型98.21124.64 / 91.57545.68 / 439.86109PP-OCRv4的服务端印章文本检测模型,精度更高,适合在较好的服务器上部署
      PP-OCRv4_mobile_seal_det推理模型/训练模型96.479.70 / 3.5650.38 / 19.644.6PP-OCRv4的移动端印章文本检测模型,效率更高,适合在端侧部署
      + +测试环境说明: + +
        +
      • 性能测试环境 +
          +
        • 测试数据集: + +
            +
          • 文档图像方向分类模型:PaddleX 自建的数据集,覆盖证件和文档等多个场景,包含 1000 张图片。
          • +
          • 文本图像矫正模型:DocUNet
          • +
          • 版面区域检测模型:PaddleOCR 自建的版面区域分析数据集,包含中英文论文、杂志和研报等常见的 1w 张文档类型图片。
          • +
          • PP-DocLayout_plus-L:PaddleOCR 自建的版面区域检测数据集,包含中英文论文、杂志、报纸、研报、PPT、试卷、课本等 1300 张文档类型图片。
          • +
          • 表格结构识别模型:PaddleX 内部自建英文表格识别数据集。
          • +
          • 文本检测模型:PaddleOCR 自建的中文数据集,覆盖街景、网图、文档、手写多个场景,其中检测包含 500 张图片。
          • +
          • 中文识别模型: PaddleOCR 自建的中文数据集,覆盖街景、网图、文档、手写多个场景,其中文本识别包含 1.1w 张图片。
          • +
          • ch_SVTRv2_rec:PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务A榜评估集。
          • +
          • ch_RepSVTR_rec:PaddleOCR算法模型挑战赛 - 赛题一:OCR端到端识别任务B榜评估集。
          • +
          • 英文识别模型:PaddleX 自建的英文数据集。
          • +
          • 多语言识别模型:PaddleX 自建的多语种数据集。
          • +
          • 文本行方向分类模型:PaddleX 自建的数据集,覆盖证件和文档等多个场景,包含 1000 张图片。
          • +
          • 印章文本检测模型:PaddleX 自建的数据集,包含500张圆形印章图像。
          • +
          +
        • +
        • 硬件配置: +
            +
          • GPU:NVIDIA Tesla T4
          • +
          • CPU:Intel Xeon Gold 6271C @ 2.60GHz
          • +
          • 其他环境:Ubuntu 20.04 / CUDA 11.8 / cuDNN 8.9 / TensorRT 8.6.1.6
          • +
          +
        • +
        +
      • +
      • 推理模式说明
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + +
      模式GPU配置CPU配置加速技术组合
      常规模式FP32精度 / 无TRT加速FP32精度 / 8线程PaddleInference
      高性能模式选择先验精度类型和加速策略的最优组合FP32精度 / 8线程选择先验最优后端(Paddle/OpenVINO/TRT等)
      + +
      + +## 2. 快速开始 + +在本地使用 PP-DocTranslation 产线前,请确保您已经按照[安装教程](../installation.md)完成了wheel包安装。 + +**请注意,如果在执行过程中遇到程序失去响应、程序异常退出、内存资源耗尽、推理速度极慢等问题,请尝试参考文档调整配置,例如关闭不需要使用的功能或使用更轻量的模型。** + +使用前需准备大语言模型的API密钥,支持[百度云千帆平台](https://console.bce.baidu.com/qianfan/ais/console/onlineService)或符合OpenAI接口标准的本地大模型服务。 + +### 2.1 命令行方式体验 + +可以下载 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png),使用一行命令即可快速体验产线效果: + +```bash +paddleocr pp_doctranslation -i vehicle_certificate-1.png --target_language en --qianfan_api_key your_api_key +``` + +
      命令行支持更多参数设置,点击展开以查看命令行参数的详细说明 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      参数参数说明参数类型默认值
      input待预测数据,必填。如图像文件或者PDF文件的本地路径:/root/data/img.jpg如URL链接,如图像文件或PDF文件的网络URL:示例如本地目录,该目录下需包含待预测图像,如本地路径:/root/data/(当前不支持目录中包含PDF文件的预测,PDF文件需要指定到具体文件路径)。 +str
      save_path指定推理结果文件保存的路径。如果不设置,推理结果将不会保存到本地。str
      target_language目标语言(ISO 639-1 语言代码)。strzh
      layout_detection_model_name版面区域检测的模型名称。如果不设置,将会使用产线默认模型。str
      layout_detection_model_dir版面区域检测模型的目录路径。如果不设置,将会下载官方模型。str
      layout_threshold版面模型得分阈值。0-1 之间的任意浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 0.5。 +float
      layout_nms版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      layout_unclip_ratio版面区域检测模型检测框的扩张系数。 +任意大于 0 浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 1.0。 +float
      layout_merge_bboxes_mode版面检测中模型输出的检测框的合并处理模式。 +
        +
      • large,设置为large时,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留外部最大的框,删除重叠的内部框;
      • +
      • small,设置为small,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留内部被包含的小框,删除重叠的外部框;
      • +
      • union,不进行框的过滤处理,内外框都保留;
      • +
      如果不设置,将使用产线初始化的该参数值,默认初始化为large。 +
      str
      chart_recognition_model_name图表解析的模型名称。如果不设置,将会使用产线默认模型。str
      chart_recognition_model_dir图表解析模型的目录路径。如果不设置,将会下载官方模型。str
      chart_recognition_batch_size图表解析模型的batch size。如果不设置,将默认设置batch size为1int
      region_detection_model_name文档图像版面子模块检测的模型名称。如果不设置,将会使用产线默认模型。str
      region_detection_model_dir文档图像版面子模块检测模型的目录路径。如果不设置,将会下载官方模型。str
      doc_orientation_classify_model_name文档方向分类模型的名称。如果不设置,将会使用产线默认模型。str
      doc_orientation_classify_model_dir文档方向分类模型的目录路径。如果不设置,将会下载官方模型。str
      doc_unwarping_model_name文本图像矫正模型的名称。如果不设置,将会使用产线默认模型。str
      doc_unwarping_model_dir文本图像矫正模型的目录路径。如果不设置,将会下载官方模型。str
      text_detection_model_name文本检测模型的名称。如果不设置,将会使用产线默认模型。str
      text_detection_model_dir文本检测模型的目录路径。如果不设置,将会下载官方模型。str
      text_det_limit_side_len文本检测的图像边长限制。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 960。 +int
      text_det_limit_type文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 max。 +str
      text_det_thresh检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.3。 +float
      text_det_box_thresh检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.6。 +float
      text_det_unclip_ratio文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 2.0。 +float
      textline_orientation_model_name文本行方向模型的名称。如果不设置,将会使用产线默认模型。str
      textline_orientation_model_dir文本行方向模型的目录路径。如果不设置,将会下载官方模型。str
      textline_orientation_batch_size文本行方向模型的batch size。如果不设置,将默认设置batch size为1int
      text_recognition_model_name文本识别模型的名称。如果不设置,将会使用产线默认模型。str
      text_recognition_model_dir文本识别模型的目录路径。如果不设置,将会下载官方模型。str
      text_recognition_batch_size文本识别模型的batch size。如果不设置,将默认设置batch size为1int
      text_rec_score_thresh文本识别阈值,得分大于该阈值的文本结果会被保留。 +大于 0 的任意浮点数。如果不设置,将默认使用产线初始化的该参数值 0.0。即不设阈值。 +float
      table_classification_model_name表格分类模型的名称。如果不设置,将会使用产线默认模型。str
      table_classification_model_dir表格分类模型的目录路径。如果不设置,将会下载官方模型。str
      wired_table_structure_recognition_model_name有线表格结构识别模型的名称。如果不设置,将会使用产线默认模型。str
      wired_table_structure_recognition_model_dir有线表格结构识别模型的目录路径。如果不设置,将会下载官方模型。str
      wireless_table_structure_recognition_model_name无线表格结构识别模型的名称。如果不设置,将会使用产线默认模型。str
      wireless_table_structure_recognition_model_dir无线表格结构识别模型的目录路径。如果不设置,将会下载官方模型。str
      wired_table_cells_detection_model_name有线表格单元格检测模型的名称。如果不设置,将会使用产线默认模型。str
      wired_table_cells_detection_model_dir有线表格单元格检测模型的目录路径。如果不设置,将会下载官方模型。str
      wireless_table_cells_detection_model_name无线表格单元格检测模型的名称。如果不设置,将会使用产线默认模型。str
      wireless_table_cells_detection_model_dir无线表格单元格检测模型的目录路径。如果不设置,将会下载官方模型。str
      table_orientation_classify_model_name表格方向分类模型的名称。如果不设置,将会使用产线默认模型。str
      table_orientation_classify_model_dir表格方向分类模型的目录路径。如果不设置,将会下载官方模型。str
      seal_text_detection_model_name印章文本检测模型的名称。如果不设置,将会使用产线默认模型。str
      seal_text_detection_model_dir印章文本检测模型的目录路径。如果不设置,将会下载官方模型。str
      seal_det_limit_side_len印章文本检测的图像边长限制。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 736。 +int
      seal_det_limit_type印章文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 min。 +str
      seal_det_thresh检测像素阈值。输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.2。 +float
      seal_det_box_thresh检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.6。 +float
      seal_det_unclip_ratio印章文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.5。 +float
      seal_text_recognition_model_name印章文本识别模型的名称。如果不设置,将会使用产线默认模型。str
      seal_text_recognition_model_dir印章文本识别模型的目录路径。如果不设置,将会下载官方模型。str
      seal_text_recognition_batch_size印章文本识别模型的batch size。如果不设置,将默认设置batch size为1int
      seal_rec_score_thresh文本识别阈值,得分大于该阈值的文本结果会被保留。 +大于 0 的任意浮点数 +。如果不设置,将默认使用产线初始化的该参数值 0.0。即不设阈值。 +float
      formula_recognition_model_name公式识别模型的名称。如果不设置,将会使用产线默认模型。str
      formula_recognition_model_dir公式识别模型的目录路径。如果不设置,将会下载官方模型。str
      formula_recognition_batch_size公式识别模型的batch size。如果不设置,将默认设置batch size为1int
      use_doc_orientation_classify是否使用文档方向分类模块。boolFalse
      use_doc_unwarping是否使用文本图像矫正模块。boolFalse
      use_textline_orientation是否加载并使用文本行方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      use_seal_recognition是否加载并使用印章文本识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      use_table_recognition是否加载并使用表格识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      use_formula_recognition是否加载并使用公式识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      use_chart_recognition是否使用图表解析模块。boolFalse
      use_region_detection是否加载并使用文档区域检测子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool
      device用于推理的设备。支持指定具体卡号: +
        +
      • CPU:如 cpu 表示使用 CPU 进行推理;
      • +
      • GPU:如 gpu:0 表示使用第 1 块 GPU 进行推理;
      • +
      • NPU:如 npu:0 表示使用第 1 块 NPU 进行推理;
      • +
      • XPU:如 xpu:0 表示使用第 1 块 XPU 进行推理;
      • +
      • MLU:如 mlu:0 表示使用第 1 块 MLU 进行推理;
      • +
      • DCU:如 dcu:0 表示使用第 1 块 DCU 进行推理;
      • +
      如果不设置,将默认使用产线初始化的该参数值,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备。 +
      str
      enable_hpi是否启用高性能推理。boolFalse
      use_tensorrt是否启用 Paddle Inference 的 TensorRT 子图引擎。如果模型不支持通过 TensorRT 加速,即使设置了此标志,也不会使用加速。
      +对于 CUDA 11.8 版本的飞桨,兼容的 TensorRT 版本为 8.x(x>=6),建议安装 TensorRT 8.6.1.6。
      +对于 CUDA 12.6 版本的飞桨,兼容的 TensorRT 版本为 10.x(x>=5),建议安装 TensorRT 10.5.0.18。 +
      boolFalse
      precision计算精度,如 fp32、fp16。strfp32
      enable_mkldnn是否启用 MKL-DNN 加速推理。如果 MKL-DNN 不可用或模型不支持通过 MKL-DNN 加速,即使设置了此标志,也不会使用加速。 +boolTrue
      mkldnn_cache_capacity +MKL-DNN 缓存容量。 +int10
      cpu_threads在 CPU 上进行推理时使用的线程数。int8
      paddlex_configPaddleX产线配置文件路径。str
      +
      +
      + +运行结果会被打印到终端上。 + +### 2.2 Python脚本方式集成 + +命令行方式是为了快速体验查看效果,一般来说,在项目中,往往需要通过代码集成,可以下载 [测试文件](https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/vehicle_certificate-1.png),使用如下示例代码进行推理: + +```python +from paddlex import create_pipeline +# 创建翻译产线 +pipeline = create_pipeline(pipeline="PP-DocTranslation") + +# 文档路径 +input_path = "document_sample.pdf" + +# 输出目录 +output_path = "./output" + +# 大模型配置 +chat_bot_config = { + "module_name": "chat_bot", + "model_name": "ernie-3.5-8k", + "base_url": "https://qianfan.baidubce.com/v2", + "api_type": "openai", + "api_key": "api_key", # your api_key +} + +if input_path.lower().endswith(".md"): + # 读取markdown文档,支持传入目录和以 .md 为后缀的 url 链接 + ori_md_info_list = pipeline.load_from_markdown(input_path) +else: + # 使用 PP-StructureV3 对 PDF/图片 文档进行版面解析,获取markdown信息 + visual_predict_res = pipeline.visual_predict( + input_path, + use_doc_orientation_classify=False, + use_doc_unwarping=False, + use_common_ocr=True, + use_seal_recognition=True, + use_table_recognition=True, + ) + + ori_md_info_list = [] + for res in visual_predict_res: + layout_parsing_result = res["layout_parsing_result"] + ori_md_info_list.append(layout_parsing_result.markdown) + layout_parsing_result.save_to_img(output_path) + layout_parsing_result.save_to_markdown(output_path) + + # 将多页文档的 markdown 信息拼接成一个 markdown 文件,可将合并后的 markdown 原文保存 + if input_path.lower().endswith(".pdf"): + ori_md_info = pipeline.concatenate_markdown_pages(ori_md_info_list) + ori_md_info.save_to_markdown(output_path) + +# 执行文档翻译(目标语言:英文) +tgt_md_info_list = pipeline.translate( + ori_md_info_list=ori_md_info_list, + target_language="en", + chunk_size=5000, + chat_bot_config=chat_bot_config, +) +# 保存翻译结果 +for tgt_md_info in tgt_md_info_list: + tgt_md_info.save_to_markdown(output_path) +``` + +执行上述代码后,您将得到翻译原文的文档解析结果、翻译原文的 Markdown 文件和翻译后文档的 Markdown 文件,保存在 `output` 目录中。 + +PP-DocTranslation 预测的流程、API 说明、产出说明如下: + +
      (1)调用 PPDocTranslation 实例化 PP-DocTranslation 产线对象。 + +相关参数说明如下: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      参数参数说明参数类型默认值
      layout_detection_model_name版面区域检测的模型名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      layout_detection_model_dir版面区域检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      layout_threshold版面模型得分阈值。 +
        +
      • float0-1 之间的任意浮点数;
      • +
      • dict{0:0.1} key为类别ID,value为该类别的阈值;
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 0.5
      • +
      +
      float|dict|NoneNone
      layout_nms版面检测是否使用后处理NMS。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      layout_unclip_ratio版面区域检测模型检测框的扩张系数。 +
        +
      • float:任意大于 0 浮点数;
      • +
      • Tuple[float,float]:在横纵两个方向各自的扩张系数;
      • +
      • dict,dict的key为int类型,代表cls_id, value为tuple类型,如{0: (1.1, 2.0)},表示将模型输出的第0类别检测框中心不变,宽度扩张1.1倍,高度扩张2.0倍;
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 1.0
      • +
      +
      float|Tuple[float,float]|dict|NoneNone
      layout_merge_bboxes_mode版面区域检测的重叠框过滤方式。 +
        +
      • strlargesmallunion,分别表示重叠框过滤时选择保留大框,小框还是同时保留;
      • +
      • dict: dict的key为int类型,代表cls_id,value为str类型,如{0: "large", 2: "small"},表示对第0类别检测框使用large模式,对第2类别检测框使用small模式;
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 large
      • +
      +
      str|dict|NoneNone
      chart_recognition_model_name图表解析的模型名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      chart_recognition_model_dir图表解析模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      chart_recognition_batch_size图表解析模型的batch size。如果设置为None,将默认设置batch size为1int|NoneNone
      region_detection_model_name文档图像版面子模块检测的模型名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      region_detection_model_dir文档图像版面子模块检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      doc_orientation_classify_model_name文档方向分类模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      doc_orientation_classify_model_dir文档方向分类模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      doc_unwarping_model_name文本图像矫正模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      doc_unwarping_model_dir文本图像矫正模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      text_detection_model_name文本检测模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      text_detection_model_dir文本检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      text_det_limit_side_len文本检测的图像边长限制。 +
        +
      • int:大于 0 的任意整数;
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 960
      • +
      +
      int|NoneNone
      text_det_limit_type文本检测的图像边长限制类型。 +
        +
      • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 max
      • +
      +
      str|NoneNone
      text_det_thresh检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.3
      +
      float|NoneNone
      text_det_box_thresh检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.6
      +
      float|NoneNone
      text_det_unclip_ratio文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 2.0
      +
      float|NoneNone
      textline_orientation_model_name文本行方向模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      textline_orientation_model_dir文本行方向模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      textline_orientation_batch_size文本行方向模型的batch size。如果设置为None,将默认设置batch size为1int|NoneNone
      text_recognition_model_name文本识别模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      text_recognition_model_dir文本识别模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      text_recognition_batch_size文本识别模型的batch size。如果设置为None,将默认设置batch size为1int|NoneNone
      text_rec_score_thresh文本识别阈值,得分大于该阈值的文本结果会被保留。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.0,即不设阈值。
      +
      float|NoneNone
      table_classification_model_name表格分类模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      table_classification_model_dir表格分类模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      wired_table_structure_recognition_model_name有线表格结构识别模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      wired_table_structure_recognition_model_dir有线表格结构识别模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      wireless_table_structure_recognition_model_name无线表格结构识别模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      wireless_table_structure_recognition_model_dir无线表格结构识别模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      wired_table_cells_detection_model_name有线表格单元格检测模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      wired_table_cells_detection_model_dir有线表格单元格检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      wireless_table_cells_detection_model_name无线表格单元格检测模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      wireless_table_cells_detection_model_dir无线表格单元格检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      table_orientation_classify_model_name表格方向分类模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      table_orientation_classify_model_dir表格方向分类模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      seal_text_detection_model_name印章文本检测模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      seal_text_detection_model_dir印章文本检测模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      seal_det_limit_side_len印章文本检测的图像边长限制。 +
        +
      • int:大于 0 的任意整数;
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 736
      • +
      +
      int|NoneNone
      seal_det_limit_type印章文本检测的图像边长限制类型。 +
        +
      • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 min
      • +
      +
      str|NoneNone
      seal_det_thresh检测像素阈值,输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。 +
        +
      • float:大于 0 的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.2
      +
      float|NoneNone
      seal_det_box_thresh检测框阈值,检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.6
      +
      float|NoneNone
      seal_det_unclip_ratio印章文本检测扩张系数,使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.5
      +
      float|NoneNone
      seal_text_recognition_model_name印章文本识别模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      seal_text_recognition_model_dir印章文本识别模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      seal_text_recognition_batch_size印章文本识别模型的batch size。如果设置为None,将默认设置batch size为1int|NoneNone
      seal_rec_score_thresh印章文本识别阈值,得分大于该阈值的文本结果会被保留。 +
        +
      • float:大于0的任意浮点数; +
      • None:如果设置为None,将默认使用产线初始化的该参数值 0.0,即不设阈值。
      +
      float|NoneNone
      formula_recognition_model_name公式识别模型的名称。如果设置为None,将会使用产线默认模型。str|NoneNone
      formula_recognition_model_dir公式识别模型的目录路径。如果设置为None,将会下载官方模型。str|NoneNone
      formula_recognition_batch_size公式识别模型的batch size。如果设置为None,将默认设置batch size为1int|NoneNone
      use_doc_orientation_classify是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_doc_unwarping是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_textline_orientation是否加载并使用文本行方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_seal_recognition是否加载并使用印章文本识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_table_recognition是否加载并使用表格识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_formula_recognition是否加载并使用公式识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_chart_recognition是否加载并使用图表解析模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      use_region_detection是否加载并使用文档区域检测子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|NoneNone
      chat_bot_config大语言模型配置信息。配置内容为如下dict: +
      {
      +"module_name": "chat_bot",
      +"model_name": "ernie-3.5-8k",
      +"base_url": "https://qianfan.baidubce.com/v2",
      +"api_type": "openai",
      +"api_key": "api_key"  # 请将此设置为实际的API密钥
      +}
      +
      dict|NoneNone
      device用于推理的设备。支持指定具体卡号: +
        +
      • CPU:如 cpu 表示使用 CPU 进行推理;
      • +
      • GPU:如 gpu:0 表示使用第 1 块 GPU 进行推理;
      • +
      • NPU:如 npu:0 表示使用第 1 块 NPU 进行推理;
      • +
      • XPU:如 xpu:0 表示使用第 1 块 XPU 进行推理;
      • +
      • MLU:如 mlu:0 表示使用第 1 块 MLU 进行推理;
      • +
      • DCU:如 dcu:0 表示使用第 1 块 DCU 进行推理;
      • +
      • None:如果设置为None,初始化时,会优先使用本地的 GPU 0号设备,如果没有,则使用 CPU 设备。
      • +
      +
      str|NoneNone
      enable_hpi是否启用高性能推理。boolFalse
      use_tensorrt是否启用 Paddle Inference 的 TensorRT 子图引擎。如果模型不支持通过 TensorRT 加速,即使设置了此标志,也不会使用加速。
      +对于 CUDA 11.8 版本的飞桨,兼容的 TensorRT 版本为 8.x(x>=6),建议安装 TensorRT 8.6.1.6。
      +对于 CUDA 12.6 版本的飞桨,兼容的 TensorRT 版本为 10.x(x>=5),建议安装 TensorRT 10.5.0.18。 +
      boolFalse
      precision计算精度,如 fp32、fp16。str"fp32"
      enable_mkldnn是否启用 MKL-DNN 加速推理。如果 MKL-DNN 不可用或模型不支持通过 MKL-DNN 加速,即使设置了此标志,也不会使用加速。 +boolTrue
      mkldnn_cache_capacity +MKL-DNN 缓存容量。 +int10
      cpu_threads在 CPU 上进行推理时使用的线程数。int8
      paddlex_configPaddleX产线配置文件路径。str|NoneNone
      + +
      + +
      (2)调用 PP-DocTranslation 产线对象的 visual_predict() 方法获取视觉预测结果,该方法会返回一个结果列表。另外,产线还提供了 visual_predict_iter() 方法。两者在参数接受和结果返回方面是完全一致的,区别在于 visual_predict_iter() 返回的是一个 generator,能够逐步处理和获取预测结果,适合处理大型数据集或希望节省内存的场景。可以根据实际需求选择使用这两种方法中的任意一种。以下是 visual_predict() 方法的参数及其说明: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      参数参数说明参数类型默认值
      input待预测数据,支持多种输入类型,必填。 +
        +
      • Python Var:如 numpy.ndarray 表示的图像数据;
      • +
      • str:如图像文件或者PDF文件的本地路径:/root/data/img.jpg如URL链接,如图像文件或PDF文件的网络URL:示例如本地目录,该目录下需包含待预测图像,如本地路径:/root/data/(当前不支持目录中包含PDF文件的预测,PDF文件需要指定到具体文件路径);
      • +
      • list:列表元素需为上述类型数据,如[numpy.ndarray, numpy.ndarray]["/root/data/img1.jpg", "/root/data/img2.jpg"]["/root/data1", "/root/data2"]
      • +
      +
      Python Var|str|list
      use_doc_orientation_classify是否在推理时使用文档方向分类模块。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneFalse
      use_doc_unwarping是否在推理时使用文本图像矫正模块。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneFalse
      use_textline_orientation是否在推理时使用文本行方向分类模块。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      use_seal_recognition是否在推理时使用印章文本识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      use_table_recognition是否在推理时使用表格识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      use_formula_recognition是否在推理时使用公式识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      use_chart_recognition是否使用图表解析模块。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneFalse
      use_region_detection是否使用文档区域检测子产线。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      layout_threshold参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|dict|NoneNone
      layout_nms参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。bool|NoneNone
      layout_unclip_ratio参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|Tuple[float,float]|dict|NoneNone
      layout_merge_bboxes_mode参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。str|dict|NoneNone
      text_det_limit_side_len参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。int|NoneNone
      text_det_limit_type参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。str|NoneNone
      text_det_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      text_det_box_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      text_det_unclip_ratio参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      text_rec_score_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      seal_det_limit_side_len参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。int|NoneNone
      seal_det_limit_type参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。str|NoneNone
      seal_det_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      seal_det_box_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      seal_det_unclip_ratio参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      seal_rec_score_thresh参数含义与实例化参数基本相同。设置为None表示使用实例化参数,否则该参数优先级更高。float|NoneNone
      use_wired_table_cells_trans_to_html是否启用有线表单元格检测结果直转HTML,启用则直接基于有线表单元格检测结果的几何关系构建HTML。boolFalse
      use_wireless_table_cells_trans_to_html是否启用无线表单元格检测结果直转HTML,启用则直接基于无线表单元格检测结果的几何关系构建HTML。boolFalse
      use_table_orientation_classify是否启用表格使用表格方向分类,启用时当图像中的表格存在90/180/270度旋转时,能够将方向校正并正确完成表格识别。boolTrue
      use_ocr_results_with_table_cells是否启用单元格切分OCR,启用时会基于单元格预测结果对OCR检测结果进行切分和重识别,避免出现文字缺失情况。boolTrue
      use_e2e_wired_table_rec_model是否启用有线表端到端表格识别模式,启用则不使用单元格检测模型,只使用表格结构识别模型。boolFalse
      use_e2e_wireless_table_rec_model是否启用无线表端到端表格识别模式,启用则不使用单元格检测模型,只使用表格结构识别模型。boolTrue
      +
      + +
      (3)对视觉预测结果进行处理:每个样本的预测结果均为对应的Result对象,且支持打印、保存为图片、保存为json文件的操作: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      方法方法说明参数参数类型参数说明默认值
      print()打印结果到终端format_jsonbool是否对输出内容进行使用 JSON 缩进格式化True
      indentint指定缩进级别,以美化输出的 JSON 数据,使其更具可读性,仅当 format_jsonTrue 时有效4
      ensure_asciibool控制是否将非 ASCII 字符转义为 Unicode。设置为 True 时,所有非 ASCII 字符将被转义;False 则保留原始字符,仅当format_jsonTrue时有效False
      save_to_json()将结果保存为json格式的文件save_pathstr保存的文件路径,当为目录时,保存文件命名与输入文件类型命名一致
      indentint指定缩进级别,以美化输出的 JSON 数据,使其更具可读性,仅当 format_jsonTrue 时有效4
      ensure_asciibool控制是否将非 ASCII 字符转义为 Unicode。设置为 True 时,所有非 ASCII 字符将被转义;False 则保留原始字符,仅当format_jsonTrue时有效False
      save_to_img()将中间各个模块的可视化图像保存在png格式的图像save_pathstr保存的文件路径,支持目录或文件路径
      save_to_markdown()将图像或者PDF文件中的每一页分别保存为markdown格式的文件save_pathstr保存的文件路径,支持目录或文件路径
      save_to_html()将文件中的表格保存为html格式的文件save_pathstr保存的文件路径,支持目录或文件路径
      save_to_xlsx()将文件中的表格保存为xlsx格式的文件save_pathstr保存的文件路径,支持目录或文件路径
      + +- 调用`print()` 方法会将结果打印到终端,打印到终端的内容解释如下: + - `input_path`: `(str)` 待预测图像或者PDF的输入路径 + + - `page_index`: `(Union[int, None])` 如果输入是PDF文件,则表示当前是PDF的第几页,否则为 `None` + + - `model_settings`: `(Dict[str, bool])` 配置产线所需的模型参数 + + - `use_doc_preprocessor`: `(bool)` 控制是否启用文档预处理子产线 + - `use_general_ocr`: `(bool)` 控制是否启用 OCR 子产线 + - `use_seal_recognition`: `(bool)` 控制是否启用印章识别子产线 + - `use_table_recognition`: `(bool)` 控制是否启用表格识别子产线 + - `use_formula_recognition`: `(bool)` 控制是否启用公式识别子产线 + + - `doc_preprocessor_res`: `(Dict[str, Union[List[float], str]])` 文档预处理结果字典,仅当`use_doc_preprocessor=True`时存在 + - `input_path`: `(str)` 文档预处理子产线接受的图像路径,当输入为`numpy.ndarray`时,保存为`None`,此处为`None` + - `page_index`: `None`,此处的输入为`numpy.ndarray`,所以值为`None` + - `model_settings`: `(Dict[str, bool])` 文档预处理子产线的模型配置参数 + - `use_doc_orientation_classify`: `(bool)` 控制是否启用文档图像方向分类子模块 + - `use_doc_unwarping`: `(bool)` 控制是否启用文本图像扭曲矫正子模块 + - `angle`: `(int)` 文档图像方向分类子模块的预测结果,启用时返回实际角度值 + + - `parsing_res_list`: `(List[Dict])` 解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。 + - `block_bbox`: `(np.ndarray)` 版面区域的边界框。 + - `block_label`: `(str)` 版面区域的标签,例如`text`, `table`等。 + - `block_content`: `(str)` 内容为版面区域内的内容。 + - `seg_start_flag`: `(bool)` 标识该版面区域是否是段落的开始。 + - `seg_end_flag`: `(bool)` 标识该版面区域是否是段落的结束。 + - `sub_label`: `(str)` 版面区域的子标签,例如`text`的子标签可能为`title_text`。 + - `sub_index`: `(int)` 版面区域的子索引,用于恢复Markdown。 + - `index`: `(int)` 版面区域的索引,用于显示版面排序结果。 + + + - `overall_ocr_res`: `(Dict[str, Union[List[str], List[float], numpy.ndarray]])` 全局 OCR 结果的字典 + - `input_path`: `(Union[str, None])` 图像OCR子产线接受的图像路径,当输入为`numpy.ndarray`时,保存为`None` + - `page_index`: `None`,此处的输入为`numpy.ndarray`,所以值为`None` + - `model_settings`: `(Dict)` OCR子产线的模型配置参数 + - `dt_polys`: `(List[numpy.ndarray])` 文本检测的多边形框列表。每个检测框由4个顶点坐标构成的numpy数组表示,数组shape为(4, 2),数据类型为int16 + - `dt_scores`: `(List[float])` 文本检测框的置信度列表 + - `text_det_params`: `(Dict[str, Dict[str, int, float]])` 文本检测模块的配置参数 + - `limit_side_len`: `(int)` 图像预处理时的边长限制值 + - `limit_type`: `(str)` 边长限制的处理方式 + - `thresh`: `(float)` 文本像素分类的置信度阈值 + - `box_thresh`: `(float)` 文本检测框的置信度阈值 + - `unclip_ratio`: `(float)` 文本检测框的膨胀系数 + - `text_type`: `(str)` 文本检测的类型,当前固定为"general" + + - `text_type`: `(str)` 文本检测的类型,当前固定为"general" + - `textline_orientation_angles`: `(List[int])` 文本行方向分类的预测结果。启用时返回实际角度值(如[0,0,1] + - `text_rec_score_thresh`: `(float)` 文本识别结果的过滤阈值 + - `rec_texts`: `(List[str])` 文本识别结果列表,仅包含置信度超过`text_rec_score_thresh`的文本 + - `rec_scores`: `(List[float])` 文本识别的置信度列表,已按`text_rec_score_thresh`过滤 + - `rec_polys`: `(List[numpy.ndarray])` 经过置信度过滤的文本检测框列表,格式同`dt_polys` + + - `formula_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 公式识别结果列表,每个元素为一个字典 + - `rec_formula`: `(str)` 公式识别结果 + - `rec_polys`: `(numpy.ndarray)` 公式检测框,shape为(4, 2),dtype为int16 + - `formula_region_id`: `(int)` 公式所在的区域编号 + + - `seal_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 印章识别结果列表,每个元素为一个字典 + - `input_path`: `(str)` 印章图像的输入路径 + - `page_index`: `None`,此处的输入为`numpy.ndarray`,所以值为`None` + - `model_settings`: `(Dict)` 印章识别子产线的模型配置参数 + - `dt_polys`: `(List[numpy.ndarray])` 印章检测框列表,格式同`dt_polys` + - `text_det_params`: `(Dict[str, Dict[str, int, float]])` 印章检测模块的配置参数, 具体参数含义同上 + - `text_type`: `(str)` 印章检测的类型,当前固定为"seal" + - `text_rec_score_thresh`: `(float)` 印章识别结果的过滤阈值 + - `rec_texts`: `(List[str])` 印章识别结果列表,仅包含置信度超过`text_rec_score_thresh`的文本 + - `rec_scores`: `(List[float])` 印章识别的置信度列表,已按`text_rec_score_thresh`过滤 + - `rec_polys`: `(List[numpy.ndarray])` 经过置信度过滤的印章检测框列表,格式同`dt_polys` + - `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个矩形 + + - `table_res_list`: `(List[Dict[str, Union[numpy.ndarray, List[float], str]]])` 表格识别结果列表,每个元素为一个字典 + - `cell_box_list`: `(List[numpy.ndarray])` 表格单元格的边界框列表 + - `pred_html`: `(str)` 表格的HTML格式字符串 + - `table_ocr_pred`: `(dict)` 表格的OCR识别结果 + - `rec_polys`: `(List[numpy.ndarray])` 单元格的检测框列表 + - `rec_texts`: `(List[str])` 单元格的识别结果 + - `rec_scores`: `(List[float])` 单元格的识别置信度 + - `rec_boxes`: `(numpy.ndarray)` 检测框的矩形边界框数组,shape为(n, 4),dtype为int16。每一行表示一个矩形 + +- 调用`save_to_json()` 方法会将上述内容保存到指定的 `save_path` 中,如果指定为目录,则保存的路径为`save_path/{your_img_basename}_res.json`,如果指定为文件,则直接保存到该文件中。由于 json 文件不支持保存numpy数组,因此会将其中的 `numpy.array` 类型转换为列表形式。 +- 调用`save_to_img()` 方法会将可视化结果保存到指定的 `save_path` 中,如果指定为目录,则会将版面区域检测可视化图像、全局OCR可视化图像、版面阅读顺序可视化图像等内容保存,如果指定为文件,则直接保存到该文件中。(产线通常包含较多结果图片,不建议直接指定为具体的文件路径,否则多张图会被覆盖,仅保留最后一张图) +- 调用`save_to_markdown()` 方法会将转化后的 Markdown 文件保存到指定的 `save_path` 中,保存的文件路径为`save_path/{your_img_basename}.md`,如果输入是 PDF 文件,建议直接指定目录,否责多个 markdown 文件会被覆盖。 +- 调用 `concatenate_markdown_pages()` 方法将 PP-DocTranslation 产线输出的多页Markdown内容`markdown_list`合并为单个完整文档,并返回合并后的Markdown内容。 +
      + +
      (4)调用 translate() 方法执行文档翻译,该方法会返回翻译的 markdown 原文和译文,是一个markdown对象,可以通过执行 save_to_markdown() 方法将需要的部分保存到本地。以下是 translate() 方法的相关参数说明: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      参数参数说明参数类型默认值
      ori_md_info_list原始Markdown格式的数据列表,包含需要翻译的内容。必须为字典组成的列表,每个字典表示一个文档块List[Dict]无默认值(必填)
      target_language目标语言(ISO 639-1 语言代码,如 "en"/"ja"/"fr")。str"zh"
      chunk_size翻译文本分块处理的字符数阈值。int5000
      task_description自定义任务描述提示词。str|NoneNone
      output_format指定输出格式要求,如“保持原Markdown结构”。str|NoneNone
      rules_str自定义翻译规则说明。str|NoneNone
      few_shot_demo_text_content少样本学习的示例文本内容。str|NoneNone
      few_shot_demo_key_value_list结构化少样本示例数据。键值对格式的示例数据,可传入专业术语对照表。str|NoneNone
      chat_bot_config大语言模型配置。设置为None表示使用实例化参数,否则该参数优先级更高。dict|NoneNone
      llm_request_interval向大语言模型发送请求的时间间隔,单位为秒。该参数可用于防止过于频繁地调用大语言模型。float0
      + +
      + +## 3. 开发集成/部署 + +如果产线可以达到您对产线推理速度和精度的要求,您可以直接进行开发集成/部署。 + +若您需要将产线直接应用在您的Python项目中,可以参考 [2.2 Python脚本方式](#22-python脚本方式集成)中的示例代码。 + +此外,PaddleOCR 也提供了其他两种部署方式,详细说明如下: + +🚀 高性能推理:在实际生产环境中,许多应用对部署策略的性能指标(尤其是响应速度)有着较严苛的标准,以确保系统的高效运行与用户体验的流畅性。为此,PaddleOCR 提供高性能推理功能,旨在对模型推理及前后处理进行深度性能优化,实现端到端流程的显著提速,详细的高性能推理流程请参考[高性能推理](../deployment/high_performance_inference.md)。 + +☁️ 服务化部署:服务化部署是实际生产环境中常见的一种部署形式。通过将推理功能封装为服务,客户端可以通过网络请求来访问这些服务,以获取推理结果。详细的产线服务化部署流程请参考[服务化部署](../deployment/serving.md)。 + +以下是基础服务化部署的API参考与多语言服务调用示例: + +
      API参考 +

      对于服务提供的主要操作:

      +
        +
      • HTTP请求方法为POST。
      • +
      • 请求体和响应体均为JSON数据(JSON对象)。
      • +
      • 当请求处理成功时,响应状态码为200,响应体的属性如下:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      logIdstring请求的UUID。
      errorCodeinteger错误码。固定为0
      errorMsgstring错误说明。固定为"Success"
      resultobject操作结果。
      +
        +
      • 当请求处理未成功时,响应体的属性如下:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      logIdstring请求的UUID。
      errorCodeinteger错误码。与响应状态码相同。
      errorMsgstring错误说明。
      +

      服务提供的主要操作如下:

      +
        +
      • analyzeImages
      • +
      +

      使用计算机视觉模型对图像进行分析,获得OCR、表格识别结果等。

      +

      POST /doctrans-visual

      +
        +
      • 请求体的属性如下:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义是否必填
      filestring服务器可访问的图像文件或PDF文件的URL,或上述类型文件内容的Base64编码结果。默认对于超过10页的PDF文件,只有前10页的内容会被处理。
      要解除页数限制,请在产线配置文件中添加以下配置: +
      Serving:
      +  extra:
      +    max_num_input_imgs: null
      +
      +
      fileTypeintegernull文件类型。0表示PDF文件,1表示图像文件。若请求体无此属性,则将根据URL推断文件类型。
      useDocOrientationClassifyboolean | null请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。
      useDocUnwarpingboolean | null请参阅产线对象中 predict 方法的 use_doc_unwarping 参数相关说明。
      useTextlineOrientationboolean | null请参阅产线对象中 predict 方法的 use_textline_orientation 参数相关说明。
      useSealRecognitionboolean | null请参阅产线对象中 predict 方法的 use_seal_recognition 参数相关说明。
      useTableRecognitionboolean | null请参阅产线对象中 predict 方法的 use_table_recognition 参数相关说明。
      useFormulaRecognitionboolean | null请参阅产线对象中 predict 方法的 use_formula_recognition 参数相关说明。
      useChartRecognitionboolean | null请参阅产线对象中 predict 方法的 use_chart_recognition 参数相关说明。
      useRegionDetectionboolean | null请参阅产线对象中 predict 方法的 use_region_detection 参数相关说明。
      layoutThresholdnumber | object | null请参阅产线对象中 predict 方法的 layout_threshold 参数相关说明。
      layoutNmsboolean | null请参阅产线对象中 predict 方法的 layout_nms 参数相关说明。
      layoutUnclipRationumber | array | object | null请参阅产线对象中 predict 方法的 layout_unclip_ratio 参数相关说明。
      layoutMergeBboxesModestring | object | null请参阅产线对象中 predict 方法的 layout_merge_bboxes_mode 参数相关说明。
      textDetLimitSideLeninteger | null请参阅产线对象中 predict 方法的 text_det_limit_side_len 参数相关说明。
      textDetLimitTypestring | null请参阅产线对象中 predict 方法的 text_det_limit_type 参数相关说明。
      textDetThreshnumber | null请参阅产线对象中 predict 方法的 text_det_thresh 参数相关说明。
      textDetBoxThreshnumber | null请参阅产线对象中 predict 方法的 text_det_box_thresh 参数相关说明。
      textDetUnclipRationumber | null请参阅产线对象中 predict 方法的 text_det_unclip_ratio 参数相关说明。
      textRecScoreThreshnumber | null请参阅产线对象中 predict 方法的 text_rec_score_thresh 参数相关说明。
      sealDetLimitSideLeninteger | null请参阅产线对象中 predict 方法的 seal_det_limit_side_len 参数相关说明。
      sealDetLimitTypestring | null请参阅产线对象中 predict 方法的 seal_det_limit_type 参数相关说明。
      sealDetThreshnumber | null请参阅产线对象中 predict 方法的 seal_det_thresh 参数相关说明。
      sealDetBoxThreshnumber | null请参阅产线对象中 predict 方法的 seal_det_box_thresh 参数相关说明。
      sealDetUnclipRationumber | null请参阅产线对象中 predict 方法的 seal_det_unclip_ratio 参数相关说明。
      sealRecScoreThreshnumber | null请参阅产线对象中 predict 方法的 seal_rec_score_thresh 参数相关说明。
      useWiredTableCellsTransToHtmlboolean请参阅产线对象中 predict 方法的 use_wired_table_cells_trans_to_html 参数相关说明。No
      useWirelessTableCellsTransToHtmlboolean请参阅产线对象中 predict 方法的 use_wireless_table_cells_trans_to_html 参数相关说明。No
      useTableOrientationClassifyboolean请参阅产线对象中 predict 方法的 use_table_orientation_classify 参数相关说明。No
      useOcrResultsWithTableCellsboolean请参阅产线对象中 predict 方法的 use_ocr_results_with_table_cells 参数相关说明。
      useE2eWiredTableRecModelboolean请参阅产线对象中 predict 方法的 use_e2e_wired_table_rec_model 参数相关说明。
      useE2eWirelessTableRecModelboolean请参阅产线对象中 predict 方法的 use_e2e_wireless_table_rec_model 参数相关说明。
      visualizeboolean | null是否返回可视化结果图以及处理过程中的中间图像等。 +
        +
      • 传入 true:返回图像。
      • +
      • 传入 false:不返回图像。
      • +
      • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
      • +
      +
      例如,在产线配置文件中添加如下字段:
      +
      Serving:
      +  visualize: False
      +
      +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 +
      +
        +
      • 请求处理成功时,响应体的result具有如下属性:
      • +
      + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      layoutParsingResultsarray版面解析结果。数组长度为1(对于图像输入)或实际处理的文档页数(对于PDF输入)。对于PDF输入,数组中的每个元素依次表示PDF文件中实际处理的每一页的结果。
      dataInfoobject输入数据信息。
      +

      layoutParsingResults中的每个元素为一个object,具有如下属性:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      prunedResultobject产线对象的 visual_predict 方法生成的 layout_parsing_result 的 JSON 表示中 res 字段的简化版本,其中去除了 input_pathpage_index 字段。
      markdownobjectMarkdown结果。
      outputImagesobject | null参见产线预测结果的 img 属性说明。图像为JPEG格式,使用Base64编码。
      inputImagestring | null输入图像。图像为JPEG格式,使用Base64编码。
      +

      markdown为一个object,具有如下属性:

      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      textstringMarkdown文本。
      imagesobjectMarkdown图片相对路径和Base64编码图像的键值对。
      isStartboolean当前页面第一个元素是否为段开始。
      isEndboolean当前页面最后一个元素是否为段结束。
      +
        +
      • translate
      • +
      +

      利用大模型翻译文档。

      +

      POST /doctrans-translate

      +
        +
      • 请求体的属性如下:
      • +
      + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      名称类型含义是否必填
      markdownListarray待翻译的Markdown列表。可从analyzeImages操作的结果中获取。images属性将不会被用到。
      targetLanguagestring请参阅产线对象中 translate 方法的 target_language 参数相关说明。
      chunkSizeinteger请参阅产线对象中 translate 方法的 chunk_size 参数相关说明。
      taskDescriptionstring | null请参阅产线对象中 translate 方法的 task_description 参数相关说明。
      outputFormatstring | null请参阅产线对象中 translate 方法的 output_format 参数相关说明。
      rulesStrstring | null请参阅产线对象中 translate 方法的 rules_str 参数相关说明。
      fewShotDemoTextContentstring | null请参阅产线对象中 translate 方法的 few_shot_demo_text_content 参数相关说明。
      fewShotDemoKeyValueListstring | null请参阅产线对象中 translate 方法的 few_shot_demo_key_value_list 参数相关说明。
      chatBotConfigobject | null请参阅产线对象中 translate 方法的 chat_bot_config 参数相关说明。
      llmRequestIntervalnumber | null请参阅产线对象中 translate 方法的 llm_request_interval 参数相关说明。
      +
        +
      • 请求处理成功时,响应体的result具有如下属性:
      • +
      + + + + + + + + + + + + + + + +
      名称类型含义
      translationResultsarray翻译结果。
      +

      translationResults中的每个元素为一个object,具有如下属性:

      + + + + + + + + + + + + + + + + + + + + +
      名称类型含义
      languagestring目标语言。
      markdownobjectMarkdown结果。对象定义与analyzeImages操作返回的markdown一致。
      +
    • 注意:
    • +在请求体中包含大模型调用的API key等敏感参数可能存在安全风险。如无必要,请在配置文件中设置这些参数,在请求时不传递。 +

      +
      +
      多语言调用服务示例 +
      +Python + +
      import base64
      +import pathlib
      +import pprint
      +import sys
      +
      +import requests
      +
      +
      +API_BASE_URL = "http://127.0.0.1:8080"
      +
      +file_path = "./demo.jpg"
      +target_language = "en"
      +
      +with open(file_path, "rb") as file:
      +    file_bytes = file.read()
      +    file_data = base64.b64encode(file_bytes).decode("ascii")
      +
      +payload = {
      +    "file": file_data,
      +    "fileType": 1,
      +}
      +resp_visual = requests.post(url=f"{API_BASE_URL}/doctrans-visual", json=payload)
      +if resp_visual.status_code != 200:
      +    print(
      +        f"Request to doctrans-visual failed with status code {resp_visual.status_code}."
      +    )
      +    pprint.pp(resp_visual.json())
      +    sys.exit(1)
      +result_visual = resp_visual.json()["result"]
      +
      +markdown_list = []
      +for i, res in enumerate(result_visual["layoutParsingResults"]):
      +    md_dir = pathlib.Path(f"markdown_{i}")
      +    md_dir.mkdir(exist_ok=True)
      +    (md_dir / "doc.md").write_text(res["markdown"]["text"])
      +    for img_path, img in res["markdown"]["images"].items():
      +        img_path = md_dir / img_path
      +        img_path.parent.mkdir(parents=True, exist_ok=True)
      +        img_path.write_bytes(base64.b64decode(img))
      +    print(f"Markdown document to be translated is saved at {md_dir / 'doc.md'}")
      +    del res["markdown"]["images"]
      +    markdown_list.append(res["markdown"])
      +    for img_name, img in res["outputImages"].items():
      +        img_path = f"{img_name}_{i}.jpg"
      +        with open(img_path, "wb") as f:
      +            f.write(base64.b64decode(img))
      +        print(f"Output image saved at {img_path}")
      +
      +payload = {
      +    "markdownList": markdown_list,
      +    "targetLanguage": target_language,
      +}
      +resp_translate = requests.post(url=f"{API_BASE_URL}/doctrans-translate", json=payload)
      +if resp_translate.status_code != 200:
      +    print(
      +        f"Request to doctrans-translate failed with status code {resp_translate.status_code}."
      +    )
      +    pprint.pp(resp_translate.json())
      +    sys.exit(1)
      +result_translate = resp_translate.json()["result"]
      +
      +for i, res in enumerate(result_translate["translationResults"]):
      +    md_dir = pathlib.Path(f"markdown_{i}")
      +    (md_dir / "doc_translated.md").write_text(res["markdown"]["text"])
      +    print(f"Translated markdown document saved at {md_dir / 'doc_translated.md'}")
      +
      +
      +
      + +## 4. 二次开发 +如果 PP-DocTranslation 产线提供的默认模型权重在您的场景中,精度或速度不满意,您可以尝试利用您自己拥有的特定领域或应用场景的数据对现有模型进行进一步的微调,以提升在您的场景中的识别效果。 + +### 4.1 模型微调 +由于 PP-DocTranslation 产线包含若干模块,模型产线的效果如果不及预期,可能来自于其中任何一个模块。您可以对提取效果差的 case 进行分析,通过可视化图像,确定是哪个模块存在问题,并参考以下表格中对应的微调教程链接进行模型微调。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      情形微调模块微调参考链接
      版面区域检测不准,如印章、表格未检出等版面区域检测模块链接
      表格结构识别不准表格结构识别模块链接
      公式识别不准公式识别模块链接
      印章文本存在漏检印章文本检测模块链接
      文本存在漏检文本检测模块链接
      文本内容都不准文本识别模块链接
      垂直或者旋转文本行矫正不准文本行方向分类模块链接
      整图旋转矫正不准文档图像方向分类模块链接
      图像扭曲矫正不准文本图像矫正模块暂不支持微调
      + +### 4.2 模型应用 +当您使用私有数据集完成微调训练后,可获得本地模型权重文件,然后可以通过自定义产线配置文件的方式,使用微调后的模型权重。 + +1. 获取产线配置文件 + +可调用 PaddleOCR 中 PP-DocTranslation 产线对象的 `export_paddlex_config_to_yaml` 方法,将当前产线配置导出为 YAML 文件: + +```Python +from paddleocr import PPDocTranslation + +pipeline = PPDocTranslation() +pipeline.export_paddlex_config_to_yaml("PP-DocTranslation.yaml") +``` + +2. 修改配置文件 + +在得到默认的产线配置文件后,将微调后模型权重的本地路径替换至产线配置文件中的对应位置即可。例如 + +```yaml +...... +SubModules: + TextDetection: + module_name: text_detection + model_name: PP-OCRv5_server_det + model_dir: null # 替换为微调后的文本检测模型权重路径 + limit_side_len: 960 + limit_type: max + thresh: 0.3 + box_thresh: 0.6 + unclip_ratio: 1.5 + + TextRecognition: + module_name: text_recognition + model_name: PP-OCRv5_server_rec + model_dir: null # 替换为微调后的文本检测模型权重路径 + batch_size: 1 + score_thresh: 0 +...... +``` + +在产线配置文件中,不仅包含 PaddleOCR CLI 和 Python API 支持的参数,还可进行更多高级配置,具体信息可在 [PaddleX模型产线使用概览](https://paddlepaddle.github.io/PaddleX/3.0/pipeline_usage/pipeline_develop_guide.html) 中找到对应的产线使用教程,参考其中的详细说明,根据需求调整各项配置。 + +3. 在 CLI 中加载产线配置文件 + +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: + +```bash +paddleocr pp_doctranslation --paddlex_config PP-DocTranslation.yaml ... +``` + +4. 在 Python API 中加载产线配置文件 + +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: + +```python +from paddleocr import PPDocTranslation + +pipeline = PPDocTranslation(paddlex_config="PP-DocTranslation.yaml") +``` diff --git a/docs/version3.x/pipeline_usage/PP-StructureV3.en.md b/docs/version3.x/pipeline_usage/PP-StructureV3.en.md index fa0fd7cc85..d19a89ca45 100644 --- a/docs/version3.x/pipeline_usage/PP-StructureV3.en.md +++ b/docs/version3.x/pipeline_usage/PP-StructureV3.en.md @@ -8,7 +8,7 @@ comments: true Layout analysis is a technique used to extract structured information from document images. It is primarily used to convert complex document layouts into machine-readable data formats. This technology has broad applications in document management, information extraction, and data digitization. Layout analysis combines Optical Character Recognition (OCR), image processing, and machine learning algorithms to identify and extract text blocks, titles, paragraphs, images, tables, and other layout elements from documents. This process generally includes three main steps: layout analysis, element analysis, and data formatting. The final result is structured document data, which enhances the efficiency and accuracy of data processing. PP-StructureV3 improves upon the general layout analysis v1 pipeline by enhancing layout region detection, table recognition, and formula recognition. It also adds capabilities such as multi-column reading order recovery, chart understanding, and result conversion to Markdown files. It performs excellently across various document types and can handle complex document data. This pipeline also provides flexible service deployment options, supporting invocation using multiple programming languages on various hardware. In addition, it offers secondary development capabilities, allowing you to train and fine-tune models on your own dataset and integrate the trained models seamlessly. -PP-StructureV3 includes the following six modules. Each module can be independently trained and inferred, and contains multiple models. Click the corresponding module for more documentation. +The PP-StructureV3 pipeline consists of the following six modules or sub-pipelines. Each module or sub-pipeline can be trained and inferred independently and contains multiple models. For more details, please click the corresponding links to view the documentation. - [Layout Detection Module](../module_usage/layout_detection.en.md) - [General OCR Subline](./OCR.en.md) @@ -1033,7 +1033,7 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu layout_merge_bboxes_mode -The merging mode for the detection boxes output by the model in layout region detection. +The merging mode for the detection boxes output by the model in layout detection.
      • large: When set to "large", only the largest outer bounding box will be retained for overlapping bounding boxes, and the inner overlapping boxes will be removed;
      • small: When set to "small", only the smallest inner bounding boxes will be retained for overlapping bounding boxes, and the outer overlapping boxes will be removed;
      • @@ -1362,13 +1362,13 @@ any float > 0. If not set, the default is 0.6. use_doc_orientation_classify Whether to use document orientation classification module. bool -False +False use_doc_unwarping Whether to use document unwarping module. bool -False +False use_textline_orientation @@ -1398,7 +1398,7 @@ any float > 0. If not set, the default is 0.6. use_chart_recognition Whether to use the chart parsing module. bool -False +False use_region_detection @@ -2003,31 +2003,31 @@ The above Python script performs the following steps: use_textline_orientation -Whether to use the text line orientation classification. If not set, the default is True. -bool - +Whether to use the text line orientation classification. If set to None, the default value is True. +bool|None +None use_seal_recognition -Whether to enable seal text recognition subpipeline. If not set, the default is True. -bool - +Whether to enable seal text recognition subpipeline. If set to None, the default value is True. +bool|None +None use_table_recognition -Whether to enable table recognition subpipeline. If not set, the default is True. -bool - +Whether to enable table recognition subpipeline. If set to None, the default value is True. +bool|None +None use_formula_recognition -Whether to enable formula recognition subpipeline. If not set, the default is True. -bool - +Whether to enable formula recognition subpipeline. If set to None, the default value is True. +bool|None +None use_chart_recognition -Whether to use the chart parsing module. If set to None, the default value is True. +Whether to load and use the chart parsing module. If set to None, the default value is True. bool|None None @@ -2130,49 +2130,49 @@ MKL-DNN cache capacity. use_doc_orientation_classify -Whether to use document orientation classification during inference. +Whether to use document orientation classification during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None False use_doc_unwarping -Whether to use document image unwarping during inference. +Whether to use document image unwarping during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None False use_textline_orientation -Whether to use textline orientation classification during inference. +Whether to use textline orientation classification during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None None use_seal_recognition -Whether to use the seal text recognition sub-pipeline during inference. +Whether to use the seal text recognition sub-pipeline during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None None use_table_recognition -Whether to use the table recognition sub-pipeline during inference. +Whether to use the table recognition sub-pipeline during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None None use_formula_recognition -Whether to use the formula recognition sub-pipeline during inference. +Whether to use the formula recognition sub-pipeline during inference. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None None use_chart_recognition -Whether to use the chart parsing module. If set to None, the default value is True. +Whether to use the chart parsing module. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None False use_region_detection -Whether to use the document region detection pipeline. If set to None, the default value is True. +Whether to use the document region detection pipeline. If set to None, the instantiation value is used; otherwise, this parameter takes precedence. bool|None None @@ -2274,13 +2274,13 @@ MKL-DNN cache capacity. use_wired_table_cells_trans_to_html -Whether to enable direct conversion of wired table cell detection results to HTML. Default is False. If enabled, HTML will be constructed directly based on the geometric relationship of wired table cell detection results. +Whether to enable direct conversion of wired table cell detection results to HTML. If enabled, HTML will be constructed directly based on the geometric relationship of wired table cell detection results. bool False use_wireless_table_cells_trans_to_html -Whether to enable direct conversion of wireless table cell detection results to HTML. Default is False. If enabled, HTML will be constructed directly based on the geometric relationship of wireless table cell detection results. +Whether to enable direct conversion of wireless table cell detection results to HTML. If enabled, HTML will be constructed directly based on the geometric relationship of wireless table cell detection results. bool False @@ -2648,26 +2648,6 @@ Below is the API reference and multi-language service invocation examples for ba No -visualize -boolean | null - -Whether to return the final visualization image and intermediate images during the processing.
        -
          -
        • If true is provided: return images.
        • -
        • If false is provided: do not return any images.
        • -
        • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
        • -
        -
        -For example, adding the following setting to the pipeline config file:
        -
        Serving:
        -  visualize: False
        -
        -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
        -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Refer to the use_doc_orientation_classify parameter in the pipeline’s predict method. @@ -2818,6 +2798,26 @@ If neither the request body nor the configuration file is set (If visualiz Refer to the use_e2e_wireless_table_rec_model parameter in the pipeline’s predict method. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
        +
          +
        • If true is provided: return images.
        • +
        • If false is provided: do not return any images.
        • +
        • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
        • +
        +
        +For example, adding the following setting to the pipeline config file:
        +
        Serving:
        +  visualize: False
        +
        +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
        +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
          @@ -2894,7 +2894,7 @@ If neither the request body nor the configuration file is set (If visualiz images object -Key-value pairs of image relative paths and base64-encoded image content. +Key-value pairs of image relative paths and Base64-encoded image content. isStart @@ -3512,7 +3512,7 @@ paddleocr pp_structurev3 --paddlex_config PP-StructureV3.yaml ... ``` 4. Load the pipeline configuration file via Python API -When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or a configuration dictionary using the paddlex_config parameter. PaddleOCR will load its content as the pipeline configuration. Example: +When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or a configuration dictionary using the `paddlex_config` parameter. PaddleOCR will load its content as the pipeline configuration. Example: ```python from paddleocr import PPStructureV3 diff --git a/docs/version3.x/pipeline_usage/PP-StructureV3.md b/docs/version3.x/pipeline_usage/PP-StructureV3.md index 7e1b1a2a89..b1acfd064e 100644 --- a/docs/version3.x/pipeline_usage/PP-StructureV3.md +++ b/docs/version3.x/pipeline_usage/PP-StructureV3.md @@ -8,7 +8,7 @@ comments: true 版面解析是一种从文档图像中提取结构化信息的技术,主要用于将复杂的文档版面转换为机器可读的数据格式。这项技术在文档管理、信息提取和数据数字化等领域具有广泛的应用。版面解析通过结合光学字符识别(OCR)、图像处理和机器学习算法,能够识别和提取文档中的文本块、标题、段落、图片、表格以及其他版面元素。此过程通常包括版面分析、元素分析和数据格式化三个主要步骤,最终生成结构化的文档数据,提升数据处理的效率和准确性。PP-StructureV3 产线在通用版面解析v1产线的基础上,强化了版面区域检测、表格识别、公式识别的能力,增加了图表理解能力和多栏阅读顺序的恢复能力、结果转换 Markdown 文件的能力,在多种文档数据中,表现优异,可以处理较复杂的文档数据。本产线同时提供了灵活的服务化部署方式,支持在多种硬件上使用多种编程语言调用。不仅如此,本产线也提供了二次开发的能力,您可以基于本产线在您自己的数据集上训练调优,训练后的模型也可以无缝集成。 -PP-StructureV3 产线中包含以下6个模块。每个模块均可独立进行训练和推理,并包含多个模型。有关详细信息,请点击相应模块以查看文档。 +PP-StructureV3 产线中包含以下6个模块或子产线。每个模块或子产线均可独立进行训练和推理,并包含多个模型。有关详细信息,请点击相应链接以查看文档。 - [版面区域检测模块](../module_usage/layout_detection.md) - [通用OCR子产线](./OCR.md) @@ -1094,21 +1094,21 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu layout_threshold -版面模型得分阈值。0-1 之间的任意浮点数。如果不设置,将默认使用产线初始化的该参数值,初始化为 0.5。 +版面模型得分阈值。0-1 之间的任意浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 0.5float layout_nms -版面检测是否使用后处理NMS。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool layout_unclip_ratio 版面区域检测模型检测框的扩张系数。 -任意大于 0 浮点数。如果不设置,将默认使用产线初始化的该参数值,初始化为 1.0。 +任意大于 0 浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 1.0float @@ -1120,7 +1120,7 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu
        • large,设置为large时,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留外部最大的框,删除重叠的内部框;
        • small,设置为small,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留内部被包含的小框,删除重叠的外部框;
        • union,不进行框的过滤处理,内外框都保留;
        • -
        如果不设置,将默认使用产线初始化的该参数值,初始化为large。 +
      如果不设置,将使用产线初始化的该参数值,默认初始化为largestr @@ -1194,14 +1194,14 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu text_det_limit_side_len 文本检测的图像边长限制。 -大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 960。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 960int text_det_limit_type -文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 max。 +文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 maxstr @@ -1363,14 +1363,14 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu seal_det_limit_side_len 印章文本检测的图像边长限制。 -大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 736。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 736int seal_det_limit_type -印章文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 min。 +印章文本检测的图像边长限制类型。支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 minstr @@ -1450,35 +1450,35 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu use_doc_orientation_classify 是否使用文档方向分类模块。 bool -False +False use_doc_unwarping 是否使用文本图像矫正模块。 bool -False +False use_textline_orientation -是否加载并使用文本行方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本行方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_seal_recognition -是否加载并使用印章文本识别子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用印章文本识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_table_recognition -是否加载并使用表格识别子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用表格识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_formula_recognition -是否加载并使用公式识别子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用公式识别子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -1486,11 +1486,11 @@ paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png --device gpu use_chart_recognition 是否使用图表解析模块。 bool -False +False use_region_detection -是否加载并使用文档区域检测子产线。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档区域检测子产线。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -1655,7 +1655,7 @@ for item in markdown_images: 在上述 Python 脚本中,执行了如下几个步骤: -
      (1)实例化 PPStructureV3 实例化产线对象,具体参数说明如下: +
      (1)实例化产线对象,具体参数说明如下: @@ -1685,7 +1685,7 @@ for item in markdown_images:
      • float0-1 之间的任意浮点数;
      • dict{0:0.1} key为类别ID,value为该类别的阈值;
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 0.5
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 0.5
      @@ -1693,7 +1693,7 @@ for item in markdown_images: - + @@ -1704,7 +1704,7 @@ for item in markdown_images:
    • float:任意大于 0 浮点数;
    • Tuple[float,float]:在横纵两个方向各自的扩张系数;
    • dict,dict的key为int类型,代表cls_id, value为tuple类型,如{0: (1.1, 2.0)},表示将模型输出的第0类别检测框中心不变,宽度扩张1.1倍,高度扩张2.0倍;
    • -
    • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 1.0
    • +
    • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 1.0
    • @@ -1716,7 +1716,7 @@ for item in markdown_images:
      • strlargesmallunion,分别表示重叠框过滤时选择保留大框,小框还是同时保留;
      • dict: dict的key为int类型,代表cls_id,value为str类型,如{0: "large", 2: "small"},表示对第0类别检测框使用large模式,对第2类别检测框使用small模式;
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 large
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 large
      @@ -1793,7 +1793,7 @@ for item in markdown_images: @@ -1804,7 +1804,7 @@ for item in markdown_images: @@ -1975,7 +1975,7 @@ for item in markdown_images: @@ -1986,7 +1986,7 @@ for item in markdown_images: @@ -2070,49 +2070,49 @@ for item in markdown_images: - + - + - + - + - + - + - + - + @@ -2210,49 +2210,49 @@ MKL-DNN 缓存容量。 - + - + - + - + - + - + - + - + @@ -2354,13 +2354,13 @@ MKL-DNN 缓存容量。 - + - + @@ -2728,23 +2728,6 @@ MKL-DNN 缓存容量。 - - - - - - @@ -2894,6 +2877,23 @@ MKL-DNN 缓存容量。 + + + + + +
      float|dict|None
      layout_nms版面检测是否使用后处理NMS。如果设置为None,将默认使用产线初始化的该参数值,初始化为True版面检测是否使用后处理NMS。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      float|Tuple[float,float]|dict|None str|dict|None文本检测的图像边长限制。
      • int:大于 0 的任意整数;
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 960
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 960
      int|None文本检测的图像边长限制类型。
      • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 max
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 max
      str|None印章文本检测的图像边长限制。
      • int:大于 0 的任意整数;
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 736
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 736
      int|None印章文本检测的图像边长限制类型。
      • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
      • -
      • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 min
      • +
      • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 min
      str|None
      use_doc_orientation_classify是否加载文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_doc_unwarping是否加载文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_textline_orientation是否加载并使用文本行方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用文本行方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_seal_recognition是否加载并使用印章文本识别子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用印章文本识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_table_recognition是否加载并使用表格识别子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用表格识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_formula_recognition是否加载并使用公式识别子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用公式识别子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_chart_recognition是否加载图表解析模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用图表解析模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_region_detection是否加载并使用文档区域检测子产线。如果设置为None,将默认使用产线初始化的该参数值,初始化为True是否加载并使用文档区域检测子产线。如果设置为None,将使用产线初始化的该参数值,默认初始化为True bool|None None
      use_doc_orientation_classify是否在推理时使用文档方向分类模块。是否在推理时使用文档方向分类模块。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None False
      use_doc_unwarping是否在推理时使用文本图像矫正模块。是否在推理时使用文本图像矫正模块。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None False
      use_textline_orientation是否在推理时使用文本行方向分类模块。是否在推理时使用文本行方向分类模块。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None None
      use_seal_recognition是否在推理时使用印章文本识别子产线。是否在推理时使用印章文本识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None None
      use_table_recognition是否在推理时使用表格识别子产线。是否在推理时使用表格识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None None
      use_formula_recognition是否在推理时使用公式识别子产线。是否在推理时使用公式识别子产线。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None None
      use_chart_recognition是否使用图表解析模块。是否使用图表解析模块。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None False
      use_region_detection是否使用文档区域检测子产线。是否使用文档区域检测子产线。设置为None表示使用实例化参数,否则该参数优先级更高。 bool|None None
      use_wired_table_cells_trans_to_html是否启用有线表单元格检测结果直转HTML,默认False,启用则直接基于有线表单元格检测结果的几何关系构建HTML。是否启用有线表单元格检测结果直转HTML,启用则直接基于有线表单元格检测结果的几何关系构建HTML。 bool False
      use_wireless_table_cells_trans_to_html是否启用无线表单元格检测结果直转HTML,默认False,启用则直接基于无线表单元格检测结果的几何关系构建HTML。是否启用无线表单元格检测结果直转HTML,启用则直接基于无线表单元格检测结果的几何关系构建HTML。 bool False
      visualizeboolean | null是否返回可视化结果图以及处理过程中的中间图像等。 -
        -
      • 传入 true:返回图像。
      • -
      • 传入 false:不返回图像。
      • -
      • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
      • -
      -
      例如,在产线配置文件中添加如下字段:
      -
      Serving:
      -  visualize: False
      -
      -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 -
      useDocOrientationClassify boolean | null 请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。请参阅产线对象中 predict 方法的 use_e2e_wireless_table_rec_model 参数相关说明。
      visualizeboolean | null是否返回可视化结果图以及处理过程中的中间图像等。 +
        +
      • 传入 true:返回图像。
      • +
      • 传入 false:不返回图像。
      • +
      • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
      • +
      +
      例如,在产线配置文件中添加如下字段:
      +
      Serving:
      +  visualize: False
      +
      +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 +
        @@ -2938,7 +2938,7 @@ MKL-DNN 缓存容量。 markdown object -markdown结果。 +Markdown结果。 outputImages @@ -2970,7 +2970,7 @@ MKL-DNN 缓存容量。 images object -Markdown图片相对路径和base64编码图像的键值对。 +Markdown图片相对路径和Base64编码图像的键值对。 isStart @@ -3581,7 +3581,7 @@ SubPipelines: 3. 在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash paddleocr pp_structurev3 --paddlex_config PP-StructureV3.yaml ... @@ -3589,7 +3589,7 @@ paddleocr pp_structurev3 --paddlex_config PP-StructureV3.yaml ... 4. 在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python from paddleocr import PPStructureV3 diff --git a/docs/version3.x/pipeline_usage/doc_preprocessor.en.md b/docs/version3.x/pipeline_usage/doc_preprocessor.en.md index 0783dc37b8..b7de998b0b 100644 --- a/docs/version3.x/pipeline_usage/doc_preprocessor.en.md +++ b/docs/version3.x/pipeline_usage/doc_preprocessor.en.md @@ -196,13 +196,13 @@ For example, the local path of an image file or PDF file: /root/data/img.j use_doc_orientation_classify -Whether to load and use the document orientation classification module. If not set, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the document orientation classification module. If not set, the parameter value initialized by the pipeline will be used, which defaults to True. bool use_doc_unwarping -Whether to load and use the text image unwarping module. If not set, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the text image unwarping module. If not set, the parameter value initialized by the pipeline will be used, which defaults to True. bool @@ -342,13 +342,13 @@ In the above Python script, the following steps are executed: use_doc_orientation_classify -Whether to load and use the document orientation classification module. If set to None, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the document orientation classification module. If set to None, the parameter value initialized by the pipeline will be used, which defaults to True. bool|None None use_doc_unwarping -Whether to load and use the text image unwarping module. If set to None, the parameter value initialized by the pipeline will be used by default, initialized as True. +Whether to load and use the text image unwarping module. If set to None, the parameter value initialized by the pipeline will be used, which defaults to True. bool|None None @@ -680,6 +680,18 @@ Below are the API references for basic service-oriented deployment and examples No +useDocOrientationClassify +boolean | null +Please refer to the description of the use_doc_orientation_classify parameter in the predict method of the pipeline object. +No + + +useDocUnwarping +boolean | null +Please refer to the description of the use_doc_unwarping parameter in the predict method of the pipeline object. +No + + visualize boolean | null @@ -699,18 +711,6 @@ If neither the request body nor the configuration file is set (If visualiz No - -useDocOrientationClassify -boolean | null -Please refer to the description of the use_doc_orientation_classify parameter in the predict method of the pipeline object. -No - - -useDocUnwarping -boolean | null -Please refer to the description of the use_doc_unwarping parameter in the predict method of the pipeline object. -No -
          diff --git a/docs/version3.x/pipeline_usage/doc_preprocessor.md b/docs/version3.x/pipeline_usage/doc_preprocessor.md index 33b7643f4f..1308188e69 100644 --- a/docs/version3.x/pipeline_usage/doc_preprocessor.md +++ b/docs/version3.x/pipeline_usage/doc_preprocessor.md @@ -198,14 +198,14 @@ paddleocr doc_preprocessor -i ./doc_test_rotated.jpg --device gpu use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -347,14 +347,14 @@ for res in output: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -687,6 +687,18 @@ MKL-DNN 缓存容量。 否 +useDocOrientationClassify +boolean | null +请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 +否 + + +useDocUnwarping +boolean | null +请参阅产线对象中 predict 方法的 use_doc_unwarping 参数相关说明。 +否 + + visualize boolean | null 是否返回可视化结果图以及处理过程中的中间图像等。 @@ -703,18 +715,6 @@ MKL-DNN 缓存容量。 否 - -useDocOrientationClassify -boolean | null -请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 -否 - - -useDocUnwarping -boolean | null -请参阅产线对象中 predict 方法的 use_doc_unwarping 参数相关说明。 -否 -
            diff --git a/docs/version3.x/pipeline_usage/doc_understanding.en.md b/docs/version3.x/pipeline_usage/doc_understanding.en.md index 74136d2ea1..6dabf3adb9 100644 --- a/docs/version3.x/pipeline_usage/doc_understanding.en.md +++ b/docs/version3.x/pipeline_usage/doc_understanding.en.md @@ -758,7 +758,7 @@ OpenAI interface invocation example
            import base64
             from openai import OpenAI
             
            -API_BASE_URL = "http://0.0.0.0:8080"
            +API_BASE_URL = "http://127.0.0.1:8080"
             
             # Initialize OpenAI client
             client = OpenAI(
            diff --git a/docs/version3.x/pipeline_usage/doc_understanding.md b/docs/version3.x/pipeline_usage/doc_understanding.md
            index 120d24177c..23430ab35d 100644
            --- a/docs/version3.x/pipeline_usage/doc_understanding.md
            +++ b/docs/version3.x/pipeline_usage/doc_understanding.md
            @@ -756,7 +756,7 @@ openai接口调用示例
             
            import base64
             from openai import OpenAI
             
            -API_BASE_URL = "http://0.0.0.0:8080"
            +API_BASE_URL = "http://127.0.0.1:8080"
             
             # 初始化OpenAI客户端
             client = OpenAI(
            diff --git a/docs/version3.x/pipeline_usage/formula_recognition.en.md b/docs/version3.x/pipeline_usage/formula_recognition.en.md
            index d7bc0329d4..775d3eb76e 100644
            --- a/docs/version3.x/pipeline_usage/formula_recognition.en.md
            +++ b/docs/version3.x/pipeline_usage/formula_recognition.en.md
            @@ -495,14 +495,14 @@ The name of the document orientation classification model. If not set, the defau
             
             
             use_doc_orientation_classify
            -Whether to load and use the document orientation classification module. If not set, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the document orientation classification module. If not set, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool
             
             
             
             use_doc_unwarping
             
            -Whether to load and use the text image unwarping module. If not set, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the text image unwarping module. If not set, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool
             
             
            @@ -530,7 +530,7 @@ The name of the layout detection model. If not set, the default model in pipelin
             
             layout_nms
             
            -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will default to the value initialized in the pipeline, which is set to True by default.
            +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will be set to the value initialized in the pipeline, which is True by default.
             
             bool
             
            @@ -563,7 +563,7 @@ Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detec
             
             use_layout_detection
             
            -Whether to load and use the layout detection module. If not set, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the layout detection module. If not set, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool
             
             
            @@ -749,13 +749,13 @@ In the above Python script, the following steps are executed:
             
             
             use_doc_orientation_classify
            -Whether to load and use the document orientation classification module. If set to None, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the document orientation classification module. If set to None, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool|None
             None
             
             
             use_doc_unwarping
            -Whether to load and use the text image unwarping module. If set to None, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the text image unwarping module. If set to None, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool|None
             None
             
            @@ -785,7 +785,7 @@ In the above Python script, the following steps are executed:
             
             
             layout_nms
            -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will default to the value initialized in the pipeline, which is set to True by default.
            +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will be set to the value initialized in the pipeline, which is set to True by default.
             bool|None
             None
             
            @@ -822,7 +822,7 @@ In the above Python script, the following steps are executed:
             
             
             use_layout_detection
            -Whether to load and use the layout detection module. If set to None, the parameter will default to the value initialized in the pipeline, which is True.
            +Whether to load and use the layout detection module. If set to None, the parameter will be set to the value initialized in the pipeline, which is True by default.
             bool|None
             None
             
            @@ -1225,26 +1225,6 @@ To remove the page limit, please add the following configuration to the pipeline
             No
             
             
            -visualize
            -boolean | null
            -
            -Whether to return the final visualization image and intermediate images during the processing.
            -
              -
            • If true is provided: return images.
            • -
            • If false is provided: do not return any images.
            • -
            • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
            • -
            -
            -For example, adding the following setting to the pipeline config file:
            -
            Serving:
            -  visualize: False
            -
            -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
            -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Please refer to the description of the use_doc_orientation_classify parameter of the pipeline object's predict method. @@ -1286,6 +1266,26 @@ If neither the request body nor the configuration file is set (If visualiz Please refer to the description of the layout_merge_bboxes_mode parameter of the pipeline object's predict method. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
            +
              +
            • If true is provided: return images.
            • +
            • If false is provided: do not return any images.
            • +
            • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
            • +
            +
            +For example, adding the following setting to the pipeline config file:
            +
            Serving:
            +  visualize: False
            +
            +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
            +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
              diff --git a/docs/version3.x/pipeline_usage/formula_recognition.md b/docs/version3.x/pipeline_usage/formula_recognition.md index e6bea97799..509465ebb5 100644 --- a/docs/version3.x/pipeline_usage/formula_recognition.md +++ b/docs/version3.x/pipeline_usage/formula_recognition.md @@ -492,13 +492,13 @@ paddleocr formula_recognition_pipeline -i ./general_formula_recognition_001.png use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -525,7 +525,7 @@ paddleocr formula_recognition_pipeline -i ./general_formula_recognition_001.png layout_nms -版面检测是否使用后处理NMS。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -556,7 +556,7 @@ paddleocr formula_recognition_pipeline -i ./general_formula_recognition_001.png use_layout_detection -是否加载并使用版面区域检测模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面区域检测模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -738,13 +738,13 @@ for res in output: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -773,7 +773,7 @@ for res in output: layout_nms -版面检测是否使用后处理NMS。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -784,7 +784,7 @@ for res in output:
            • float:任意大于 0 浮点数;
            • Tuple[float,float]:在横纵两个方向各自的扩张系数;
            • dict,dict的key为int类型,代表cls_id,value为tuple类型,如{0: (1.1,2.0)},表示将模型输出的第0类别检测框中心不变,宽度扩张1.1倍,高度扩张2.0倍
            • -
            • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 1.0
            • +
            • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 1.0
            float|Tuple[float,float]|dict|None @@ -796,7 +796,7 @@ for res in output:
            • strlargesmallunion,分别表示重叠框过滤时选择保留大框,小框还是同时保留;
            • dict: dict的key为int类型,代表cls_id,value为str类型,如{0: "large", 2: "small"},表示对第0类别检测框使用large模式,对第2类别检测框使用small模式;
            • -
            • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 large
            • +
            • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 large
            str|dict|None @@ -810,7 +810,7 @@ for res in output: use_layout_detection -是否加载并使用版面区域检测模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面区域检测模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1205,23 +1205,6 @@ MKL-DNN 缓存容量。 否 -visualize -boolean | null -是否返回可视化结果图以及处理过程中的中间图像等。 -
              -
            • 传入 true:返回图像。
            • -
            • 传入 false:不返回图像。
            • -
            • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
            • -
            -
            例如,在产线配置文件中添加如下字段:
            -
            Serving:
            -  visualize: False
            -
            -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 - -否 - - useDocOrientationClassify boolean | null 请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 @@ -1263,6 +1246,23 @@ MKL-DNN 缓存容量。 请参阅产线对象中predict方法的 layout_merge_bboxes_mode 参数相关说明。 否 + +visualize +boolean | null +是否返回可视化结果图以及处理过程中的中间图像等。 +
              +
            • 传入 true:返回图像。
            • +
            • 传入 false:不返回图像。
            • +
            • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
            • +
            +
            例如,在产线配置文件中添加如下字段:
            +
            Serving:
            +  visualize: False
            +
            +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 + +否 +
              @@ -1888,7 +1888,7 @@ use_layout_detection: true 3.在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash paddleocr formula_recognition_pipeline -i ./general_formula_recognition_001.png --paddlex_config FormulaRecognitionPipeline.yaml @@ -1896,7 +1896,7 @@ paddleocr formula_recognition_pipeline -i ./general_formula_recognition_001.png 4.在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python from paddleocr import FormulaRecognitionPipeline diff --git a/docs/version3.x/pipeline_usage/seal_recognition.en.md b/docs/version3.x/pipeline_usage/seal_recognition.en.md index 9d0f917f53..a39b3d9251 100644 --- a/docs/version3.x/pipeline_usage/seal_recognition.en.md +++ b/docs/version3.x/pipeline_usage/seal_recognition.en.md @@ -823,7 +823,7 @@ The name of the layout detection model. If not set, the default model in pipelin use_layout_detection -Whether to load and use the layout detection module. If not set, the parameter will default to the value initialized in the pipeline, which is True. +Whether to load and use the layout detection module. If not set, the parameter will be set to the value initialized in the pipeline, which is True by default. bool @@ -836,7 +836,7 @@ Whether to load and use the layout detection module. If not set, the parameter w layout_nms -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will default to the value initialized in the pipeline, which is set to True by default. +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If not set, the parameter will be set to the value initialized in the pipeline, which is set to True by default. bool @@ -1114,7 +1114,7 @@ In the above Python script, the following steps were executed: use_layout_detection -Whether to load and use the layout detection module. If set to None, the parameter will default to the value initialized in the pipeline, which is True. +Whether to load and use the layout detection module. If set to None, the parameter will be set to the value initialized in the pipeline, which is True by default. bool|None None @@ -1132,7 +1132,7 @@ In the above Python script, the following steps were executed: layout_nms -Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will default to the value initialized in the pipeline, which is set to True by default. +Whether to use Non-Maximum Suppression (NMS) as post-processing for layout detection. If set to None, the parameter will be set to the value initialized in the pipeline, which is set to True by default. bool|None None @@ -1660,26 +1660,6 @@ To remove the page limit, please add the following configuration to the pipeline No -visualize -boolean | null - -Whether to return the final visualization image and intermediate images during the processing.
              -
                -
              • If true is provided: return images.
              • -
              • If false is provided: do not return any images.
              • -
              • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
              • -
              -
              -For example, adding the following setting to the pipeline config file:
              -
              Serving:
              -  visualize: False
              -
              -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
              -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Please refer to the description of the use_doc_orientation_classify parameter of the pipeline object's predict method. @@ -1757,6 +1737,26 @@ If neither the request body nor the configuration file is set (If visualiz Please refer to the description of the seal_rec_score_thresh parameter of the pipeline object's predict method. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
              +
                +
              • If true is provided: return images.
              • +
              • If false is provided: do not return any images.
              • +
              • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
              • +
              +
              +For example, adding the following setting to the pipeline config file:
              +
              Serving:
              +  visualize: False
              +
              +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
              +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
                @@ -2360,7 +2360,7 @@ The pipeline configuration file not only contains the parameters supported by th 3. Load pipeline Configuration File in CLI -After modifying the configuration file, specify the path of the modified pipeline configuration file using the --paddlex_config parameter in the command line. PaddleOCR will read its contents as the pipeline configuration. Example: +After modifying the configuration file, specify the path of the modified pipeline configuration file using the `--paddlex_config` parameter in the command line. PaddleOCR will read its contents as the pipeline configuration. Example: ```bash paddleocr seal_recognition --paddlex_config SealRecognition.yaml ... @@ -2368,7 +2368,7 @@ paddleocr seal_recognition --paddlex_config SealRecognition.yaml ... 4. Load pipeline Configuration File in Python API -When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or configuration dictionary through the paddlex_config parameter. PaddleOCR will read its contents as the pipeline configuration. Example: +When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or configuration dictionary through the `paddlex_config` parameter. PaddleOCR will read its contents as the pipeline configuration. Example: ```python from paddleocr import SealRecognition diff --git a/docs/version3.x/pipeline_usage/seal_recognition.md b/docs/version3.x/pipeline_usage/seal_recognition.md index 0f1513e5a0..7a0b3cef50 100644 --- a/docs/version3.x/pipeline_usage/seal_recognition.md +++ b/docs/version3.x/pipeline_usage/seal_recognition.md @@ -807,39 +807,39 @@ paddleocr seal_recognition -i ./seal_text_det.png --device gpu use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_layout_detection -是否加载并使用版面检测模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面检测模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool layout_threshold -版面模型得分阈值。0-1 之间的任意浮点数。如果不设置,将默认使用产线初始化的该参数值,初始化为 0.5。 +版面模型得分阈值。0-1 之间的任意浮点数。如果不设置,将使用产线初始化的该参数值,默认初始化为 0.5float layout_nms -版面检测是否使用后处理NMS。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool layout_unclip_ratio 检测框的边长缩放倍数。 -大于0的浮点数,如 1.1 ,表示将模型输出的检测框中心不变,宽和高都扩张1.1倍如果不设置,将默认使用产线初始化的该参数值,初始化为1.0。 +大于0的浮点数,如 1.1 ,表示将模型输出的检测框中心不变,宽和高都扩张1.1倍如果不设置,将使用产线初始化的该参数值,默认初始化为1.0。 float @@ -851,7 +851,7 @@ paddleocr seal_recognition -i ./seal_text_det.png --device gpu
              • large,设置为large时,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留外部最大的框,删除重叠的内部框;
              • small,设置为small,表示在模型输出的检测框中,对于互相重叠包含的检测框,只保留内部被包含的小框,删除重叠的外部框;
              • union,不进行框的过滤处理,内外框都保留;
              • -
              如果不设置,将默认使用产线初始化的该参数值,初始化为large。 +
            如果不设置,将使用产线初始化的该参数值,默认初始化为largestr @@ -859,7 +859,7 @@ paddleocr seal_recognition -i ./seal_text_det.png --device gpu seal_det_limit_side_len 印章文本检测的图像边长限制。 -大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 736。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 736int @@ -867,7 +867,7 @@ paddleocr seal_recognition -i ./seal_text_det.png --device gpu seal_det_limit_type 印章文本检测的图像边长限制类型。 -支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 min。 +支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 minstr @@ -1101,19 +1101,19 @@ for res in output: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_layout_detection -是否加载并使用版面检测模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面检测模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1130,7 +1130,7 @@ for res in output: layout_nms -版面检测是否使用后处理NMS。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +版面检测是否使用后处理NMS。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1141,7 +1141,7 @@ for res in output:
          • float:任意大于 0 浮点数;
          • Tuple[float,float]:在横纵两个方向各自的扩张系数;
          • dict,dict的key为int类型,代表cls_id, value为tuple类型,如{0: (1.1, 2.0)},表示将模型输出的第0类别检测框中心不变,宽度扩张1.1倍,高度扩张2.0倍;
          • -
          • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 1.0
          • +
          • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 1.0
          float|Tuple[float,float]|dict|None @@ -1153,7 +1153,7 @@ for res in output:
          • strlargesmallunion,分别表示重叠框过滤时选择保留大框,小框还是同时保留;
          • dict: dict的key为int类型,代表cls_id,value为str类型,如{0: "large", 2: "small"},表示对第0类别检测框使用large模式,对第2类别检测框使用small模式;
          • -
          • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 large
          • +
          • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 large
          str|dict|None @@ -1164,7 +1164,7 @@ for res in output: 印章文本检测的图像边长限制。
          • int:大于 0 的任意整数;
          • -
          • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 736
          • +
          • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 736
          int|None @@ -1175,7 +1175,7 @@ for res in output: 印章文本检测的图像边长限制类型。
          • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
          • -
          • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 min
          • +
          • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 min
          str|None @@ -1654,23 +1654,6 @@ MKL-DNN 缓存容量。 否 -visualize -boolean | null -是否返回可视化结果图以及处理过程中的中间图像等。 -
            -
          • 传入 true:返回图像。
          • -
          • 传入 false:不返回图像。
          • -
          • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
          • -
          -
          例如,在产线配置文件中添加如下字段:
          -
          Serving:
          -  visualize: False
          -
          -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 - -否 - - useDocOrientationClassify boolean | null 请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 @@ -1748,6 +1731,23 @@ MKL-DNN 缓存容量。 请参阅产线对象中 predict 方法的 seal_rec_score_thresh 参数相关说明。 否 + +visualize +boolean | null +是否返回可视化结果图以及处理过程中的中间图像等。 +
            +
          • 传入 true:返回图像。
          • +
          • 传入 false:不返回图像。
          • +
          • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
          • +
          +
          例如,在产线配置文件中添加如下字段:
          +
          Serving:
          +  visualize: False
          +
          +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 + +否 +
            @@ -2351,7 +2351,7 @@ SubPipelines: 3. 在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash paddleocr seal_recognition --paddlex_config SealRecognition.yaml ... @@ -2359,7 +2359,7 @@ paddleocr seal_recognition --paddlex_config SealRecognition.yaml ... 4. 在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python from paddleocr import SealRecognition diff --git a/docs/version3.x/pipeline_usage/table_recognition_v2.en.md b/docs/version3.x/pipeline_usage/table_recognition_v2.en.md index 5842cfbf57..5d110cbcff 100644 --- a/docs/version3.x/pipeline_usage/table_recognition_v2.en.md +++ b/docs/version3.x/pipeline_usage/table_recognition_v2.en.md @@ -997,7 +997,7 @@ Local path to image files or PDF files: /root/data/img.jpg; as U text_det_limit_side_len Image side length limit for text detection. -Any integer greater than 0. If not set, the default value initialized by the pipeline will be used, initialized to 960. +Any integer greater than 0. If not set, the value initialized by the pipeline will be used, which defaults to 960. int @@ -1005,7 +1005,7 @@ Any integer greater than 0. If not set, the default value initializ text_det_limit_type Type of the image side length limit for text detection. -Supports min and max. min ensures that the shortest side of the image is not less than det_limit_side_len, while max ensures that the longest side of the image is not greater than limit_side_len. If not set, the default value initialized by the pipeline will be used, initialized to max. +Supports min and max. min ensures that the shortest side of the image is not less than det_limit_side_len, while max ensures that the longest side of the image is not greater than limit_side_len. If not set, the value initialized by the pipeline will be used, which defaults to max. str @@ -1013,7 +1013,7 @@ Supports min and max. min ensures that th text_det_thresh Detection pixel threshold. In the output probability map, only pixels with a score greater than this threshold will be considered text pixels. -Any floating-point number greater than 0. If not set, the default value initialized by the pipeline will be used, which is 0.3. +Any floating-point number greater than 0. If not set, the value initialized by the pipeline will be used, which defaults to 0.3. float @@ -1021,7 +1021,7 @@ Any floating-point number greater than 0. If not set, the default v text_det_box_thresh Detection box threshold. When the average score of all pixels within the detection result box is greater than this threshold, the result is considered a text area. -Any floating-point number greater than 0. If not set, the default value initialized by the pipeline will be used, which is 0.6. +Any floating-point number greater than 0. If not set, the value initialized by the pipeline will be used, which defaults to 0.6. float @@ -1029,7 +1029,7 @@ Any floating-point number greater than 0. If not set, the default v text_det_unclip_ratio Text detection expansion coefficient. This method expands the text area; the larger this value, the larger the expanded area. -Any floating-point number greater than 0. If not set, the default value initialized by the pipeline will be used, which is 2.0. +Any floating-point number greater than 0. If not set, the value initialized by the pipeline will be used, which defaults to 2.0. float @@ -1055,32 +1055,32 @@ Any floating-point number greater than 0. If not set, the default v text_rec_score_thresh Text recognition threshold. Text results with a score greater than this threshold will be retained. -Any floating-point number greater than 0. If not set, the default value initialized by the pipeline will be used, which is 0.0. That is, no threshold is set. +Any floating-point number greater than 0. If not set, the value initialized by the pipeline will be used, which defaults to 0.0. That is, no threshold is set. float use_doc_orientation_classify -Whether to load and use the document orientation classification module. If not set, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the document orientation classification module. If not set, the value initialized by the pipeline will be used, which defaults to True. bool use_doc_unwarping -Whether to load and use the text image unwarping module. If not set, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the text image unwarping module. If not set, the value initialized by the pipeline will be used, which defaults to True. bool use_layout_detection -Whether to load and use the layout detection module. If not set, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the layout detection module. If not set, the value initialized by the pipeline will be used, which defaults to True. bool use_ocr_model -Whether to load and use the OCR module. If not set, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the OCR module. If not set, the value initialized by the pipeline will be used, which defaults to True. bool @@ -1342,7 +1342,7 @@ In the above Python script, the following steps are performed: Image side length limit for text detection.
            • int: Any integer greater than 0;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, initialized to 960.
            • +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to 960.
            int|None @@ -1353,7 +1353,7 @@ In the above Python script, the following steps are performed: Type of the image side length limit for text detection.
            • str: Supports min and max. min ensures that the shortest side of the image is not less than det_limit_side_len, while max ensures that the longest side of the image is not greater than limit_side_len;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, initialized to max.
            • +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to max.
            str|None @@ -1364,7 +1364,7 @@ In the above Python script, the following steps are performed: Detection pixel threshold. In the output probability map, only pixels with a score greater than this threshold will be considered text pixels.
            • float: Any floating-point number greater than 0;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, which is 0.3.
            • +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to 0.3.
            float|None @@ -1375,7 +1375,7 @@ In the above Python script, the following steps are performed: Detection box threshold. When the average score of all pixels within the detection result box is greater than this threshold, the result is considered a text area.
            • float: Any floating-point number greater than 0;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, which is 0.6.
            • +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to 0.6.
            float|None @@ -1386,7 +1386,7 @@ In the above Python script, the following steps are performed: Text detection expansion coefficient. This method expands the text area; the larger this value, the larger the expanded area.
            • float: Any floating-point number greater than 0;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, which is 2.0.
            • +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to 2.0.
            float|None @@ -1415,7 +1415,7 @@ In the above Python script, the following steps are performed: Text recognition threshold. Text results with a score greater than this threshold will be retained.
            • float: Any floating-point number greater than 0;
            • -
            • None: If set to None, the default value initialized by the pipeline will be used, which is 0.0. That is, no threshold is set. +
            • None: If set to None, the value initialized by the pipeline will be used, which defaults to 0.0. That is, no threshold is set. float|None @@ -1423,25 +1423,25 @@ In the above Python script, the following steps are performed: use_doc_orientation_classify -Whether to load and use the document orientation classification module. If set to None, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the document orientation classification module. If set to None, the value initialized by the pipeline will be used, which defaults to True. bool|None None use_doc_unwarping -Whether to load and use the text image unwarping module. If set to None, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the text image unwarping module. If set to None, the value initialized by the pipeline will be used, which defaults to True. bool|None None use_layout_detection -Whether to load and use the layout detection module. If set to None, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the layout detection module. If set to None, the value initialized by the pipeline will be used, which defaults to True. bool|None None use_ocr_model -Whether to load and use the OCR module. If set to None, the default value initialized by the pipeline will be used, initialized to True. +Whether to load and use the OCR module. If set to None, the value initialized by the pipeline will be used, which defaults to True. bool|None None @@ -1911,26 +1911,6 @@ Below is the API reference for basic service-oriented deployment and examples of No -visualize -boolean | null - -Whether to return the final visualization image and intermediate images during the processing.
              -
                -
              • If true is provided: return images.
              • -
              • If false is provided: do not return any images.
              • -
              • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
              • -
              -
              -For example, adding the following setting to the pipeline config file:
              -
              Serving:
              -  visualize: False
              -
              -will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
              -If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. - -No - - useDocOrientationClassify boolean | null Please refer to the use_doc_orientation_classify parameter description in the predict method of the model object. @@ -2008,6 +1988,26 @@ If neither the request body nor the configuration file is set (If visualiz Please refer to the use_e2e_wireless_table_rec_model parameter description in the predict method of the model object. No + +visualize +boolean | null + +Whether to return the final visualization image and intermediate images during the processing.
              +
                +
              • If true is provided: return images.
              • +
              • If false is provided: do not return any images.
              • +
              • If this parameter is omitted from the request body, or if null is explicitly passed, the behavior will follow the value of Serving.visualize in the pipeline configuration.
              • +
              +
              +For example, adding the following setting to the pipeline config file:
              +
              Serving:
              +  visualize: False
              +
              +will disable image return by default. This behavior can be overridden by explicitly setting the visualize parameter in the request.
              +If neither the request body nor the configuration file is set (If visualize is set to null in the request and not defined in the configuration file), the image is returned by default. + +No +
                @@ -2681,7 +2681,7 @@ The pipeline configuration file includes not only the parameters supported by Pa 3. Loading the pipeline configuration file in CLI -After completing the configuration file modifications, specify the path to the modified pipeline configuration file using the --paddlex_config parameter in the command line. PaddleOCR will read its contents as the pipeline configuration. For example: +After completing the configuration file modifications, specify the path to the modified pipeline configuration file using the `--paddlex_config` parameter in the command line. PaddleOCR will read its contents as the pipeline configuration. For example: ```bash paddleocr table_recognition_v2_pipeline --paddlex_config PaddleOCR.yaml ... @@ -2689,7 +2689,7 @@ paddleocr table_recognition_v2_pipeline --paddlex_config PaddleOCR.yaml ... 4. Loading the pipeline configuration file in Python API -When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or configuration dictionary through the paddlex_config parameter. PaddleOCR will read its contents as the pipeline configuration. For example: +When initializing the pipeline object, you can pass the PaddleX pipeline configuration file path or configuration dictionary through the `paddlex_config` parameter. PaddleOCR will read its contents as the pipeline configuration. For example: ```python from paddleocr import TableRecognitionPipelineV2 diff --git a/docs/version3.x/pipeline_usage/table_recognition_v2.md b/docs/version3.x/pipeline_usage/table_recognition_v2.md index 063ae777a7..907de43889 100644 --- a/docs/version3.x/pipeline_usage/table_recognition_v2.md +++ b/docs/version3.x/pipeline_usage/table_recognition_v2.md @@ -999,7 +999,7 @@ paddleocr table_recognition_v2 -i ./table_recognition_v2.jpg --device gpu text_det_limit_side_len 文本检测的图像边长限制。 -大于 0 的任意整数。如果不设置,将默认使用产线初始化的该参数值,初始化为 960。 +大于 0 的任意整数。如果不设置,将使用产线初始化的该参数值,默认初始化为 960int @@ -1007,7 +1007,7 @@ paddleocr table_recognition_v2 -i ./table_recognition_v2.jpg --device gpu text_det_limit_type 文本检测的图像边长限制类型。 -支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将默认使用产线初始化的该参数值,初始化为 max。 +支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len。如果不设置,将使用产线初始化的该参数值,默认初始化为 maxstr @@ -1068,25 +1068,25 @@ paddleocr table_recognition_v2 -i ./table_recognition_v2.jpg --device gpu use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_doc_unwarping -是否加载并使用文本图像矫正模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_layout_detection -是否加载并使用版面检测模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面检测模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool use_ocr_model -是否加载并使用OCR模块。如果不设置,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用OCR模块。如果不设置,将使用产线初始化的该参数值,默认初始化为Truebool @@ -1348,7 +1348,7 @@ for res in output: 文本检测的图像边长限制。
                • int:大于 0 的任意整数;
                • -
                • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 960
                • +
                • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 960
                int|None @@ -1359,7 +1359,7 @@ for res in output: 文本检测的图像边长限制类型。
                • str:支持 minmaxmin 表示保证图像最短边不小于 det_limit_side_lenmax 表示保证图像最长边不大于 limit_side_len
                • -
                • None:如果设置为None,将默认使用产线初始化的该参数值,初始化为 max
                • +
                • None:如果设置为None,将使用产线初始化的该参数值,默认初始化为 max
                str|None @@ -1425,25 +1425,25 @@ for res in output: use_doc_orientation_classify -是否加载并使用文档方向分类模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文档方向分类模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_doc_unwarping -是否加载并使用文本图像矫正模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用文本图像矫正模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_layout_detection -是否加载并使用版面检测模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用版面检测模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None use_ocr_model -是否加载并使用OCR模块。如果设置为None,将默认使用产线初始化的该参数值,初始化为True。 +是否加载并使用OCR模块。如果设置为None,将使用产线初始化的该参数值,默认初始化为Truebool|None None @@ -1912,23 +1912,6 @@ MKL-DNN 缓存容量。 否 -visualize -boolean | null -是否返回可视化结果图以及处理过程中的中间图像等。 -
                  -
                • 传入 true:返回图像。
                • -
                • 传入 false:不返回图像。
                • -
                • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
                • -
                -
                例如,在产线配置文件中添加如下字段:
                -
                Serving:
                -  visualize: False
                -
                -将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 - -否 - - useDocOrientationClassify boolean | null 请参阅产线对象中 predict 方法的 use_doc_orientation_classify 参数相关说明。 @@ -2006,6 +1989,23 @@ MKL-DNN 缓存容量。 请参阅产线对象中 predict 方法的 use_e2e_wireless_table_rec_model 参数相关说明。 否 + +visualize +boolean | null +是否返回可视化结果图以及处理过程中的中间图像等。 +
                  +
                • 传入 true:返回图像。
                • +
                • 传入 false:不返回图像。
                • +
                • 若请求体中未提供该参数或传入 null:遵循产线配置文件Serving.visualize 的设置。
                • +
                +
                例如,在产线配置文件中添加如下字段:
                +
                Serving:
                +  visualize: False
                +
                +将默认不返回图像,通过请求体中的visualize参数可以覆盖默认行为。如果请求体和配置文件中均未设置(或请求体传入null、配置文件中未设置),则默认返回图像。 + +否 +
                  @@ -2680,7 +2680,7 @@ SubPipelines: 3.在 CLI 中加载产线配置文件 -在修改完成配置文件后,通过命令行的 --paddlex_config 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +在修改完成配置文件后,通过命令行的 `--paddlex_config` 参数指定修改后的产线配置文件的路径,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```bash paddleocr table_recognition_v2_pipeline --paddlex_config PaddleOCR.yaml ... @@ -2688,7 +2688,7 @@ paddleocr table_recognition_v2_pipeline --paddlex_config PaddleOCR.yaml ... 4.在 Python API 中加载产线配置文件 -初始化产线对象时,可通过 paddlex_config 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: +初始化产线对象时,可通过 `paddlex_config` 参数传入 PaddleX 产线配置文件路径或配置dict,PaddleOCR 会读取其中的内容作为产线配置。示例如下: ```python from paddleocr import TableRecognitionPipelineV2 diff --git a/mkdocs.yml b/mkdocs.yml index 1157478d74..9e237574dc 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -303,6 +303,7 @@ nav: - 文档理解产线: version3.x/pipeline_usage/doc_understanding.md - 印章文本识别产线: version3.x/pipeline_usage/seal_recognition.md - 通用表格识别v2产线: version3.x/pipeline_usage/table_recognition_v2.md + - PP-DocTranslation产线: version3.x/pipeline_usage/PP-DocTranslation.md - 多硬件使用: - PaddleOCR 多硬件使用指南: version3.x/other_devices_support/multi_devices_use_guide.md - 昇腾 NPU 飞桨安装教程: version3.x/other_devices_support/paddlepaddle_install_NPU.md diff --git a/paddleocr/__init__.py b/paddleocr/__init__.py index bd9280d970..320c4a896a 100644 --- a/paddleocr/__init__.py +++ b/paddleocr/__init__.py @@ -32,6 +32,7 @@ from ._pipelines import ( FormulaRecognitionPipeline, PaddleOCR, PPChatOCRv4Doc, + PPDocTranslation, PPStructureV3, SealRecognition, TableRecognitionPipelineV2, @@ -57,6 +58,7 @@ __all__ = [ "FormulaRecognitionPipeline", "PaddleOCR", "PPChatOCRv4Doc", + "PPDocTranslation", "PPStructureV3", "SealRecognition", "TableRecognitionPipelineV2", diff --git a/paddleocr/_cli.py b/paddleocr/_cli.py index aedbc87aa0..d291183a5c 100644 --- a/paddleocr/_cli.py +++ b/paddleocr/_cli.py @@ -38,6 +38,7 @@ from ._pipelines import ( FormulaRecognitionPipeline, PaddleOCR, PPChatOCRv4Doc, + PPDocTranslation, PPStructureV3, SealRecognition, TableRecognitionPipelineV2, @@ -54,6 +55,7 @@ def _register_pipelines(subparsers): FormulaRecognitionPipeline, PaddleOCR, PPChatOCRv4Doc, + PPDocTranslation, PPStructureV3, SealRecognition, TableRecognitionPipelineV2, diff --git a/paddleocr/_pipelines/__init__.py b/paddleocr/_pipelines/__init__.py index d0fec91926..b23a633c7f 100644 --- a/paddleocr/_pipelines/__init__.py +++ b/paddleocr/_pipelines/__init__.py @@ -17,6 +17,7 @@ from .doc_understanding import DocUnderstanding from .formula_recognition import FormulaRecognitionPipeline from .ocr import PaddleOCR from .pp_chatocrv4_doc import PPChatOCRv4Doc +from .pp_doctranslation import PPDocTranslation from .pp_structurev3 import PPStructureV3 from .seal_recognition import SealRecognition from .table_recognition_v2 import TableRecognitionPipelineV2 @@ -27,6 +28,7 @@ __all__ = [ "FormulaRecognitionPipeline", "PaddleOCR", "PPChatOCRv4Doc", + "PPDocTranslation", "PPStructureV3", "SealRecognition", "TableRecognitionPipelineV2", diff --git a/paddleocr/_pipelines/pp_chatocrv4_doc.py b/paddleocr/_pipelines/pp_chatocrv4_doc.py index b53725e59f..69819e6838 100644 --- a/paddleocr/_pipelines/pp_chatocrv4_doc.py +++ b/paddleocr/_pipelines/pp_chatocrv4_doc.py @@ -422,9 +422,9 @@ class PPChatOCRv4DocCLISubcommandExecutor(PipelineCLISubcommandExecutor): subparser.add_argument( "--save_path", type=str, - default="output", help="Path to the output directory.", ) + subparser.add_argument( "--invoke_mllm", type=str2bool, @@ -693,7 +693,7 @@ class PPChatOCRv4DocCLISubcommandExecutor(PipelineCLISubcommandExecutor): chatocr = PPChatOCRv4Doc(**params) - result_visual = chatocr.visual_predict(input) + result_visual = chatocr.visual_predict_iter(input) visual_info_list = [] for res in result_visual: diff --git a/paddleocr/_pipelines/pp_doctranslation.py b/paddleocr/_pipelines/pp_doctranslation.py new file mode 100644 index 0000000000..b51df66f90 --- /dev/null +++ b/paddleocr/_pipelines/pp_doctranslation.py @@ -0,0 +1,936 @@ +# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .._utils.cli import ( + get_subcommand_args, + str2bool, +) +from .._utils.logging import logger +from .base import PaddleXPipelineWrapper, PipelineCLISubcommandExecutor +from .utils import create_config_from_structure + + +class PPDocTranslation(PaddleXPipelineWrapper): + def __init__( + self, + layout_detection_model_name=None, + layout_detection_model_dir=None, + layout_threshold=None, + layout_nms=None, + layout_unclip_ratio=None, + layout_merge_bboxes_mode=None, + chart_recognition_model_name=None, + chart_recognition_model_dir=None, + chart_recognition_batch_size=None, + region_detection_model_name=None, + region_detection_model_dir=None, + doc_orientation_classify_model_name=None, + doc_orientation_classify_model_dir=None, + doc_unwarping_model_name=None, + doc_unwarping_model_dir=None, + text_detection_model_name=None, + text_detection_model_dir=None, + text_det_limit_side_len=None, + text_det_limit_type=None, + text_det_thresh=None, + text_det_box_thresh=None, + text_det_unclip_ratio=None, + textline_orientation_model_name=None, + textline_orientation_model_dir=None, + textline_orientation_batch_size=None, + text_recognition_model_name=None, + text_recognition_model_dir=None, + text_recognition_batch_size=None, + text_rec_score_thresh=None, + table_classification_model_name=None, + table_classification_model_dir=None, + wired_table_structure_recognition_model_name=None, + wired_table_structure_recognition_model_dir=None, + wireless_table_structure_recognition_model_name=None, + wireless_table_structure_recognition_model_dir=None, + wired_table_cells_detection_model_name=None, + wired_table_cells_detection_model_dir=None, + wireless_table_cells_detection_model_name=None, + wireless_table_cells_detection_model_dir=None, + table_orientation_classify_model_name=None, + table_orientation_classify_model_dir=None, + seal_text_detection_model_name=None, + seal_text_detection_model_dir=None, + seal_det_limit_side_len=None, + seal_det_limit_type=None, + seal_det_thresh=None, + seal_det_box_thresh=None, + seal_det_unclip_ratio=None, + seal_text_recognition_model_name=None, + seal_text_recognition_model_dir=None, + seal_text_recognition_batch_size=None, + seal_rec_score_thresh=None, + formula_recognition_model_name=None, + formula_recognition_model_dir=None, + formula_recognition_batch_size=None, + use_doc_orientation_classify=None, + use_doc_unwarping=None, + use_textline_orientation=None, + use_seal_recognition=None, + use_table_recognition=None, + use_formula_recognition=None, + use_chart_recognition=None, + use_region_detection=None, + chat_bot_config=None, + **kwargs, + ): + params = locals().copy() + params.pop("self") + params.pop("kwargs") + self._params = params + + super().__init__(**kwargs) + + @property + def _paddlex_pipeline_name(self): + return "PP-DocTranslation" + + def visual_predict_iter( + self, + input, + *, + use_doc_orientation_classify=False, + use_doc_unwarping=False, + use_textline_orientation=None, + use_seal_recognition=None, + use_table_recognition=None, + use_formula_recognition=None, + use_chart_recognition=False, + use_region_detection=None, + layout_threshold=None, + layout_nms=None, + layout_unclip_ratio=None, + layout_merge_bboxes_mode=None, + text_det_limit_side_len=None, + text_det_limit_type=None, + text_det_thresh=None, + text_det_box_thresh=None, + text_det_unclip_ratio=None, + text_rec_score_thresh=None, + seal_det_limit_side_len=None, + seal_det_limit_type=None, + seal_det_thresh=None, + seal_det_box_thresh=None, + seal_det_unclip_ratio=None, + seal_rec_score_thresh=None, + use_wired_table_cells_trans_to_html=False, + use_wireless_table_cells_trans_to_html=False, + use_table_orientation_classify=True, + use_ocr_results_with_table_cells=True, + use_e2e_wired_table_rec_model=False, + use_e2e_wireless_table_rec_model=True, + **kwargs, + ): + return self.paddlex_pipeline.visual_predict( + input, + use_doc_orientation_classify=use_doc_orientation_classify, + use_doc_unwarping=use_doc_unwarping, + use_textline_orientation=use_textline_orientation, + use_seal_recognition=use_seal_recognition, + use_table_recognition=use_table_recognition, + use_formula_recognition=use_formula_recognition, + use_chart_recognition=use_chart_recognition, + use_region_detection=use_region_detection, + layout_threshold=layout_threshold, + layout_nms=layout_nms, + layout_unclip_ratio=layout_unclip_ratio, + layout_merge_bboxes_mode=layout_merge_bboxes_mode, + text_det_limit_side_len=text_det_limit_side_len, + text_det_limit_type=text_det_limit_type, + text_det_thresh=text_det_thresh, + text_det_box_thresh=text_det_box_thresh, + text_det_unclip_ratio=text_det_unclip_ratio, + text_rec_score_thresh=text_rec_score_thresh, + seal_det_limit_side_len=seal_det_limit_side_len, + seal_det_limit_type=seal_det_limit_type, + seal_det_thresh=seal_det_thresh, + seal_det_box_thresh=seal_det_box_thresh, + seal_det_unclip_ratio=seal_det_unclip_ratio, + seal_rec_score_thresh=seal_rec_score_thresh, + use_wired_table_cells_trans_to_html=use_wired_table_cells_trans_to_html, + use_wireless_table_cells_trans_to_html=use_wireless_table_cells_trans_to_html, + use_table_orientation_classify=use_table_orientation_classify, + use_ocr_results_with_table_cells=use_ocr_results_with_table_cells, + use_e2e_wired_table_rec_model=use_e2e_wired_table_rec_model, + use_e2e_wireless_table_rec_model=use_e2e_wireless_table_rec_model, + **kwargs, + ) + + def visual_predict( + self, + input, + *, + use_doc_orientation_classify=False, + use_doc_unwarping=False, + use_textline_orientation=None, + use_seal_recognition=None, + use_table_recognition=None, + use_formula_recognition=None, + use_chart_recognition=False, + use_region_detection=None, + layout_threshold=None, + layout_nms=None, + layout_unclip_ratio=None, + layout_merge_bboxes_mode=None, + text_det_limit_side_len=None, + text_det_limit_type=None, + text_det_thresh=None, + text_det_box_thresh=None, + text_det_unclip_ratio=None, + text_rec_score_thresh=None, + seal_det_limit_side_len=None, + seal_det_limit_type=None, + seal_det_thresh=None, + seal_det_box_thresh=None, + seal_det_unclip_ratio=None, + seal_rec_score_thresh=None, + use_wired_table_cells_trans_to_html=False, + use_wireless_table_cells_trans_to_html=False, + use_table_orientation_classify=True, + use_ocr_results_with_table_cells=True, + use_e2e_wired_table_rec_model=False, + use_e2e_wireless_table_rec_model=True, + **kwargs, + ): + return list( + self.visual_predict_iter( + input, + use_doc_orientation_classify=use_doc_orientation_classify, + use_doc_unwarping=use_doc_unwarping, + use_textline_orientation=use_textline_orientation, + use_seal_recognition=use_seal_recognition, + use_table_recognition=use_table_recognition, + use_formula_recognition=use_formula_recognition, + use_chart_recognition=use_chart_recognition, + use_region_detection=use_region_detection, + layout_threshold=layout_threshold, + layout_nms=layout_nms, + layout_unclip_ratio=layout_unclip_ratio, + layout_merge_bboxes_mode=layout_merge_bboxes_mode, + text_det_limit_side_len=text_det_limit_side_len, + text_det_limit_type=text_det_limit_type, + text_det_thresh=text_det_thresh, + text_det_box_thresh=text_det_box_thresh, + text_det_unclip_ratio=text_det_unclip_ratio, + text_rec_score_thresh=text_rec_score_thresh, + seal_det_limit_side_len=seal_det_limit_side_len, + seal_det_limit_type=seal_det_limit_type, + seal_det_thresh=seal_det_thresh, + seal_det_box_thresh=seal_det_box_thresh, + seal_det_unclip_ratio=seal_det_unclip_ratio, + seal_rec_score_thresh=seal_rec_score_thresh, + use_wired_table_cells_trans_to_html=use_wired_table_cells_trans_to_html, + use_wireless_table_cells_trans_to_html=use_wireless_table_cells_trans_to_html, + use_table_orientation_classify=use_table_orientation_classify, + use_ocr_results_with_table_cells=use_ocr_results_with_table_cells, + use_e2e_wired_table_rec_model=use_e2e_wired_table_rec_model, + use_e2e_wireless_table_rec_model=use_e2e_wireless_table_rec_model, + **kwargs, + ) + ) + + def translate_iter( + self, + ori_md_info_list, + *, + target_language="zh", + chunk_size=5000, + task_description=None, + output_format=None, + rules_str=None, + few_shot_demo_text_content=None, + few_shot_demo_key_value_list=None, + chat_bot_config=None, + **kwargs, + ): + return self.paddlex_pipeline.translate( + ori_md_info_list, + target_language=target_language, + chunk_size=chunk_size, + task_description=task_description, + output_format=output_format, + rules_str=rules_str, + few_shot_demo_text_content=few_shot_demo_text_content, + few_shot_demo_key_value_list=few_shot_demo_key_value_list, + chat_bot_config=chat_bot_config, + **kwargs, + ) + + def translate( + self, + ori_md_info_list, + *, + target_language="zh", + chunk_size=5000, + task_description=None, + output_format=None, + rules_str=None, + few_shot_demo_text_content=None, + few_shot_demo_key_value_list=None, + chat_bot_config=None, + **kwargs, + ): + return list( + self.translate_iter( + ori_md_info_list, + target_language=target_language, + chunk_size=chunk_size, + task_description=task_description, + output_format=output_format, + rules_str=rules_str, + few_shot_demo_text_content=few_shot_demo_text_content, + few_shot_demo_key_value_list=few_shot_demo_key_value_list, + chat_bot_config=chat_bot_config, + **kwargs, + ) + ) + + def load_from_markdown(self, input): + return self.paddlex_pipeline.load_from_markdown(input) + + def concatenate_markdown_pages(self, markdown_list): + return self.paddlex_pipeline.concatenate_markdown_pages(markdown_list) + + @classmethod + def get_cli_subcommand_executor(cls): + return PPDocTranslationCLISubcommandExecutor() + + def _get_paddlex_config_overrides(self): + # HACK: We should consider reducing duplication. + STRUCTURE = { + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.use_doc_orientation_classify": self._params[ + "use_doc_orientation_classify" + ], + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.use_doc_unwarping": self._params[ + "use_doc_unwarping" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.use_textline_orientation": self._params[ + "use_textline_orientation" + ], + "SubPipelines.LayoutParser.use_seal_recognition": self._params[ + "use_seal_recognition" + ], + "SubPipelines.LayoutParser.use_table_recognition": self._params[ + "use_table_recognition" + ], + "SubPipelines.LayoutParser.use_formula_recognition": self._params[ + "use_formula_recognition" + ], + "SubPipelines.LayoutParser.use_chart_recognition": self._params[ + "use_chart_recognition" + ], + "SubPipelines.LayoutParser.use_region_detection": self._params[ + "use_region_detection" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.model_name": self._params[ + "layout_detection_model_name" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.model_dir": self._params[ + "layout_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.threshold": self._params[ + "layout_threshold" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.layout_nms": self._params[ + "layout_nms" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.layout_unclip_ratio": self._params[ + "layout_unclip_ratio" + ], + "SubPipelines.LayoutParser.SubModules.LayoutDetection.layout_merge_bboxes_mode": self._params[ + "layout_merge_bboxes_mode" + ], + "SubPipelines.LayoutParser.SubModules.ChartRecognition.model_name": self._params[ + "chart_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubModules.ChartRecognition.model_dir": self._params[ + "chart_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubModules.ChartRecognition.batch_size": self._params[ + "chart_recognition_batch_size" + ], + "SubPipelines.LayoutParser.SubModules.RegionDetection.model_name": self._params[ + "region_detection_model_name" + ], + "SubPipelines.LayoutParser.SubModules.RegionDetection.model_dir": self._params[ + "region_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_name": self._params[ + "doc_orientation_classify_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_dir": self._params[ + "doc_orientation_classify_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_name": self._params[ + "doc_unwarping_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_dir": self._params[ + "doc_unwarping_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.model_name": self._params[ + "text_detection_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.model_dir": self._params[ + "text_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.limit_side_len": self._params[ + "text_det_limit_side_len" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.limit_type": self._params[ + "text_det_limit_type" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.thresh": self._params[ + "text_det_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.box_thresh": self._params[ + "text_det_box_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextDetection.unclip_ratio": self._params[ + "text_det_unclip_ratio" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.model_name": self._params[ + "textline_orientation_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.model_dir": self._params[ + "textline_orientation_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.batch_size": self._params[ + "textline_orientation_batch_size" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextRecognition.model_name": self._params[ + "text_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextRecognition.model_dir": self._params[ + "text_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextRecognition.batch_size": self._params[ + "text_recognition_batch_size" + ], + "SubPipelines.LayoutParser.SubPipelines.GeneralOCR.SubModules.TextRecognition.score_thresh": self._params[ + "text_rec_score_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.TableClassification.model_name": self._params[ + "table_classification_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.TableClassification.model_dir": self._params[ + "table_classification_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WiredTableStructureRecognition.model_name": self._params[ + "wired_table_structure_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WiredTableStructureRecognition.model_dir": self._params[ + "wired_table_structure_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WirelessTableStructureRecognition.model_name": self._params[ + "wireless_table_structure_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WirelessTableStructureRecognition.model_dir": self._params[ + "wireless_table_structure_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WiredTableCellsDetection.model_name": self._params[ + "wired_table_cells_detection_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WiredTableCellsDetection.model_dir": self._params[ + "wired_table_cells_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WirelessTableCellsDetection.model_name": self._params[ + "wireless_table_cells_detection_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.WirelessTableCellsDetection.model_dir": self._params[ + "wireless_table_cells_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.TableOrientationClassify.model_name": self._params[ + "table_orientation_classify_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubModules.TableOrientationClassify.model_dir": self._params[ + "table_orientation_classify_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.model_name": self._params[ + "text_detection_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.model_dir": self._params[ + "text_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.limit_side_len": self._params[ + "text_det_limit_side_len" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.limit_type": self._params[ + "text_det_limit_type" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.thresh": self._params[ + "text_det_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.box_thresh": self._params[ + "text_det_box_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextDetection.unclip_ratio": self._params[ + "text_det_unclip_ratio" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.model_name": self._params[ + "textline_orientation_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.model_dir": self._params[ + "textline_orientation_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextLineOrientation.batch_size": self._params[ + "textline_orientation_batch_size" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextRecognition.model_name": self._params[ + "text_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextRecognition.model_dir": self._params[ + "text_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextRecognition.batch_size": self._params[ + "text_recognition_batch_size" + ], + "SubPipelines.LayoutParser.SubPipelines.TableRecognition.SubPipelines.GeneralOCR.SubModules.TextRecognition.score_thresh": self._params[ + "text_rec_score_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.model_name": self._params[ + "seal_text_detection_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.model_dir": self._params[ + "seal_text_detection_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.limit_side_len": self._params[ + "text_det_limit_side_len" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.limit_type": self._params[ + "seal_det_limit_type" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.thresh": self._params[ + "seal_det_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.box_thresh": self._params[ + "seal_det_box_thresh" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextDetection.unclip_ratio": self._params[ + "seal_det_unclip_ratio" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextRecognition.model_name": self._params[ + "seal_text_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextRecognition.model_dir": self._params[ + "seal_text_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.SealRecognition.SubPipelines.SealOCR.SubModules.TextRecognition.batch_size": self._params[ + "seal_text_recognition_batch_size" + ], + "SubPipelines.LayoutParser.SubPipelines.FormulaRecognition.SubModules.FormulaRecognition.model_name": self._params[ + "formula_recognition_model_name" + ], + "SubPipelines.LayoutParser.SubPipelines.FormulaRecognition.SubModules.FormulaRecognition.model_dir": self._params[ + "formula_recognition_model_dir" + ], + "SubPipelines.LayoutParser.SubPipelines.FormulaRecognition.SubModules.FormulaRecognition.batch_size": self._params[ + "formula_recognition_batch_size" + ], + "SubModules.LLM_Chat": self._params["chat_bot_config"], + } + return create_config_from_structure(STRUCTURE) + + +class PPDocTranslationCLISubcommandExecutor(PipelineCLISubcommandExecutor): + @property + def subparser_name(self): + return "pp_doctranslation" + + def _update_subparser(self, subparser): + subparser.add_argument( + "-i", + "--input", + type=str, + required=True, + help="Input path or URL.", + ) + subparser.add_argument( + "--save_path", + type=str, + help="Path to the output directory.", + ) + + subparser.add_argument( + "--target_language", + type=str, + default="zh", + help="Target language.", + ) + + subparser.add_argument( + "--layout_detection_model_name", + type=str, + help="Name of the layout detection model.", + ) + subparser.add_argument( + "--layout_detection_model_dir", + type=str, + help="Path to the layout detection model directory.", + ) + subparser.add_argument( + "--layout_threshold", + type=float, + help="Score threshold for the layout detection model.", + ) + subparser.add_argument( + "--layout_nms", + type=str2bool, + help="Whether to use NMS in layout detection.", + ) + subparser.add_argument( + "--layout_unclip_ratio", + type=float, + help="Expansion coefficient for layout detection.", + ) + subparser.add_argument( + "--layout_merge_bboxes_mode", + type=str, + help="Overlapping box filtering method.", + ) + + subparser.add_argument( + "--chart_recognition_model_name", + type=str, + help="Name of the chart recognition model.", + ) + subparser.add_argument( + "--chart_recognition_model_dir", + type=str, + help="Path to the chart recognition model directory.", + ) + subparser.add_argument( + "--chart_recognition_batch_size", + type=int, + help="Batch size for the chart recognition model.", + ) + + subparser.add_argument( + "--region_detection_model_name", + type=str, + help="Name of the region detection model.", + ) + subparser.add_argument( + "--region_detection_model_dir", + type=str, + help="Path to the region detection model directory.", + ) + + subparser.add_argument( + "--doc_orientation_classify_model_name", + type=str, + help="Name of the document image orientation classification model.", + ) + subparser.add_argument( + "--doc_orientation_classify_model_dir", + type=str, + help="Path to the document image orientation classification model directory.", + ) + subparser.add_argument( + "--doc_unwarping_model_name", + type=str, + help="Name of the text image unwarping model.", + ) + subparser.add_argument( + "--doc_unwarping_model_dir", + type=str, + help="Path to the image unwarping model directory.", + ) + + subparser.add_argument( + "--text_detection_model_name", + type=str, + help="Name of the text detection model.", + ) + subparser.add_argument( + "--text_detection_model_dir", + type=str, + help="Path to the text detection model directory.", + ) + subparser.add_argument( + "--text_det_limit_side_len", + type=int, + help="This sets a limit on the side length of the input image for the text detection model.", + ) + subparser.add_argument( + "--text_det_limit_type", + type=str, + help="This determines how the side length limit is applied to the input image before feeding it into the text deteciton model.", + ) + subparser.add_argument( + "--text_det_thresh", + type=float, + help="Detection pixel threshold for the text detection model. Pixels with scores greater than this threshold in the output probability map are considered text pixels.", + ) + subparser.add_argument( + "--text_det_box_thresh", + type=float, + help="Detection box threshold for the text detection model. A detection result is considered a text region if the average score of all pixels within the border of the result is greater than this threshold.", + ) + subparser.add_argument( + "--text_det_unclip_ratio", + type=float, + help="Text detection expansion coefficient, which expands the text region using this method. The larger the value, the larger the expansion area.", + ) + subparser.add_argument( + "--textline_orientation_model_name", + type=str, + help="Name of the text line orientation classification model.", + ) + subparser.add_argument( + "--textline_orientation_model_dir", + type=str, + help="Path to the text line orientation classification directory.", + ) + subparser.add_argument( + "--textline_orientation_batch_size", + type=int, + help="Batch size for the text line orientation classification model.", + ) + subparser.add_argument( + "--text_recognition_model_name", + type=str, + help="Name of the text recognition model.", + ) + subparser.add_argument( + "--text_recognition_model_dir", + type=str, + help="Path to the text recognition model directory.", + ) + subparser.add_argument( + "--text_recognition_batch_size", + type=int, + help="Batch size for the text recognition model.", + ) + subparser.add_argument( + "--text_rec_score_thresh", + type=float, + help="Text recognition threshold used in general OCR. Text results with scores greater than this threshold are retained.", + ) + + subparser.add_argument( + "--table_classification_model_name", + type=str, + help="Name of the table classification model.", + ) + subparser.add_argument( + "--table_classification_model_dir", + type=str, + help="Path to the table classification model directory.", + ) + subparser.add_argument( + "--wired_table_structure_recognition_model_name", + type=str, + help="Name of the wired table structure recognition model.", + ) + subparser.add_argument( + "--wired_table_structure_recognition_model_dir", + type=str, + help="Path to the wired table structure recognition model directory.", + ) + subparser.add_argument( + "--wireless_table_structure_recognition_model_name", + type=str, + help="Name of the wireless table structure recognition model.", + ) + subparser.add_argument( + "--wireless_table_structure_recognition_model_dir", + type=str, + help="Path to the wired table structure recognition model directory.", + ) + subparser.add_argument( + "--wired_table_cells_detection_model_name", + type=str, + help="Name of the wired table cells detection model.", + ) + subparser.add_argument( + "--wired_table_cells_detection_model_dir", + type=str, + help="Path to the wired table cells detection model directory.", + ) + subparser.add_argument( + "--wireless_table_cells_detection_model_name", + type=str, + help="Name of the wireless table cells detection model.", + ) + subparser.add_argument( + "--wireless_table_cells_detection_model_dir", + type=str, + help="Path to the wireless table cells detection model directory.", + ) + + subparser.add_argument( + "--seal_text_detection_model_name", + type=str, + help="Name of the seal text detection model.", + ) + subparser.add_argument( + "--seal_text_detection_model_dir", + type=str, + help="Path to the seal text detection model directory.", + ) + subparser.add_argument( + "--seal_det_limit_side_len", + type=int, + help="This sets a limit on the side length of the input image for the seal text detection model.", + ) + subparser.add_argument( + "--seal_det_limit_type", + type=str, + help="This determines how the side length limit is applied to the input image before feeding it into the seal text deteciton model.", + ) + subparser.add_argument( + "--seal_det_thresh", + type=float, + help="Detection pixel threshold for the seal text detection model. Pixels with scores greater than this threshold in the output probability map are considered text pixels.", + ) + subparser.add_argument( + "--seal_det_box_thresh", + type=float, + help="Detection box threshold for the seal text detection model. A detection result is considered a text region if the average score of all pixels within the border of the result is greater than this threshold.", + ) + subparser.add_argument( + "--seal_det_unclip_ratio", + type=float, + help="Seal text detection expansion coefficient, which expands the text region using this method. The larger the value, the larger the expansion area.", + ) + subparser.add_argument( + "--seal_text_recognition_model_name", + type=str, + help="Name of the seal text recognition model.", + ) + subparser.add_argument( + "--seal_text_recognition_model_dir", + type=str, + help="Path to the seal text recognition model directory.", + ) + subparser.add_argument( + "--seal_text_recognition_batch_size", + type=int, + help="Batch size for the seal text recognition model.", + ) + subparser.add_argument( + "--seal_rec_score_thresh", + type=float, + help="Seal text recognition threshold. Text results with scores greater than this threshold are retained.", + ) + + subparser.add_argument( + "--formula_recognition_model_name", + type=str, + help="Name of the formula recognition model.", + ) + subparser.add_argument( + "--formula_recognition_model_dir", + type=str, + help="Path to the formula recognition model directory.", + ) + subparser.add_argument( + "--formula_recognition_batch_size", + type=int, + help="Batch size for the formula recognition model.", + ) + + subparser.add_argument( + "--use_doc_orientation_classify", + type=str2bool, + default=False, + help="Whether to use document image orientation classification.", + ) + subparser.add_argument( + "--use_doc_unwarping", + type=str2bool, + default=False, + help="Whether to use text image unwarping.", + ) + subparser.add_argument( + "--use_textline_orientation", + type=str2bool, + help="Whether to use text line orientation classification.", + ) + subparser.add_argument( + "--use_seal_recognition", + type=str2bool, + help="Whether to use seal recognition.", + ) + subparser.add_argument( + "--use_table_recognition", + type=str2bool, + help="Whether to use table recognition.", + ) + subparser.add_argument( + "--use_formula_recognition", + type=str2bool, + help="Whether to use formula recognition.", + ) + subparser.add_argument( + "--use_chart_recognition", + type=str2bool, + default=False, + help="Whether to use chart recognition.", + ) + subparser.add_argument( + "--use_region_detection", + type=str2bool, + help="Whether to use region detection.", + ) + + # FIXME: Passing API key through CLI is not secure; consider using + # environment variables. + subparser.add_argument( + "--qianfan_api_key", + type=str, + help="Configuration for the embedding model.", + ) + + def execute_with_args(self, args): + params = get_subcommand_args(args) + input = params.pop("input") + target_language = params.pop("target_language") + save_path = params.pop("save_path") + qianfan_api_key = params.pop("qianfan_api_key") + if qianfan_api_key is not None: + params["chat_bot_config"] = { + "module_name": "chat_bot", + "model_name": "ernie-3.5-8k", + "base_url": "https://qianfan.baidubce.com/v2", + "api_type": "openai", + "api_key": qianfan_api_key, + } + + chatocr = PPDocTranslation(**params) + + logger.info("Start analyzing images") + result_visual = chatocr.visual_predict_iter(input) + + ori_md_info_list = [] + for res in result_visual: + ori_md_info_list.append(res["layout_parsing_result"].markdown) + if save_path: + res["layout_parsing_result"].save_all(save_path) + + logger.info("Start translation") + result_translate = chatocr.translate_iter( + ori_md_info_list, + target_language=target_language, + ) + + for res in result_translate: + res.print() + if save_path: + res.save_to_markdown(save_path) diff --git a/paddleocr/_pipelines/pp_structurev3.py b/paddleocr/_pipelines/pp_structurev3.py index c9cd4c6ef4..b591355ec5 100644 --- a/paddleocr/_pipelines/pp_structurev3.py +++ b/paddleocr/_pipelines/pp_structurev3.py @@ -104,6 +104,7 @@ class PPStructureV3(PaddleXPipelineWrapper): def predict_iter( self, input, + *, use_doc_orientation_classify=False, use_doc_unwarping=False, use_textline_orientation=None, @@ -174,6 +175,7 @@ class PPStructureV3(PaddleXPipelineWrapper): def predict( self, input, + *, use_doc_orientation_classify=False, use_doc_unwarping=False, use_textline_orientation=None, diff --git a/paddleocr/_pipelines/table_recognition_v2.py b/paddleocr/_pipelines/table_recognition_v2.py index 5a1f24b50b..ebf1c8b8e4 100644 --- a/paddleocr/_pipelines/table_recognition_v2.py +++ b/paddleocr/_pipelines/table_recognition_v2.py @@ -72,6 +72,7 @@ class TableRecognitionPipelineV2(PaddleXPipelineWrapper): def predict_iter( self, input, + *, use_doc_orientation_classify=None, use_doc_unwarping=None, use_layout_detection=None, @@ -118,6 +119,7 @@ class TableRecognitionPipelineV2(PaddleXPipelineWrapper): def predict( self, input, + *, use_doc_orientation_classify=None, use_doc_unwarping=None, use_layout_detection=None, diff --git a/pyproject.toml b/pyproject.toml index 67ec9a49ed..d4624571da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ classifiers = [ "Topic :: Utilities", ] dependencies = [ - "paddlex[ocr,ie,multimodal]>=3.0.3", + "paddlex[ocr,ie,multimodal,trans]>=3.1.0", "PyYAML>=6", "typing-extensions>=4.12", ] diff --git a/tests/predictors/__init__.py b/tests/models/__init__.py similarity index 100% rename from tests/predictors/__init__.py rename to tests/models/__init__.py diff --git a/tests/predictors/image_classification_common.py b/tests/models/image_classification_common.py similarity index 100% rename from tests/predictors/image_classification_common.py rename to tests/models/image_classification_common.py diff --git a/tests/predictors/object_detection_common.py b/tests/models/object_detection_common.py similarity index 100% rename from tests/predictors/object_detection_common.py rename to tests/models/object_detection_common.py diff --git a/tests/predictors/test_doc_img_orientation_classifcation.py b/tests/models/test_doc_img_orientation_classifcation.py similarity index 100% rename from tests/predictors/test_doc_img_orientation_classifcation.py rename to tests/models/test_doc_img_orientation_classifcation.py diff --git a/tests/predictors/test_doc_vlm.py b/tests/models/test_doc_vlm.py similarity index 100% rename from tests/predictors/test_doc_vlm.py rename to tests/models/test_doc_vlm.py diff --git a/tests/predictors/test_formula_recognition.py b/tests/models/test_formula_recognition.py similarity index 100% rename from tests/predictors/test_formula_recognition.py rename to tests/models/test_formula_recognition.py diff --git a/tests/predictors/test_layout_detection.py b/tests/models/test_layout_detection.py similarity index 100% rename from tests/predictors/test_layout_detection.py rename to tests/models/test_layout_detection.py diff --git a/tests/predictors/test_seal_text_detection.py b/tests/models/test_seal_text_detection.py similarity index 100% rename from tests/predictors/test_seal_text_detection.py rename to tests/models/test_seal_text_detection.py diff --git a/tests/predictors/test_table_cells_detection.py b/tests/models/test_table_cells_detection.py similarity index 100% rename from tests/predictors/test_table_cells_detection.py rename to tests/models/test_table_cells_detection.py diff --git a/tests/predictors/test_table_classifcation.py b/tests/models/test_table_classifcation.py similarity index 100% rename from tests/predictors/test_table_classifcation.py rename to tests/models/test_table_classifcation.py diff --git a/tests/predictors/test_table_structure_recognition.py b/tests/models/test_table_structure_recognition.py similarity index 100% rename from tests/predictors/test_table_structure_recognition.py rename to tests/models/test_table_structure_recognition.py diff --git a/tests/predictors/test_text_detection.py b/tests/models/test_text_detection.py similarity index 100% rename from tests/predictors/test_text_detection.py rename to tests/models/test_text_detection.py diff --git a/tests/predictors/test_text_image_unwarping.py b/tests/models/test_text_image_unwarping.py similarity index 100% rename from tests/predictors/test_text_image_unwarping.py rename to tests/models/test_text_image_unwarping.py diff --git a/tests/predictors/test_text_recognition.py b/tests/models/test_text_recognition.py similarity index 96% rename from tests/predictors/test_text_recognition.py rename to tests/models/test_text_recognition.py index 0487e65cf1..6d25a2f0bd 100644 --- a/tests/predictors/test_text_recognition.py +++ b/tests/models/test_text_recognition.py @@ -25,4 +25,5 @@ def test_predict(text_recognition_predictor, image_path): "input_img", "rec_text", "rec_score", + "vis_font", } diff --git a/tests/predictors/test_textline_orientation_classifcation.py b/tests/models/test_textline_orientation_classifcation.py similarity index 100% rename from tests/predictors/test_textline_orientation_classifcation.py rename to tests/models/test_textline_orientation_classifcation.py diff --git a/tests/pipelines/test_pp_doctranslation.py b/tests/pipelines/test_pp_doctranslation.py new file mode 100644 index 0000000000..3421985afb --- /dev/null +++ b/tests/pipelines/test_pp_doctranslation.py @@ -0,0 +1,80 @@ +import pytest + +from paddleocr import PPDocTranslation +from ..testing_utils import TEST_DATA_DIR + + +@pytest.fixture(scope="module") +def pp_doctranslation_pipeline(): + return PPDocTranslation() + + +@pytest.mark.parametrize( + "image_path", + [ + TEST_DATA_DIR / "book.jpg", + ], +) +def test_visual_predict(pp_doctranslation_pipeline, image_path): + result = pp_doctranslation_pipeline.visual_predict(str(image_path)) + + assert result is not None + assert isinstance(result, list) + assert len(result) == 1 + res = result[0] + assert isinstance(res, dict) + assert res.keys() == {"layout_parsing_result"} + assert isinstance(res["layout_parsing_result"], dict) + + +@pytest.mark.parametrize( + "params", + [ + {"use_doc_orientation_classify": False}, + {"use_doc_unwarping": False}, + {"use_table_recognition": False}, + {"use_formula_recognition": False}, + {"layout_threshold": 0.88}, + {"layout_threshold": [0.45, 0.4]}, + {"layout_threshold": {0: 0.45, 2: 0.48, 7: 0.4}}, + {"layout_nms": False}, + {"layout_unclip_ratio": 1.1}, + {"layout_unclip_ratio": [1.2, 1.5]}, + {"layout_unclip_ratio": {0: 1.2, 2: 1.5, 7: 1.8}}, + {"layout_merge_bboxes_mode": "large"}, + {"layout_merge_bboxes_mode": {0: "large", 2: "small", 7: "union"}}, + {"text_det_limit_side_len": 640, "text_det_limit_type": "min"}, + {"text_det_thresh": 0.5}, + {"text_det_box_thresh": 0.3}, + {"text_det_unclip_ratio": 3.0}, + {"text_rec_score_thresh": 0.5}, + ], +) +def test_predict_params( + monkeypatch, + pp_doctranslation_pipeline, + params, +): + def _dummy_visual_predict(input, **params): + yield {"layout_parsing_result": params} + + monkeypatch.setattr( + pp_doctranslation_pipeline.paddlex_pipeline, + "visual_predict", + _dummy_visual_predict, + ) + + result = pp_doctranslation_pipeline.visual_predict( + input, + **params, + ) + + assert isinstance(result, list) + assert len(result) == 1 + res = result[0] + res = res["layout_parsing_result"] + for k, v in params.items(): + assert res[k] == v + + +# TODO: Test constructor and other methods