Skip to content

本地部署PP-CHATOCR-V4如何调整配置参数 #3826

@hellomrsu

Description

@hellomrsu

Checklist:

描述问题

我打算本地服务器部署PP-CHATOCR-V4(但没有服务化部署或高性能部署),用于将复杂的PDF表格转换成JSON文件,然后根据识别的TEXTBOX的坐标和内容提取关键信息,我没有使用产线中的大模型,我只是因为只有这个产线能够正常运行表格识别、版面识别和OCR等模型所以用这个产线,我只需要在布局检测的JSON文件中按照坐标位置来提取对应信息。
使用默认的YAML配置文件可以运行,但是表格结构识别不准,我打算通过调整配置doc_preprocessor_pipeline等子产线提高精度,但是我只要我开启一些默认为FALSE的参数时就会报错。比如:比如启用doc_preprocessor_pipeline就会程序出错: config error for doc_preprocessor_pipeline!
启用 layout_det就会程序出错: config error for layout_det_model!
启用TableRecognition:的use_ocr_model: False就会程序出错: config error for general_ocr_pipeline!doc_preprocessor_pipeline就会程序出错: config error for doc_preprocessor_pipeline!。

复现

1.python代码:
pipeline = create_pipeline(pipeline="/home/szp/PP-TableMagic/PP-ChatOCRv4-doc2.yaml")
visual_predict_res = pipeline.visual_predict(
input=filepath,
use_doc_orientation_classify=True,
use_doc_unwarping=True,
use_common_ocr=True,
use_seal_recognition=True,
use_table_recognition=True,
layout_nms=True,
uvdoc=True,
)
2.YAML配置文件:

pipeline_name: PP-ChatOCRv4-doc

use_layout_parser: True

use_mllm_predict: True

SubModules:
LLM_Chat:
module_name: chat_bot
model_name: deepseek-r1:1.5b
base_url: "http://localhost:11434/v1"
api_type: openai
api_key: sk-123456789
temperature: 0.2

LLM_Retriever:
module_name: retriever
model_name: nomic-embed-text
base_url: "http://localhost:11434/v1"
api_type: openai
api_key: sk-123456789

MLLM_Chat:
module_name: chat_bot
model_name: granite3.2-vision
base_url: "http://localhost:11434/v1"
api_type: openai
api_key: sk-123456789
temperature: 0.3

PromptEngneering:
KIE_CommonText:
module_name: prompt_engneering

  task_type: text_kie_prompt_v2

  task_description: '你现在的任务是从OCR结果中提取问题列表中每一个问题的答案。
      OCR的文字识别结果使用```符号包围,包含所识别出来的文字,顺序在原始图片中从左至右、从上至下。
      我指定的问题列表使用[]符号包围。请注意OCR的文字识别结果可能存在长句子换行被切断、不合理的分词、
      文字被错误合并等问题,你需要结合上下文语义进行综合判断,以获取准确的答案。'

  output_format: '在返回结果时使用JSON格式,包含多个key-value对,key值为我指定的问题,value值为该问题对应的答案。
      如果认为OCR识别结果中,对于问题key,没有答案,则将value赋值为"未知"。请只输出json格式的结果,
      并做json格式校验后返回,不要包含其它多余文字!'

  rules_str: '请依次确认满足下面要求。(1)每个问题的答案用OCR结果的内容回答,针对问题回答尽可能详细和完整,
      并保持格式、数字、正负号、单位、符号和标点都与OCR结果中的内容完全一致。
      (2)如果答案的句末有标点符号,请添加标点符号。
      (3)对于答案中的数字,如果可以推断出单位,请补充相应的单位。'

  few_shot_demo_text_content:

  few_shot_demo_key_value_list:
      
KIE_Table:
  module_name: prompt_engneering

  task_type: table_kie_prompt_v2

  task_description: '你现在的任务是从输入的html格式的表格内容中提取问题列表中每一个问题的答案。
      表格内容使用```符号包围,我指定的问题列表使用[]符号包围。'

  output_format: '在返回结果时使用JSON格式,包含多个key-value对,key值为我指定的问题,value值为该问题对应的答案。
      如果认为表格内容中,对于问题key,没有答案,则将value赋值为"未知"。请只输出json格式的结果,
      并做json格式校验后返回,不要包含其它多余文字!'

  rules_str: '请依次确认满足下面要求。(1)每个问题的答案用表格内容回答,针对问题回答尽可能详细和完整,
      并保持格式、数字、正负号、单位、符号和标点都与表格内容完全一致。
      (2)对于答案中的数字,如果可以推断出单位,请补充相应的单位。
      (3)如果答案是百分比,请添加百分号。'

  few_shot_demo_text_content:

  few_shot_demo_key_value_list:

Ensemble:
  module_name: prompt_engneering

  task_type: ensemble_prompt

  task_description: '你现在的任务是,对于一个问题,对比方法A和方法B的结果,选择更准确的一个回答。
    问题用```符号包围。'

  output_format: '请返回JSON格式的结果,包含多个key-value对,key值为我指定的问题,
    value值为`方法A`或`方法B`。如果对于问题key,没有找到答案,将value赋值为"未知"。
    请只输出json格式的结果,并做json格式校验后返回,不要包含其它多余文字!'

  rules_str: '对于涉及数字的问题,请返回与问题描述最相关且数字表述正确的答案。
    请特别注意数字中的标点使用是否合理。'

  few_shot_demo_text_content:

  few_shot_demo_key_value_list:

SubPipelines:
LayoutParser:
pipeline_name: layout_parsing

use_doc_preprocessor: True
use_general_ocr: True
use_seal_recognition: True
use_table_recognition: True
use_formula_recognition: False

SubModules:
  LayoutDetection:
    module_name: layout_detection
    model_name: RT-DETR-H_layout_3cls
    model_dir: null

SubPipelines:
  DocPreprocessor:
    pipeline_name: doc_preprocessor
    use_doc_orientation_classify: True
    use_doc_unwarping: True
    SubModules:
      DocOrientationClassify:
        module_name: doc_text_orientation
        model_name: PP-LCNet_x1_0_doc_ori
        model_dir: null
      DocUnwarping:
        module_name: image_unwarping
        model_name: UVDoc
        model_dir: null

  GeneralOCR:
    pipeline_name: OCR
    text_type: general
    use_doc_preprocessor: True
    use_textline_orientation: False
    SubModules:
      TextDetection:
        module_name: text_detection
        model_name: PP-OCRv4_server_det
        model_dir: null
        limit_side_len: 960
        limit_type: max
        thresh: 0.3
        box_thresh: 0.6
        unclip_ratio: 2.0
        
      TextRecognition:
        module_name: text_recognition
        model_name: PP-OCRv4_server_rec_doc
        model_dir: null
        batch_size: 6
        score_thresh: 0.0

  TableRecognition:
    pipeline_name: table_recognition
    use_layout_detection: True        
    use_doc_preprocessor: True
    use_ocr_model: True
    SubModules:
      TableStructureRecognition:
        module_name: table_structure_recognition
        model_name: SLANet_plus
        model_dir: null

  SealRecognition:
    pipeline_name: seal_recognition
    use_layout_detection: True
    use_doc_preprocessor: True
    SubPipelines:
      SealOCR:
        pipeline_name: OCR
        text_type: seal
        use_doc_preprocessor: True
        use_textline_orientation: False
        SubModules:
          TextDetection:
            module_name: seal_text_detection
            model_name: PP-OCRv4_server_seal_det
            model_dir: null
            limit_side_len: 736
            limit_type: min
            thresh: 0.2
            box_thresh: 0.6
            unclip_ratio: 0.5
          TextRecognition:
            module_name: text_recognition
            model_name: PP-OCRv4_server_rec_doc
            model_dir: null
            batch_size: 1
            score_thresh: 0
  1. 您使用的模型数据集是?
    详见YAML文件。
  2. 请提供您出现的报错信息及相关log
    (myenv) szp@szp:~/PP-TableMagic$ python3 cjxxV4_0415-2.py
    Using official model (PP-LCNet_x1_0_doc_ori), the model files will be automatically downloaded and saved in /home/szp/.paddlex/official_models.
    /home/szp/PP-TableMagic/myenv/lib/python3.12/site-packages/paddle/utils/cpp_extension/extension_utils.py:711: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md
    warnings.warn(warning_message)
    Using official model (UVDoc), the model files will be automatically downloaded and saved in /home/szp/.paddlex/official_models.
    Using official model (RT-DETR-H_layout_3cls), the model files will be automatically downloaded and saved in /home/szp/.paddlex/official_models.
    程序出错: config error for doc_preprocessor_pipeline!

环境

  1. 请提供您使用的PaddlePaddle、PaddleX版本号、Python版本号
    Python 版本号: 3.12.3 (main, Feb 4 2025, 14:48:35) [GCC 13.3.0]
    Python 主版本号: 3.12.3
    /home/szp/PP-TableMagic/myenv/lib/python3.12/site-packages/paddle/utils/cpp_extension/extension_utils.py:711: UserWarning: No ccache found. Please be aware that recompiling all source files may be required. You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md
    warnings.warn(warning_message)
    PaddlePaddle 版本号: 3.0.0-rc0
    PaddleX 版本号: 3.0.0.rc0

  2. 请提供您使用的操作系统信息,如Linux/Windows/MacOS
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 24.04.1 LTS
    Release: 24.04
    Codename: noble

  3. 请问您使用的CUDA/cuDNN的版本号是?
    当前使用 CPU 版本,无需 CUDA/cuDNN 加速库。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions