入门

快速开始与 API安装在线 OCRCode generator (EN)

模型与产线

PP-OCRv6 模型支持语言PP-StructureV3PaddleOCR-VL

部署与集成

Serving & API (EN)PaddleOCR.js (EN)MCP server (EN)

排错与升级

常见错误从 2.x 迁移Releases (EN)

评估

Our benchmark (EN)Compare OCR tools (EN)License & cost (EN)

工具

在线 OCR安装命令生成器Code generator (EN)报错修复助手2.x → 3.x 代码转换语言代码查询

语言

English简体中文日本語在线体验 OCR
代码转换 · 123 条对照 · 已在 3.7.0 上实测

把 PaddleOCR 2.x 代码迁移到 3.x

PaddleOCR 3.x 不向后兼容:use_gpu 和 show_log 现在会直接报错,ocr(img, cls=True) 会抛出 TypeError,draw_ocr 没了,结果也从嵌套列表变成了对象。把 2.x 代码粘贴到下面,就能得到 3.x 代码以及每一处改动和原因。

已对照 PaddleOCR 3.7.0 核实更新于 14 分钟阅读在浏览器本地运行
本页目录
  1. 2.x → 3.x 代码转换工具
  2. 3.x 改了什么,为什么改
  3. use_angle_cls 以及仍然可用的 11 个旧参数名
  4. use_gpu、show_log、use_onnx、drop_score:是报错,不是警告
  5. ocr(img, cls=True) 与新的结果格式
  6. cannot import name 'draw_ocr' from 'paddleocr'
  7. det_model_dir 和 rec_model_dir:自定义模型
  8. 悄悄变化的默认值
  9. PPStructure → PPStructureV3
  10. 命令行:paddleocr --image_dir → paddleocr ocr -i
  11. 完整的 2.x → 3.x 对照表
  12. 继续使用 2.x:把 paddleocr 锁定在 3 以下
  13. 迁移检查清单
  14. 常见问题

简短回答:把 use_angle_cls 改名为 use_textline_orientation,把 use_gpu=True 换成 device='gpu',删掉 show_log,调用 ocr.predict(img) 时不要带 cls=,并改为读取 res['rec_texts']、res['rec_scores'] 和 res['rec_polys'],而不是 line[1][0]。用 res.save_to_img('output') 代替 draw_ocr。下面的转换工具会自动完成这些修改,并标出它没把握自动处理的地方。

2.x → 3.x 代码转换工具#

粘贴 PaddleOCR 2.x 代码或 2.x 命令#

在浏览器本地运行
加载一个 2.x 示例
边输入边转换,代码不会离开本页。改动说明和提示目前为英文。

PythonPaddleOCR 3.x

需要人工检查

每一处改动,附原因和出处

转换工具基于规则,而不是靠猜。它只改写自己能识别的模式,为每处改动注明 PaddleOCR 源码中的依据行,并在需要人来决定的地方留下 # TODO(paddleocr 3.x) 注释。我们在 PaddleOCR 3.7.0 上运行了前两个示例的转换结果:两者都没有报错,都正确读出了测试小票的全部 27 行,第一个还写出了 result.jpg。7

3.x 改了什么,为什么改#

PaddleOCR 2.x 从 2021 年到 2025 年初,一直是在同一套轻量代码上不断叠加功能。维护者在升级说明中写道,这种方式走到了尽头:代码重复、接口不一致,旧依赖也无法再配合新版 PaddlePaddle。他们的答案是“一次重大的、不向后兼容的升级”。2 在 3.x 中,paddleocr 包是 PaddleX 产线之上的一层薄封装;PaddleOCR 封装的是 PaddleX 的 OCR 产线,并返回结果对象。1

  1. paddleocr 2.7.0.3——至今仍常见于老项目的 requirements.txt。
  2. paddleocr 2.10.0——最后一个 2.x 版本。
  3. paddleocr 3.0.0——基于 PaddleX 的全新 API。
  4. paddleocr 3.7.0——当前版本,默认使用 PP-OCRv6 模型。

以上日期均为 PyPI 上的首次上传日期。6 现在不指定版本安装 paddleocr 会得到 3.7.0,所以只要新建环境,2.x 代码就会立刻出错。导致出错的改动如下:

未知参数直接报错#

只有 11 个旧参数名会被自动转换。其余参数,包括 use_gpu 和 show_log,都会抛出 ValueError: Unknown argument。

ocr() 的开关没了#

cls、det、rec、bin、inv 和 slice 都已移除。ocr() 只是 predict() 的弃用别名。

结果变成对象#

每页一个 OCRResult,内含几组并列的列表,而不是每行一个 [box, (text, score)]。旧的下标写法会报 KeyError: 0。

辅助函数和 PPStructure 被移除#

draw_ocr、save_structure_res 等都没了,结果对象可以自己保存和绘图。PPStructure 变成了 PPStructureV3。

还有两处改动不会报错,但会改变输出:新的默认模型和预处理(见 悄悄变化的默认值),以及推理引擎的安装方式。在 3.x 中 pip install paddleocr 不会安装 PaddlePaddle,而 PyPI 上的 paddlepaddle-gpu 停在 2.6.2——见 安装教程。

use_angle_cls 以及仍然可用的 11 个旧参数名#

3.x 为 PaddleOCR 的旧关键字参数保留了一张小小的映射表。下面是完整列表,直接摘自源码:1

pythonpaddleocr/_pipelines/ocr.py, lines 44-56
_DEPRECATED_PARAM_NAME_MAPPING = {
    "det_model_dir": "text_detection_model_dir",
    "det_limit_side_len": "text_det_limit_side_len",
    "det_limit_type": "text_det_limit_type",
    "det_db_thresh": "text_det_thresh",
    "det_db_box_thresh": "text_det_box_thresh",
    "det_db_unclip_ratio": "text_det_unclip_ratio",
    "rec_model_dir": "text_recognition_model_dir",
    "rec_batch_num": "text_recognition_batch_size",
    "use_angle_cls": "use_textline_orientation",
    "cls_model_dir": "textline_orientation_model_dir",
    "cls_batch_num": "textline_orientation_batch_size",
}

传入其中任意一个,3.x 都会替你改成新名称并给出警告。我们在 3.7.0 上运行 PaddleOCR(lang='en', use_angle_cls=True),得到的正是:7

textOutput
DeprecationWarning: The parameter `use_angle_cls` has been deprecated and will be removed in the future. Please use `use_textline_orientation` instead.

除非由 __main__ 触发,Python 默认会隐藏 DeprecationWarning,所以很多人根本看不到这条警告。从这张表周围的代码可以得出三条规则:1

  • 新旧名称同时传入会报错。PaddleOCR(use_angle_cls=True, use_textline_orientation=True) 会抛出 ValueError: `use_angle_cls` and `use_textline_orientation` are mutually exclusive.(我们复现过)。
  • 只有 PaddleOCR 有这张表。PPStructureV3(det_model_dir=...) 和 PPStructureV3(use_angle_cls=True) 会抛出 ValueError: Unknown argument: det_model_dir / use_angle_cls。两者我们都复现过。
  • “还能用”不等于“行为不变”。2.x 中 use_angle_cls 默认为 False。3.x 中不设置 use_textline_orientation 时采用产线默认值,也就是 True。5

同样这 11 个名称在 paddleocr ocr 中也以命令行参数的形式存在:--use_angle_cls 仍然可用,并会打印 CLIDeprecationWarning: The option `--use_angle_cls` has been deprecated and will be removed in the future. Please refer to the documentation for more details.

use_gpu、show_log、use_onnx、drop_score:是报错,不是警告#

其余所有遗留的关键字参数都会撞上这个循环,它只接受 3.x 的引擎选项:1

pythonpaddleocr/_common_args.py, lines 52-54
unknown_names = kwargs.keys() - default_vals.keys()
for name in unknown_names:
    raise ValueError(f"Unknown argument: {name}")

因为它遇到第一个未知名称就抛出异常,而 unknown_names 又是集合,所以带着三个过时参数的构造函数每次运行只会报出其中一个。用下面的表格或转换工具一次性全部改掉。我们在 3.7.0 上的复现结果:7

textPaddleOCR(lang='en', **kw) on paddleocr 3.7.0
use_gpu=True      -> ValueError: Unknown argument: use_gpu
show_log=False    -> ValueError: Unknown argument: show_log
use_onnx=True     -> ValueError: Unknown argument: use_onnx
drop_score=0.5    -> ValueError: Unknown argument: drop_score
2.x3.x 替代写法说明
use_gpu=Truedevice='gpu'或 'gpu:1'。不写 device 时,PaddlePaddle 能识别到 CUDA GPU 就用 GPU 0,否则用 CPU。
use_gpu=Falsedevice='cpu''cpu:0' 会被拒绝;CPU 不带序号。
gpu_id=1device='gpu:1'序号写在设备字符串里。
gpu_mem=500—没有对应项。显存不足请见 GPU 显存不足。
use_xpu / use_npu / use_mlu / use_gcudevice='xpu' 等支持的设备类型:cpu、gpu、xpu、npu、mlu、gcu、dcu、iluvatar_gpu、metax_gpu。
show_log=False直接删掉新的 paddleocr logger 默认就是 ERROR 级别。需要更多输出:logger.setLevel(logging.INFO)。
use_onnx=Trueengine='onnxruntime'PaddleOCR 3.5+,需要 pip install onnxruntime。我们的测试:3.7.0 只装 onnxruntime、不装 PaddlePaddle 也能运行。
drop_score=0.5text_rec_score_thresh=0.5不是别名。3.x 默认为 0.0,不设置就不会过滤任何结果。
rec_image_shape='3, 48, 320'text_rec_input_shape=(3, 48, 320)现在是元组,不再是字符串。

反方向的常见错误:device='cuda'。PaddleX 会用一个裸 AssertionError 拒绝它;GPU 的设备类型叫 gpu。

ocr(img, cls=True) 与新的结果格式#

3.x 仍然有 ocr() 方法,但它只是一个已弃用的别名,会把关键字参数转发给 predict():1

pythonpaddleocr/_pipelines/ocr.py, lines 239-241
@deprecated("Please use `predict` instead.")
def ocr(self, img, **kwargs):
    return self.predict(img, **kwargs)

predict() 没有 cls 参数,所以几乎每篇 2.x 教程里都有的那一行会直接失败。在 3.7.0 上我们得到:7

textocr.ocr('receipt.png', cls=True)
TypeError: PaddleOCR.predict() got an unexpected keyword argument 'cls'

文本行方向分类现在在创建对象时决定(use_textline_orientation=True),或在单次调用时用 predict(img, use_textline_orientation=False) 指定。PaddleX 源码里有个坑:你可以在单次调用时关闭它,但如果创建对象时没开,单次调用时再打开只会记录一条错误日志,而不会执行。

更大的变化是返回值。在 2.x 中,ocr() 为每张图片返回一个列表,每行是 [box, (text, score)],没识别到文字时返回 None。3 在 3.x 中,predict() 为每张图片或每个 PDF 页面返回一个 OCRResult。它是一个包含若干并列列表的字典:5

键内容
rec_texts每行识别出的文字(只包含得分 ≥ text_rec_score_thresh 的行)
rec_scores每行的置信度
rec_polys每行的多边形:形状为 (4, 2) 的 int16 NumPy 数组
rec_boxes水平外接框,形状 (n, 4):[x_min, y_min, x_max, y_max]
dt_polys所有检测到的框(不经过得分过滤)
input_path、page_index结果的来源

值得了解旧循环遇到这个对象时会发生什么,因为报错里完全不提 PaddleOCR。for line in result[0] 现在遍历的是字典的键,所以第一个 line 是字符串 'input_path',box, (text, score) = line 会报 ValueError: too many values to unpack (expected 2)。result[0][0][1][0] 这类下标会报 KeyError: 0。两者我们都复现过。7

result = ocr.ocr(img_path, cls=True)
for line in result[0]:
    box, (text, score) = line
    print(text, score, box)
result = ocr.predict(img_path)
for res in result:  # 每张图片 / 每个 PDF 页面一个 OCRResult
    for box, text, score in zip(res['rec_polys'], res['rec_texts'], res['rec_scores']):
        print(text, score, box.tolist())

转换之后有三个细节容易出错。多边形是 NumPy 数组,所以 json.dumps 之前要先调用 .tolist()(或者直接用 res.json)。没有文字的页面得到的是空列表而不是 None,所以 if result[0] is None 永远不会成立——改为判断 if not res['rec_texts']。另外,在默认的 use_doc_unwarping=True 下,坐标对应的是展平后的图片:在我们的小票上,开启弯曲矫正时第一行是 [[119,11],[507,8],[507,46],[120,49]],关闭时是 [[128,55],[489,55],[489,82],[128,82]]。7 详见 检测框与原图对不上。

ocr(img, det=False) 和 ocr(img, rec=False) 在产线中没有对应写法,请使用单模型类:TextRecognition(model_name="PP-OCRv6_medium_rec").predict(crop) 返回 rec_text 和 rec_score;TextDetection(model_name="PP-OCRv6_medium_det").predict(img) 返回 dt_polys 和 dt_scores。转换工具不会去猜你的裁剪图是怎么来的,而是给这些调用标上 TODO。

cannot import name 'draw_ocr' from 'paddleocr'#

draw_ocr 由 paddleocr 2.10.0 导出,而 3.x 包里没有它,所以导入会失败:7

text
ImportError: cannot import name 'draw_ocr' from 'paddleocr'

现在结果对象可以自己绘图。升级说明用一行调用替换了整段可视化代码:2

from PIL import Image
from paddleocr import draw_ocr
result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
for res in result:
    res.save_to_img('output')            # 写出 <name>_ocr_res_img.png(以及预处理后的图片)
    pil_image = res.img['ocr_res_img']   # 或者以 PIL 图片的形式留在内存中

在我们的小票上,save_to_img('output') 写出了 receipt_ocr_res_img.png 和 receipt_preprocessed_img.png;res.img 里也是这两个键。7 要使用自己的字体,请设置环境变量 PADDLE_PDX_LOCAL_FONT_FILE_PATH,而不是传 font_path。其他被移除的辅助函数也同样对应:save_structure_res → res.save_to_json()、save_to_xlsx()、save_to_html() 或 save_all();convert_info_docx → res.save_to_word();to_excel → res.save_to_xlsx()。5

det_model_dir 和 rec_model_dir:自定义模型#

det_model_dir、rec_model_dir 和 cls_model_dir 属于那 11 个别名,所以在 PaddleOCR 上仍然可用。但底层有两点变化:

  • 还要给出模型名称。如果只设置了 text_detection_model_dir,产线会沿用默认名称(PP-OCRv6_medium_det),PaddleX 再拿它与文件夹中 inference.yml 里的名称比对:ValueError: Model name mismatch: expected 'PP-OCRv6_medium_det' but config has 'PP-OCRv5_server_det'. Please input the correct model dir.5
  • 文件夹必须是 3.x 格式的导出。3.x 会查找 inference.json 或 inference.pdmodel,以及 inference.pdiparams 和 inference.yml。没有有效文件的文件夹会报 No valid model files were found for engine 'paddle_static'。
  • 训练相关的选项没了。rec_char_dict_path、rec_algorithm、det_algorithm、use_space_char 和 max_text_length 会报 Unknown argument。模型按名称选择,各模块的设置放在导出的 PaddleX 配置中(先 export_paddlex_config_to_yaml,再传 paddlex_config=...)。
python3.x 使用自己的模型
from paddleocr import PaddleOCR

ocr = PaddleOCR(
    text_detection_model_name='PP-OCRv5_server_det',
    text_detection_model_dir='./models/PP-OCRv5_server_det_infer',
    text_recognition_model_name='PP-OCRv5_server_rec',
    text_recognition_model_dir='./models/PP-OCRv5_server_rec_infer',
)

给出模型名称或文件夹后,lang 和 ocr_version 会被忽略,并给出 UserWarning。另外注意,2.x 的文字体系取值 lang='latin'、'arabic'、'cyrillic' 和 'devanagari' 在 3.x 中不是语言代码:它们会报 No models are available for lang='latin' and ocr_version=None. 请从 语言列表 中选择真正的语言代码。

悄悄变化的默认值#

迁移后能跑通的代码,文字、检测框和速度仍可能与以前不同,因为默认值变了:53

设置2.x 默认3.x 默认
模型PP-OCRv4PP-OCRv6_medium 检测 + 识别
整页方向分类—开启(use_doc_orientation_classify)
文档弯曲矫正(UVDoc)—开启(use_doc_unwarping)
文本行方向分类关闭(use_angle_cls=False)开启(use_textline_orientation)
检测缩放960,max64,min(最长边 4000)
得分过滤0.5(drop_score)0.0(text_rec_score_thresh)
CPU 上的 oneDNN关闭开启(enable_mkldnn=True)

转换工具的“保持 2.x 的行为”选项会加上报错数据库推荐的四个开关,使输出接近 2.x:use_doc_orientation_classify=False、use_doc_unwarping=False、use_textline_orientation=False 和 text_rec_score_thresh=0.5。关闭预处理模型还能让 3.x 跑得更快。它保留新模型——新模型在我们的五份测试文档上 124 项中 123 项完全正确(我们的基准测试(英文))。

新环境里,oneDNN 默认值会坑你。在 enable_mkldnn=True 和 PaddlePaddle 3.3.1(如今 pip install paddlepaddle 装到的版本)下,CPU 推理会崩溃,报 ConvertPirAttribute2RuntimeAttribute not support [pir::ArrayAttribute<pir::DoubleAttribute>]。请锁定 paddlepaddle==3.2.0。详情和我们的耗时数据:oneDNN 问题的解决方法。

PPStructure → PPStructureV3#

在 3.x 中,from paddleocr import PPStructure 会报 ImportError: cannot import name 'PPStructure' from 'paddleocr'。升级说明指向 PPStructureV3,它需要额外安装:28

python -m pip install "paddleocr[doc-parser]"

没有安装它时,PPStructureV3() 会报 RuntimeError: A dependency error occurred during pipeline creation(解决方法)。它的构造函数有自己的一套参数,而且没有别名映射表,所以连在 PaddleOCR 上能用的旧名称在这里也会报错。我们在 3.7.0 上从 PPStructureV3 得到了 use_gpu、det_model_dir、use_angle_cls 和 show_log 的 Unknown argument 报错。7

PPStructure(2.x)PPStructureV3(3.x)
use_gpu=Truedevice='gpu'
table=Falseuse_table_recognition=False
formula=Trueuse_formula_recognition=True(现在默认开启)
image_orientation=Trueuse_doc_orientation_classify=True
layout_model_dirlayout_detection_model_dir + layout_detection_model_name
table_model_dir拆分为:wired_table_structure_recognition_model_dir / wireless_…
recovery=Trueres.save_to_word(dir) / res.save_to_markdown(dir)
layout=False、ocr=False没有开关:改用 PaddleOCR 或 TableRecognitionPipelineV2
mode='kie'PP-ChatOCRv4(pip install "paddleocr[ie]")
from paddleocr import PPStructure, save_structure_res

table_engine = PPStructure(show_log=True, image_orientation=True, use_gpu=True)
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, './output', os.path.basename(img_path).split('.')[0])
for line in result:
    line.pop('img')
    print(line)
from paddleocr import PPStructureV3

pipeline = PPStructureV3(use_doc_orientation_classify=True, device='gpu')
output = pipeline.predict(img_path)       # 每页一个结果;PDF 可以直接传入
for res in output:
    res.print()
    res.save_to_json('output')
    res.save_to_markdown('output')        # 另有:save_to_word、save_to_html、save_to_xlsx、save_to_img

2.x 的版面结果是单张图片的区域字典列表;3.x 的结果是每页一个对象。我们的 PP-StructureV3 指南 详细介绍了输出内容,包括它默认使用哪些 OCR 模型。

命令行:paddleocr --image_dir → paddleocr ocr -i#

3.x 的命令行需要子命令,并用 -i 传入输入。2.x 的写法会以一种让人摸不着头脑的方式失败:argparse 把你的文件名当成了子命令。我们在 3.7.0 上的运行结果:7

textpaddleocr --image_dir receipt.png --use_angle_cls true --lang en
usage: paddleocr [-h] [-v] COMMAND ...
paddleocr: error: argument COMMAND: invalid choice: 'receipt.png' (choose from 'doc_preprocessor', 'doc_understanding', 'formula_recognition_pipeline', 'ocr', 'doc_parser', 'pp_chatocrv4_doc', 'pp_doctranslation', 'pp_structurev3', ...)
2.x 命令3.x 命令
paddleocr --image_dir x.png --use_angle_cls true --lang enpaddleocr ocr -i x.png --use_textline_orientation True --lang en
--use_gpu false--device cpu(--use_gpu 会报 unrecognized arguments)
--type structure --recovery true --output ./outpaddleocr pp_structurev3 -i x.pdf --save_path ./out
--det falsepaddleocr text_recognition -i crop.png
--rec falsepaddleocr text_detection -i x.png
--use_onnx true--engine onnxruntime
--det_model_dir d --rec_model_dir r--text_detection_model_dir d --text_recognition_model_dir r

布尔参数接受 true/True/1,其他值都视为 false。我们用 --save_path 在小票上运行了 paddleocr ocr:它打印了结果,并写出了 JSON 和两张图片。可以把整个 shell 脚本粘贴进转换工具,它只改写 paddleocr 和 pip install 这两类行,其余保持不变。

完整的 2.x → 3.x 对照表#

下面是我们核实过的全部 123 条对照,与转换工具使用同一份数据生成。“别名,有警告”表示旧名称仍可使用;“需改名”表示必须修改;“已替换”和“已移除”如果保留不改就会报错。每一行都链接到我们阅读过的文件和行号。各行的说明目前为英文原文。135

导入 13#

2.x3.x说明(英文)来源
from paddleocr import PaddleOCRfrom paddleocr import PaddleOCR有变化 Same import name; the class is now a wrapper around the PaddleX 'OCR' pipeline and returns result objects instead of nested lists.PaddleOCR/paddleocr/__init__.py:32-43; PaddleOCR/paddleocr/_pipelines/ocr.py:66,175-177
from paddleocr import PPStructurefrom paddleocr import PPStructureV3已替换 PPStructure was removed in 3.x; the upgrade notes recommend PPStructureV3. Needs the doc-parser dependency group: pip install "paddleocr[doc-parser]".PaddleOCR/docs/update/upgrade_notes.en.md:73; PaddleOCR/paddleocr/__init__.py:84-131 (no PPStructure in __all__); PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:963
from paddleocr import draw_ocr—已移除 draw_ocr was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import draw_structure_result—已移除 draw_structure_result was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import save_structure_res—已移除 save_structure_res was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import download_with_progressbar—已移除 download_with_progressbar was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import sorted_layout_boxes—已移除 sorted_layout_boxes was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import convert_info_docx—已移除 convert_info_docx was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import to_excel—已移除 to_excel was exported by paddleocr 2.10.0 but is not exported by 3.x; importing it raises ImportError. See the matching 'util' entry for the replacement.paddleocr-2.10.0/paddleocr/__init__.py:14-24,32-42; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr import convert_info_markdown—已移除 Listed in 2.10.0 paddleocr.py __all__ (not re-exported by the package __init__). No 3.x export; use PPStructureV3 result .save_to_markdown().paddleocr-2.10.0/paddleocr/paddleocr.py:73-84; PaddleOCR/paddleocr/__init__.py:84-131
from paddleocr.tools.infer.utility import ... / from paddleocr.ppocr... / from paddleocr.ppstructure...—已移除 The 2.x wheel bundled tools/, ppocr/ and ppstructure/ inside the paddleocr package. The 3.x package only contains paddleocr/ (setuptools include = paddleocr, paddleocr.*), whose public API is the __all__ list.paddleocr-2.10.0/paddleocr/(wheel contains paddleocr/tools, paddleocr/ppocr, paddleocr/ppstructure); PaddleOCR/pyproject.toml:61-64; PaddleOCR/paddleocr/__init__.py:84-131
(new in 3.x) module classesfrom paddleocr import TextDetection, TextRecognition, TextLineOrientationClassification, LayoutDetection, ...有变化 3.x exposes single-model classes used to replace ocr(det=False) / ocr(rec=False).PaddleOCR/paddleocr/__init__.py:17-31
from paddleocr import logger (did not exist in 2.x; 2.x used show_log)from paddleocr import logger有变化 3.x uses a single logging.Logger named 'paddleocr', level ERROR by default.PaddleOCR/paddleocr/__init__.py:66; PaddleOCR/paddleocr/_utils/logging.py:19-36; PaddleOCR/docs/version3.x/logging.en.md:9-11

PaddleOCR 构造参数 47#

2.x3.x说明(英文)来源
use_angle_clsuse_textline_orientation别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default False (utility.py:124). 3.x pipeline default is True (paddlex OCR.yaml:7) when not set.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:124; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_model_dirtext_detection_model_dir别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. Also set text_detection_model_name to the model's real name, otherwise the default PP-OCRv6_medium_det name is kept and PaddleX raises 'Model name mismatch' if the directory's inference.yml names another model.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:61; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
rec_model_dirtext_recognition_model_dir别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. Also set text_recognition_model_name (see det_model_dir note).PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:97; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
cls_model_dirtextline_orientation_model_dir别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. Also set textline_orientation_model_name if not the default.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:125; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_db_threshtext_det_thresh别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default 0.3; 3.x YAML default 0.3 (paddlex configs/pipelines/OCR.yaml:32).PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:67; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_db_box_threshtext_det_box_thresh别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default 0.6; 3.x YAML default 0.6.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:68; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_db_unclip_ratiotext_det_unclip_ratio别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default 1.5; 3.x YAML default 1.5.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:69; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_limit_side_lentext_det_limit_side_len别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. Default CHANGED: 2.x 960 with limit_type 'max'; 3.x YAML 64 with limit_type 'min' and max_side_limit 4000 (paddlex configs/pipelines/OCR.yaml:29-31). CLI type is int in 3.x (2.x float).PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:62; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
det_limit_typetext_det_limit_type别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. Default CHANGED: 2.x 'max'; 3.x YAML 'min'.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:63; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
rec_batch_numtext_recognition_batch_size别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default 6; 3.x YAML default 6.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:100; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
cls_batch_numtextline_orientation_batch_size别名,有警告 Old name still works on PaddleOCR only, with a DeprecationWarning. Passing both names raises ValueError; PPStructureV3 raises Unknown argument. 2.x default 6; 3.x YAML default 6.PaddleOCR/paddleocr/_pipelines/ocr.py:44-56,155-169; PaddleOCR/paddleocr/_utils/deprecation.py:36-42; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:128; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml
langlang有变化 Same name. Model selection logic changed: lang=None and ocr_version=None -> PP-OCRv6_medium_det/rec. 2.x script-group values 'latin', 'arabic', 'cyrillic', 'devanagari', 'ch_doc', 'structure' are not language codes in 3.x and give ValueError "No models are available for lang='latin' and ocr_version=None." Use a real code (e.g. 'fr', 'de', 'ru', 'ar', 'hi'); 'french' and 'german' are still accepted. Ignored with a warning when model names/dirs are given.PaddleOCR/paddleocr/_pipelines/ocr.py:113-127,318-353; PaddleOCR/paddleocr/_utils/langs.py:17-60; paddleocr-2.10.0/paddleocr/paddleocr.py:506-527
ocr_version='PP-OCR' | 'PP-OCRv2' | 'PP-OCRv3' | 'PP-OCRv4'ocr_version='PP-OCRv3' | 'PP-OCRv4' | 'PP-OCRv5' | 'PP-OCRv6'有变化 2.x choices PP-OCR, PP-OCRv2, PP-OCRv3, PP-OCRv4 (default PP-OCRv4). 3.x PaddleOCR accepts PP-OCRv3..PP-OCRv6; anything else raises ValueError "Invalid OCR version: PP-OCRv2. Supported values are ['PP-OCRv3', 'PP-OCRv4', 'PP-OCRv5', 'PP-OCRv6']." PPStructureV3 accepts only PP-OCRv3..PP-OCRv5. PP-OCRv4 in 3.x only supports lang 'ch' and 'en'.paddleocr-2.10.0/paddleocr/paddleocr.py:90-91; PaddleOCR/paddleocr/_pipelines/ocr.py:58,97-100,393-399; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:28,103-106
use_gpu=True|Falsedevice='gpu' | 'gpu:0' | 'cpu'已替换 use_gpu is not accepted: ValueError "Unknown argument: use_gpu". Use device. If device is not set, GPU 0 is used when available, else CPU. If device='gpu' but Paddle has no CUDA, PaddleX logs 'The specified device (GPU) is not available! Switching to CPU instead.'PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); PaddleOCR/paddleocr/_common_args.py:38-50,102-106; paddlex-3.7.2/paddlex/utils/device.py:55-75; paddlex-3.7.2/paddlex/inference/models/runners/paddle_static/config/pp_option.py:97-115; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:40
gpu_id=Ndevice='gpu:N'已替换 Raises 'Unknown argument: gpu_id'. Device id is part of the device string.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddlex-3.7.2/paddlex/utils/device.py:78-100; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:55
gpu_mem=500—已移除 Raises 'Unknown argument: gpu_mem'. No equivalent parameter in 3.x. (Note: the repo FAQ still suggests gpu_mem=200 for OOM; that advice is 2.x-only.)PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:54; PaddleOCR/docs/FAQ.en.md:91
use_xpu=Truedevice='xpu' (or 'xpu:0')已替换 Raises 'Unknown argument: use_xpu'. Supported device types: cpu, gpu, xpu, npu, mlu, gcu, dcu, iluvatar_gpu, metax_gpu.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddlex-3.7.2/paddlex/utils/device.py:31-41; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:41
use_npu=Truedevice='npu' (or 'npu:0')已替换 Raises 'Unknown argument: use_npu'. Supported device types: cpu, gpu, xpu, npu, mlu, gcu, dcu, iluvatar_gpu, metax_gpu.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddlex-3.7.2/paddlex/utils/device.py:31-41; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:42
use_mlu=Truedevice='mlu' (or 'mlu:0')已替换 Raises 'Unknown argument: use_mlu'. Supported device types: cpu, gpu, xpu, npu, mlu, gcu, dcu, iluvatar_gpu, metax_gpu.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddlex-3.7.2/paddlex/utils/device.py:31-41; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:43
use_gcu=Truedevice='gcu' (or 'gcu:0')已替换 Raises 'Unknown argument: use_gcu'. Supported device types: cpu, gpu, xpu, npu, mlu, gcu, dcu, iluvatar_gpu, metax_gpu.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddlex-3.7.2/paddlex/utils/device.py:31-41; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:45
use_tensorrtuse_tensorrt有变化 Same name, still a constructor/CLI option. Ignored if engine_config is passed explicitly.PaddleOCR/paddleocr/_common_args.py:44,71,77-89,152-157; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:51; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:152
precision='fp32'|'fp16'|'int8'precision='fp32'|'fp16'有变化 Same name; only fp32 and fp16 accepted. Others raise ValueError "Invalid precision: int8. Supported values are: ['fp32', 'fp16']." Applies to TensorRT (use_tensorrt=True).PaddleOCR/paddleocr/_common_args.py:66-69; PaddleOCR/paddleocr/_constants.py:17,21; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:53
enable_mkldnnenable_mkldnn有变化 Same name; default CHANGED from False (2.x) to True (3.x). enable_mkldnn=False makes the CPU run_mode 'paddle' instead of the oneDNN path.paddleocr-2.10.0/paddleocr/tools/infer/utility.py:131; PaddleOCR/paddleocr/_constants.py:18; PaddleOCR/paddleocr/_common_args.py:90-95
(new) mkldnn_cache_capacitymkldnn_cache_capacity有变化 New in 3.x, default 10.PaddleOCR/paddleocr/_common_args.py:47; PaddleOCR/paddleocr/_constants.py:19
cpu_threadscpu_threads有变化 Same name, default 10 in both.paddleocr-2.10.0/paddleocr/tools/infer/utility.py:132; PaddleOCR/paddleocr/_constants.py:20
ir_optim / min_subgraph_size—已移除 Raise 'Unknown argument: ...'. Low-level Paddle Inference options now go through engine_config (paddle_static fields: run_mode, delete_pass, enable_new_ir, trt_* ...).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:50,52; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:79-97
use_onnx=Trueengine='onnxruntime' (3.5+) or enable_hpi=True已替换 Raises 'Unknown argument: use_onnx'. Upgrade notes: use_onnx replaced by high-performance inference (enable_hpi). The 3.5+ inference-engine doc adds engine='onnxruntime' (requires pip install onnxruntime / onnxruntime-gpu).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); PaddleOCR/docs/update/upgrade_notes.en.md:71; PaddleOCR/paddleocr/_common_args.py:29-35; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:20-30,50-58; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:155
onnx_providers=[...]engine='onnxruntime', engine_config={'providers': [...]}已替换 Raises 'Unknown argument: onnx_providers'. engine_config field 'providers' documented for onnxruntime.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:156; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:118-132
onnx_sess_optionsengine='onnxruntime', engine_config={'session_options': ...}已替换 Raises 'Unknown argument: onnx_sess_options'.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:157; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:132
(new) engine / engine_configengine=None|'paddle'|'paddle_static'|'paddle_dynamic'|'transformers'|'onnxruntime', engine_config={...}有变化 New in 3.5+. Default None ~ 'paddle' (PaddlePaddle). Invalid value -> ValueError "Invalid engine: X. Supported values are: [...]".PaddleOCR/paddleocr/_common_args.py:29-35,58-64; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:60-73
show_log=Falseimport logging; from paddleocr import logger; logger.setLevel(logging.ERROR)已替换 Raises 'Unknown argument: show_log'. Upgrade notes: show_log replaced by a new logging system. Default level is already ERROR. PaddleX has its own separate logger.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); PaddleOCR/docs/update/upgrade_notes.en.md:69; PaddleOCR/docs/version3.x/logging.en.md:9-26; PaddleOCR/paddleocr/_utils/logging.py:24-36; paddleocr-2.10.0/paddleocr/tools/infer/utility.py:154
drop_score=0.5text_rec_score_thresh需改名 drop_score is NOT in the deprecation map, so PaddleOCR(drop_score=...) raises 'Unknown argument: drop_score'. Equivalent filter is text_rec_score_thresh (constructor or predict()). Default CHANGED: 2.x 0.5, 3.x 0.0 (no filtering).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:107; paddleocr-2.10.0/paddleocr/tools/infer/predict_system.py:56,152; PaddleOCR/paddleocr/_pipelines/ocr.py:90,191; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml:45
rec_image_shape='3, 48, 320'text_rec_input_shape=(3, 48, 320)需改名 Not auto-mapped: rec_image_shape raises 'Unknown argument'. New param takes C,H,W (CLI: --text_rec_input_shape C H W).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:99; PaddleOCR/paddleocr/_pipelines/ocr.py:92,550-556
(new) text_det_input_shapetext_det_input_shape=(C, H, W)有变化 New in 3.x.PaddleOCR/paddleocr/_pipelines/ocr.py:89,533-539
return_word_boxreturn_word_box有变化 Same name (constructor and predict()).paddleocr-2.10.0/paddleocr/tools/infer/utility.py:161; PaddleOCR/paddleocr/_pipelines/ocr.py:91,192
cls_thresh / cls_image_shape / label_list—已移除 Raise 'Unknown argument'. No constructor equivalent; advanced per-module settings can be edited in an exported PaddleX pipeline config (export_paddlex_config_to_yaml + paddlex_config=...).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:126-129; PaddleOCR/paddleocr/_pipelines/base.py:74-77; PaddleOCR/docs/version3.x/paddleocr_and_paddlex.en.md:58-60
det_algorithm / rec_algorithm / det_box_type / use_dilation / det_db_score_mode / max_batch_size / det_east_* / det_sast_* / det_pse_* / scales / alpha / beta / fourier_degree—已移除 Raise 'Unknown argument'. Models are chosen by name: text_detection_model_name / text_recognition_model_name.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:60,64,70-93,96; PaddleOCR/paddleocr/_pipelines/ocr.py:73-80
rec_char_dict_path / use_space_char / max_text_length / rec_image_inverse / vis_font_path—已移除 Raise 'Unknown argument'. For visualization font, PaddleX reads env PADDLE_PDX_LOCAL_FONT_FILE_PATH.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:98,101-106; PaddleOCR/docs/FAQ.en.md:195-197; paddlex-3.7.2/paddlex/utils/flags.py:64
e2e_* / sr_* params—已移除 Raise 'Unknown argument'. End-to-end (PGNet) and super-resolution inference are not part of the 3.x PaddleOCR class.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:110-121,137-139
draw_img_save_dir / save_crop_res / crop_res_save_dir / save_log_pathres.save_to_img(path) / res.save_to_json(path)已替换 Raise 'Unknown argument'. Saving is done per result object.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:142-144,152; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1311-1315,1856-1857
use_mp / total_process_num / process_iddevice='gpu:0,1,...' or multi-process example已替换 Raise 'Unknown argument'. Docs describe multi-device device strings and a multi-process parallel inference example.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:147-149; PaddleOCR/docs/version3.x/algorithm/PP-StructureV3/PP-StructureV3.en.md:1514; PaddleOCR/docs/version3.x/inference_deployment/local_inference/parallel_inference.en.md
use_pdserving / warmup / benchmark—已移除 Raise 'Unknown argument'.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:133-134,151
page_num—已移除 Raises 'Unknown argument'. 3.x predict() accepts a PDF path directly and yields one result per page (page_index field).PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/tools/infer/utility.py:59; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:857-866,1817
image_dir (kwarg / CLI)predict(input) / CLI -i, --input需改名 Input is passed to predict(); accepts image path, PDF path, URL, directory of images, numpy array or list.paddleocr-2.10.0/paddleocr/tools/infer/utility.py:58; PaddleOCR/paddleocr/_utils/cli.py:31-45; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:857
(new) use_doc_orientation_classify / use_doc_unwarpinguse_doc_orientation_classify=False, use_doc_unwarping=False有变化 New in 3.x and ON by default in the OCR pipeline YAML (use_doc_preprocessor True). Official examples set both to False for plain OCR; set them False to get 2.x-like behaviour/speed.PaddleOCR/paddleocr/_pipelines/ocr.py:81-82,285-292; paddlex-3.7.2/paddlex/configs/pipelines/OCR.yaml:6-13; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1293-1298
(new) text_detection_model_name / text_recognition_model_name / textline_orientation_model_namee.g. text_detection_model_name='PP-OCRv5_mobile_det'有变化 New in 3.x: models chosen by official name; auto-downloaded.PaddleOCR/paddleocr/_pipelines/ocr.py:73-80; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1304-1310
(new) paddlex_configpaddlex_config='ocr_config.yaml'有变化 Load an edited PaddleX pipeline YAML; export current config with export_paddlex_config_to_yaml().PaddleOCR/paddleocr/_pipelines/base.py:54-100; PaddleOCR/docs/version3.x/inference_deployment/local_inference/inference_engine.en.md:215-245

PPStructure → PPStructureV3 参数 18#

2.x3.x说明(英文)来源
PPStructure(structure_version='PP-StructureV2')—已移除 Raises 'Unknown argument: structure_version' on PPStructureV3.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/paddleocr.py:92-93,820-824
PPStructure(layout=False)PaddleOCR(...) for OCR-only, or TableRecognitionPipelineV2 for table-only已替换 PPStructureV3 has no switch to disable layout detection ('Unknown argument: layout').PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/ppstructure/utility.py:90-95; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:32-101; PaddleOCR/paddleocr/__init__.py:42
PPStructure(table=True|False)PPStructureV3(use_table_recognition=True|False)需改名 Not auto-mapped ('Unknown argument: table'). 3.x default True.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:96-101; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:93; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:2342
PPStructure(formula=True|False)PPStructureV3(use_formula_recognition=True|False)需改名 Not auto-mapped. Default CHANGED: 2.x False, 3.x True.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:102-107; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:94; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:2350
PPStructure(ocr=True|False)—已移除 No equivalent switch on PPStructureV3 ('Unknown argument: ocr').PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); paddleocr-2.10.0/paddleocr/ppstructure/utility.py:108-113; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:32-101
PPStructure(image_orientation=True)PPStructureV3(use_doc_orientation_classify=True)需改名 Not auto-mapped. 3.x default False for PPStructureV3.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:84-89; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:89; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:2310
PPStructure(recovery=True)res.save_to_word(save_path) / res.save_to_markdown(save_path)已替换 Layout recovery is done via result methods on PPStructureV3 results.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:115-120; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:69,797; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:1694-1700
PPStructure(recovery_to_markdown=True)res.save_to_markdown(save_path); pipeline.concatenate_markdown_pages(markdown_list)已替换 paddleocr-2.10.0/paddleocr/ppstructure/utility.py:121-126; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:300-301; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:1766,2827-2851
PPStructure(use_pdf2docx_api=True)—已移除 No equivalent.paddleocr-2.10.0/paddleocr/ppstructure/utility.py; paddleocr-2.10.0/paddleocr/paddleocr.py:1002-1011
PPStructure(layout_model_dir=...)PPStructureV3(layout_detection_model_dir=..., layout_detection_model_name=...)需改名 Not auto-mapped.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:53; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:34-35
PPStructure(table_model_dir=...)PPStructureV3(wired_table_structure_recognition_model_dir=..., wireless_table_structure_recognition_model_dir=...)需改名 Not auto-mapped. 3.x splits table structure models into wired/wireless.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:36; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:65-68
PPStructure(formula_model_dir=...)PPStructureV3(formula_recognition_model_dir=..., formula_recognition_model_name=...)需改名 Not auto-mapped.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:45; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:86-87
PPStructure(layout_score_threshold=0.5)PPStructureV3(layout_threshold=0.5)需改名 Not auto-mapped. Accepts float or {class_id: thresh} dict.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:59-61; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:36; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:1820
PPStructure(layout_nms_threshold=0.5)PPStructureV3(layout_nms=True|False)有变化 Not auto-mapped. 3.x param is a bool switch, not a threshold.paddleocr-2.10.0/paddleocr/ppstructure/utility.py:62-64; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:37; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:1833
PPStructure(det_model_dir=..., rec_model_dir=..., use_angle_cls=...)PPStructureV3(text_detection_model_dir=..., text_recognition_model_dir=..., use_textline_orientation=...)需改名 PPStructureV3 has NO deprecated-name mapping: old names raise 'Unknown argument'.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}")); PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:50-61,91,129-143
PPStructure(mode='kie', ser_model_dir=..., re_model_dir=..., kie_algorithm=...)PPChatOCRv4Doc (pip install "paddleocr[ie]")已替换 KIE mode removed from the structure class; 3.x information-extraction pipeline is PP-ChatOCRv4 (dependency group 'ie').paddleocr-2.10.0/paddleocr/ppstructure/utility.py:66-83; PaddleOCR/paddleocr/__init__.py:38; PaddleOCR/docs/version3.x/installation.en.md:39-45
PPStructure(show_log=..., use_gpu=...)logger / device=...已替换 Same as PaddleOCR: 'Unknown argument'.PaddleOCR/paddleocr/_common_args.py:52-54 (raises ValueError(f"Unknown argument: {name}"))
PPStructure(...)(img, return_ocr_result_in_table=True)—已移除 __call__ no longer exists; use predict().paddleocr-2.10.0/paddleocr/paddleocr.py:902-933; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:223

方法与结果格式 12#

2.x3.x说明(英文)来源
PPStructure(...)PPStructureV3(...)已替换 Class removed; PPStructureV3 is the documented replacement.PaddleOCR/docs/update/upgrade_notes.en.md:73; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:31
ocr.ocr(img)ocr.predict(img)有变化 ocr() still exists but is decorated @deprecated('Please use predict instead.') and forwards **kwargs to predict(). Returns a list of OCRResult objects, one per image/page.PaddleOCR/paddleocr/_pipelines/ocr.py:208-241; PaddleOCR/docs/update/upgrade_notes.en.md:51-67
ocr.ocr(img, cls=True)ocr.predict(img, use_textline_orientation=True) or PaddleOCR(use_textline_orientation=True)有变化 predict() has no 'cls' kwarg -> TypeError (Python: "PaddleOCR.predict() got an unexpected keyword argument 'cls'").PaddleOCR/paddleocr/_pipelines/ocr.py:208-241; paddleocr-2.10.0/paddleocr/paddleocr.py:696-706
ocr.ocr(img, det=False) # recognition onlyTextRecognition(model_name=...).predict(img_or_crops)已替换 Upgrade notes: ocr() no longer accepts det/rec; use TextDetection / TextRecognition modules. Default rec model PP-OCRv6_medium_rec.PaddleOCR/docs/update/upgrade_notes.en.md:69; PaddleOCR/paddleocr/_models/text_recognition.py; paddleocr-2.10.0/paddleocr/paddleocr.py:784-799
ocr.ocr(img, rec=False) # detection onlyTextDetection(model_name=...).predict(img)已替换 Default det model PP-OCRv6_medium_det.PaddleOCR/docs/update/upgrade_notes.en.md:69; PaddleOCR/paddleocr/_models/text_detection.py:23-26; paddleocr-2.10.0/paddleocr/paddleocr.py:773-783
ocr.ocr(img, det=False, rec=False) # angle cls onlyTextLineOrientationClassification().predict(img)已替换 Default model PP-LCNet_x0_25_textline_ori.PaddleOCR/paddleocr/_models/textline_orientation_classification.py:21-24; paddleocr-2.10.0/paddleocr/paddleocr.py:784-798
ocr.ocr(img, bin=True, inv=True, alpha_color=..., slice={...})—已移除 predict() only takes the keyword args listed in its signature; others raise TypeError.PaddleOCR/paddleocr/_pipelines/ocr.py:208-222; paddleocr-2.10.0/paddleocr/paddleocr.py:696-706
PPStructure()(img)PPStructureV3().predict(img)有变化 Returns LayoutParsingResultV2 objects (print, save_to_json, save_to_markdown, save_to_word, save_to_html, save_to_xlsx, save_to_img).PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:223; paddlex-3.7.2/paddlex/inference/pipelines/layout_parsing/result_v2.py:48-49; PaddleOCR/docs/version3.x/pipeline_usage/PP-StructureV3.en.md:2815-2851
(new) predict_iter(input)ocr.predict_iter(img)有变化 Generator version of predict().PaddleOCR/paddleocr/_pipelines/ocr.py:179-206
(new) close()ocr.close()有变化 Releases the PaddleX pipeline.PaddleOCR/paddleocr/_pipelines/base.py:79-80
result = ocr.ocr(img); result[0] -> [[box, (text, score)], ...] (None if no text)result = ocr.predict(img); res = result[0]; res['rec_texts'], res['rec_scores'], res['rec_polys'], res['rec_boxes'], res['dt_polys']有变化 Each item is an OCRResult (a dict subclass). Old indexing like result[0][0][1][0] fails (KeyError: 0). rec_polys: list of (4,2) int16 arrays; rec_boxes: (n,4) [x_min,y_min,x_max,y_max]. res.json returns {'res': {...}} (JSON-safe lists).paddleocr-2.10.0/paddleocr/paddleocr.py:762-772; paddlex-3.7.2/paddlex/inference/pipelines/ocr/result.py:31; paddlex-3.7.2/paddlex/inference/common/result/base_result.py:75; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:197-207; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1836-1880
for line in result[0]: box, (text, score) = linefor res in result:
for text, score, poly in zip(res['rec_texts'], res['rec_scores'], res['rec_polys']): ...
有变化 Code-converter rewrite of the classic 2.x loop. rec_texts/rec_scores/rec_polys are parallel lists filtered by text_rec_score_thresh.PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1850-1853

辅助函数 9#

2.x3.x说明(英文)来源
draw_ocr(image, boxes, txts, scores, font_path=...)res.save_to_img(save_path) or res.img['ocr_res_img'] (PIL.Image)已替换 Upgrade notes show res.save_to_img('result') replacing draw_ocr. Custom font: env PADDLE_PDX_LOCAL_FONT_FILE_PATH.paddleocr-2.10.0/paddleocr/tools/infer/utility.py:451-458; PaddleOCR/docs/update/upgrade_notes.en.md:38-48,65-66; PaddleOCR/docs/version3.x/pipeline_usage/OCR.en.md:1872-1881; PaddleOCR/docs/FAQ.en.md:197
draw_structure_result(image, result, font_path)res.save_to_img(save_path)已替换 paddleocr-2.10.0/paddleocr/ppstructure/utility.py:159; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:400
save_structure_res(res, save_folder, img_name)res.save_to_json(p) / res.save_to_xlsx(p) / res.save_to_html(p) / res.save_to_img(p) / res.save_all(p)已替换 paddleocr-2.10.0/paddleocr/ppstructure/predict_system.py:274; paddlex-3.7.2/paddlex/inference/common/result/base_result.py:94-105; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:216,400,526,590
sorted_layout_boxes(res, w)res.save_to_markdown(p) / res.markdown已替换 No public 3.x equivalent function; ordered document output is obtained via the markdown result.paddleocr-2.10.0/paddleocr/ppstructure/recovery/recovery_to_doc.py:87; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:789,797
convert_info_docx(img, res, save_folder, img_name)res.save_to_word(save_path)已替换 paddleocr-2.10.0/paddleocr/ppstructure/recovery/recovery_to_doc.py:32; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:69
convert_info_markdown(res, save_folder, img_name)res.save_to_markdown(save_path) + PPStructureV3.concatenate_markdown_pages()已替换 paddleocr-2.10.0/paddleocr/paddleocr.py:69; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:797; PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:300-301
to_excel(html_table, excel_path)res.save_to_xlsx(save_path)已替换 paddleocr-2.10.0/paddleocr/ppstructure/table/predict_table.py:150; paddlex-3.7.2/paddlex/inference/common/result/mixin.py:590
download_with_progressbar(url, path)—已移除 Models are downloaded automatically to ~/.paddlex/official_models (PADDLE_PDX_CACHE_HOME); source chosen by PADDLE_PDX_MODEL_SOURCE (huggingface default; modelscope, aistudio, bos).paddleocr-2.10.0/paddleocr/__init__.py:20; paddlex-3.7.2/paddlex/utils/cache.py:28-29; paddlex-3.7.2/paddlex/inference/utils/official_models.py:878-886; paddlex-3.7.2/paddlex/utils/flags.py:72
result printing: print(line)res.print() / res.save_to_json(p)有变化 PaddleOCR/docs/update/upgrade_notes.en.md:61-66

命令行 24#

2.x3.x说明(英文)来源
paddleocr --image_dir img.pngpaddleocr ocr -i img.png有变化 3.x requires a subcommand. Without it argparse treats the path as the COMMAND: "paddleocr: error: argument COMMAND: invalid choice: 'img.png' (choose from ...)".PaddleOCR/paddleocr/_cli.py:281-309; PaddleOCR/paddleocr/_utils/cli.py:31-45; paddleocr-2.10.0/paddleocr/paddleocr.py:936-960
paddleocr --image_dir img.png --use_angle_cls truepaddleocr ocr -i img.png --use_textline_orientation True别名,有警告 --use_angle_cls is still accepted by 'paddleocr ocr' with a CLIDeprecationWarning "The option --use_angle_cls has been deprecated and will be removed in the future. ..."PaddleOCR/paddleocr/_pipelines/ocr.py:503-506,567-588; PaddleOCR/paddleocr/_utils/deprecation.py:26-33
--det_model_dir--text_detection_model_dir别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_model_dir and --text_detection_model_dir are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--rec_model_dir--text_recognition_model_dir别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--rec_model_dir and --text_recognition_model_dir are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--cls_model_dir--textline_orientation_model_dir别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--cls_model_dir and --textline_orientation_model_dir are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--det_db_thresh--text_det_thresh别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_db_thresh and --text_det_thresh are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--det_db_box_thresh--text_det_box_thresh别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_db_box_thresh and --text_det_box_thresh are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--det_db_unclip_ratio--text_det_unclip_ratio别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_db_unclip_ratio and --text_det_unclip_ratio are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--det_limit_side_len--text_det_limit_side_len别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_limit_side_len and --text_det_limit_side_len are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--det_limit_type--text_det_limit_type别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--det_limit_type and --text_det_limit_type are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--rec_batch_num--text_recognition_batch_size别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--rec_batch_num and --text_recognition_batch_size are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--cls_batch_num--textline_orientation_batch_size别名,有警告 Deprecated alias on 'paddleocr ocr' only; giving both prints "--cls_batch_num and --textline_orientation_batch_size are mutually exclusive." and exits 2.PaddleOCR/paddleocr/_pipelines/ocr.py:567-600
--use_gpu true|false--device gpu|gpu:0|cpu已替换 --use_gpu is not defined in 3.x -> argparse 'unrecognized arguments'.PaddleOCR/paddleocr/_common_args.py:129-139
--type structurepaddleocr pp_structurev3 -i <file>有变化 PaddleOCR/paddleocr/_pipelines/pp_structurev3.py:695-696; paddleocr-2.10.0/paddleocr/paddleocr.py:388,963-964
--type structure --recovery truepaddleocr pp_structurev3 -i <file> --save_path out/有变化 --save_path calls res.save_all() for each result (all registered save methods).PaddleOCR/paddleocr/_utils/cli.py:41-45,68-73
--det falsepaddleocr text_recognition -i <img>有变化 PaddleOCR/paddleocr/_models/text_recognition.py; paddleocr-2.10.0/paddleocr/paddleocr.py:386
--rec falsepaddleocr text_detection -i <img>有变化 PaddleOCR/paddleocr/_models/text_detection.py:36-38; paddleocr-2.10.0/paddleocr/paddleocr.py:387
--savefile true --output ./out--save_path ./out需改名 paddleocr-2.10.0/paddleocr/paddleocr.py:389,990-995; PaddleOCR/paddleocr/_utils/cli.py:41-45
--lang en--lang en有变化 Same flag on 'paddleocr ocr'; see 'lang' param note on removed script-group codes.PaddleOCR/paddleocr/_pipelines/ocr.py:557-559
--ocr_version PP-OCRv4--ocr_version PP-OCRv3|PP-OCRv4|PP-OCRv5|PP-OCRv6有变化 argparse choices enforced.PaddleOCR/paddleocr/_pipelines/ocr.py:560-565
--use_onnx true--engine onnxruntime (or --enable_hpi True)已替换 PaddleOCR/paddleocr/_common_args.py:140-151
--show_log false—已移除 The 3.x CLI sets the paddleocr logger to INFO itself.PaddleOCR/paddleocr/_cli.py:301-303
--enable_mkldnn / --cpu_threads / --use_tensorrt / --precisionsame flags有变化 Still available on every pipeline/model subcommand; enable_mkldnn default now True.PaddleOCR/paddleocr/_common_args.py:152-188
(3.x) subcommandsocr, doc_preprocessor, doc_understanding, formula_recognition_pipeline, doc_parser (PaddleOCR-VL), pp_chatocrv4_doc, pp_doctranslation, pp_structurev3, seal_recognition, table_recognition_v2, chart_parsing, doc_img_orientation_classification, doc_vlm, formula_recognition, layout_detection, seal_text_detection, table_cells_detection, table_classification, table_structure_recognition, text_detection, text_image_unwarping, text_recognition, textline_orientation_classification, install_hpi_deps, install_genai_server_deps, genai_server (only if the PaddleX genai server plugin imports), doc2md, api有变化 Complete list registered by _get_parser(). Pipeline/model subcommands share -i/--input, --save_path, --device, --engine, --enable_hpi, --use_tensorrt, --precision, --enable_mkldnn, --mkldnn_cache_capacity, --cpu_threads, --enable_cinn (pipelines also --paddlex_config).PaddleOCR/paddleocr/_cli.py:57-123,126-165,168-278,281-294; PaddleOCR/paddleocr/_pipelines/*.py subparser_name; PaddleOCR/paddleocr/_models/*.py subparser_name; PaddleOCR/paddleocr/_api_client/cli.py:30-35; PaddleOCR/paddleocr/_pipelines/base.py:118-131

继续使用 2.x:把 paddleocr 锁定在 3 以下#

如果暂时无法迁移,请在单独的虚拟环境中锁定最后一个 2.x 版本:

python -m pip install "paddleocr<3"

这会解析到 2.10.0。和 3.x 一样,它的 wheel 也没有把 PaddlePaddle 列为依赖,需要你自己安装框架。3 我们没有测试过哪些 PaddlePaddle 3.x 版本能运行 paddleocr 2.x,所以如果你已经有一个能用的 2.x 环境,请把它冻结下来(pip freeze > requirements.txt),而不是重建。导入了 2.x 内部模块(paddleocr.tools、paddleocr.ppocr、paddleocr.ppstructure)的代码只能在 2.x 上运行:3.x 包里没有这些模块。

等待的代价会越来越大:2.x 不会再有新模型,而 3.x 已经从 PP-OCRv5 升级到 PP-OCRv6,还新增了 PaddleOCR-VL。

迁移检查清单#

  1. 新环境,新引擎#

    新建一个 venv。pip install paddleocr,再从飞桨源安装 paddlepaddle==3.2.0,或者安装 onnxruntime。安装命令生成器 会给出适合你机器的准确命令。

  2. 转换代码#

    把每个文件都过一遍 转换工具,处理掉每一个 # TODO(paddleocr 3.x)。

  3. 把警告当成错误跑一次#

    用 python -W error::DeprecationWarning 运行测试,找出残留的别名和 ocr() 调用。

  4. 对比输出#

    在几份真实文档上比较识别文字。如果有差异,先试试“保持 2.x 的行为”那几个开关,再怀疑模型。

  5. 查一查遇到的报错#

    把任何意外的报错粘贴到 报错修复助手。

常见问题#

PaddleOCR 3.x 里 use_angle_cls 还能用吗?

能,但只在 PaddleOCR 上。它是 3.x 会映射到新名称(use_textline_orientation)的 11 个旧名称之一,并会给出 DeprecationWarning。在 PPStructureV3 上它会报 ValueError: Unknown argument: use_angle_cls,而同时传入新旧名称会报“mutually exclusive”错误。

没有 use_gpu,PaddleOCR 3.x 怎么用 GPU?

传入 device='gpu'(或 'gpu:0'、'gpu:1')。不写 device 时,只要安装的 PaddlePaddle 带 CUDA,3.x 就会自动选择 GPU 0。如果仍然在 CPU 上运行,很可能装的是 CPU 版 PaddlePaddle:见 PaddleOCR 没有使用 GPU。

为什么 ocr(img, cls=True) 会报 TypeError?

在 3.x 中 ocr() 只是把参数转发给 predict(),而 predict() 没有 cls 参数。删掉 cls=True,改为在构造函数中设置 use_textline_orientation=True。同时改用 predict();ocr() 已经弃用。

draw_ocr 用什么代替?

每个结果都能自己绘图:res.save_to_img('output') 把可视化结果写到文件夹,res.img['ocr_res_img'] 以 PIL 图片的形式返回。自定义字体请设置 PADDLE_PDX_LOCAL_FONT_FILE_PATH。

还能继续用 paddleocr==2.7.0.3 吗?

可以,只要锁定版本并保留那个能用的环境。它发布于 2023 年 9 月 15 日;2.10.0(2025 年 3 月)是最后一个 2.x 版本。两者都不会再有新模型,而且 2.x 的 API 不能和 3.x 混用在同一个环境里。

在我的代码上运行转换工具安全吗?

它完全在你的浏览器中运行,代码不会被发送到任何地方。它只修改能识别的模式,列出每处改动及其依据的源码行,并在需要人来决定的地方留下 TODO 注释。请像审查其他代码改动一样审查它的修改。

同一张图片,为什么 3.x 的结果和 2.x 不一样?

默认模型不同(PP-OCRv6 取代了 PP-OCRv4),新增了预处理(方向分类、弯曲矫正),也不再有 0.5 的得分过滤。要接近 2.x 的行为,请设置 use_doc_orientation_classify=False、use_doc_unwarping=False、use_textline_orientation=False 和 text_rec_score_thresh=0.5。

参考来源

  1. 为本页阅读的 PaddleOCR 源码,commit dab3fe3(2026-09-16):paddleocr/_pipelines/ocr.py(别名映射第 44-56 行,别名处理 155-169 行,predict()/ocr() 179-241 行)、_common_args.py(第 38-54 行)、_utils/deprecation.py(26-42)、__init__.py(84-131)、_cli.py(57-309)、_pipelines/pp_structurev3.py(32-143)。
  2. 官方升级说明:docs/update/upgrade_notes.en.md(3.x 为何打破兼容;ocr/det/rec、show_log、use_onnx 与 PPStructure 的变化)。
  3. PyPI 上的 paddleocr 2.10.0 wheel(最后一个 2.x 版本):paddleocr/paddleocr.py(ocr() 签名第 696-706 行,返回格式 762-772 行)、tools/infer/utility.py(2.x 默认值)、ppstructure/utility.py。
  4. 2.x 示例代码:docs/version2.x/ppocr/blog/whl.en.md 与 docs/version2.x/ppstructure/quick_start.en.md。
  5. PyPI 上的 PaddleX 3.7.2 wheel:paddlex/configs/pipelines/OCR.yaml(3.x OCR 默认值,第 6-45 行)、paddlex/inference/pipelines/ocr/result.py 与 common/result/(结果对象、保存方法)、inference/models/utils/model_resolver.py(Model name mismatch)。
  6. paddleocr 在 PyPI 上的发布历史,2026-10-27 读取:2.7.0.3(2023-09-15)、2.10.0(2025-03-07,最后一个 2.x)、3.0.0(2025-05-20)、3.7.0(2026-06-11)。
  7. 我们的测试,2026-10-27,Linux x86-64,Python 3.13,paddleocr 3.7.0 + paddlex 3.7.2 + paddlepaddle 3.2.0:本页引用的报错和警告原文、旧命令行写法,以及对转换工具在经典示例和结果循环上的输出的实际运行。
  8. PP-StructureV3 用法与 doc-parser 依赖:PP-StructureV3.en.md;installation.en.md。
  9. OCR 产线参数与结果字段:OCR.en.md(第 1293-1315、1836-1881 行)。
更新于 2026年10月27日·我们如何核实