模型简介
模型特点
模型能力
使用案例
🚀 PP-OCRv4_server_rec_doc
PP-OCRv4_server_rec_doc是基于PP-OCRv4_server_rec,在更多中文文档数据和PP-OCR训练数据的混合数据集上训练得到的。它增强了对一些繁体字、日文字符和特殊符号的识别能力,支持超过15000个字符。除了提升与文档相关的文本识别能力外,它还增强了通用文本识别能力。
🚀 快速开始
📦 安装指南
1. 安装PaddlePaddle
请参考以下命令,使用pip安装PaddlePaddle:
# 适用于CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
# 适用于CUDA12.6
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
# 适用于CPU
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
PaddlePaddle安装详情请参考 PaddlePaddle官方网站。
2. 安装PaddleOCR
从PyPI安装最新版本的PaddleOCR推理包:
python -m pip install paddleocr
💻 使用示例
基础用法
你可以使用单条命令快速体验其功能:
paddleocr text_recognition \
--model_name PP-OCRv4_server_rec_doc \
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/QmaPtftqwOgCtx0AIvU2z.png
你也可以将文本识别模块的模型推理集成到你的项目中。在运行以下代码之前,请将示例图像下载到本地。
from paddleocr import TextRecognition
model = TextRecognition(model_name="PP-OCRv4_server_rec_doc")
output = model.predict(input="QmaPtftqwOgCtx0AIvU2z.png", batch_size=1)
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")
运行后,得到的结果如下:
{'res': {'input_path': '/root/.paddlex/predict_input/QmaPtftqwOgCtx0AIvU2z.png', 'page_index': None, 'rec_text': 'the number of model parameters and FLOPs get larger, it', 'rec_score': 0.9796906113624573}}
可视化图像如下:
使用命令和参数说明详情请参考 文档。
高级用法
单个模型的能力是有限的,但由多个模型组成的管道可以提供更强的能力来解决现实场景中的难题。
PP-OCRv4
通用OCR管道用于通过从图像中提取文本信息并以字符串格式输出,来解决文本识别任务。管道中有5个模块:
- 文档图像方向分类模块(可选)
- 文本图像矫正模块(可选)
- 文本行方向分类模块(可选)
- 文本检测模块
- 文本识别模块
运行单条命令快速体验OCR管道:
paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/818ebrVG4OtH3sjLR-NRI.png \
--text_recognition_model_name PP-OCRv4_server_rec_doc \
--use_doc_orientation_classify False \
--use_doc_unwarping False \
--use_textline_orientation True \
--save_path ./output \
--device gpu:0
结果会打印到终端:
{'res': {'input_path': '/root/.paddlex/predict_input/818ebrVG4OtH3sjLR-NRI.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': True, 'use_textline_orientation': True}, 'doc_preprocessor_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_orientation_classify': False, 'use_doc_unwarping': False}, 'angle': -1}, 'dt_polys': array([[[ 0, 10],
...,
[ 0, 72]],
...,
[[189, 915],
...,
[190, 960]]], dtype=int16), 'text_det_params': {'limit_side_len': 64, 'limit_type': 'min', 'thresh': 0.3, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 1.5}, 'text_type': 'general', 'textline_orientation_angles': array([1, ..., 0]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['国8866', 'PPSS', '登机牌', 'BOARDING', '座位号', 'SEAT NO.', '舱位', 'CLASS', '序号', '日期DATE', 'SERIAL NO.', '航班FLIGHT', 'W', '035', 'MU237903DEC', '始发地', 'FROM', '登机口', 'GATE', '登机时间BDT', '目的地TO', '福州', 'TAIYUAN', 'G11', 'FUZHOU', '身份识别IDNO.', '姓名', 'NAME', 'ZHANGQIWEI', '票号TKTNO.', '张祺伟', '票价FARE', 'ETKT7813699238489/1', '登机口于起飞前1O分钟关闭 GATESCLOSE1OMINUTESBEFOREDEPARTURETIME'], 'rec_scores': array([0.80317128, ..., 0.96791613]), 'rec_polys': array([[[ 0, 10],
...,
[ 0, 72]],
...,
[[189, 915],
...,
[190, 960]]], dtype=int16), 'rec_boxes': array([[ 0, ..., 72],
...,
[189, ..., 960]], dtype=int16)}}
如果指定了save_path
,可视化结果将保存在save_path
下。可视化输出如下:
命令行方法用于快速体验。对于项目集成,也只需要几行代码:
from paddleocr import PaddleOCR
ocr = PaddleOCR(
text_recognition_model_name="PP-OCRv4_server_rec_doc",
use_doc_orientation_classify=False, # 使用use_doc_orientation_classify启用/禁用文档方向分类模型
use_doc_unwarping=False, # 使用use_doc_unwarping启用/禁用文档矫正模块
use_textline_orientation=True, # 使用use_textline_orientation启用/禁用文本行方向分类模型
device="gpu:0", # 使用device指定GPU进行模型推理
)
result = ocr.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/818ebrVG4OtH3sjLR-NRI.png")
for res in result:
res.print()
res.save_to_img("output")
res.save_to_json("output")
管道中默认使用的模型是PP-OCRv5_server_rec
,因此需要通过参数text_recognition_model_name
指定为PP-OCRv4_server_rec_doc
。你也可以通过参数text_recognition_model_dir
使用本地模型文件。使用命令和参数说明详情请参考 文档。
✨ 主要特性
PP-OCRv4_server_rec_doc具有以下主要特性:
- 基于PP-OCRv4_server_rec在混合数据集上训练,增强了对繁体字、日文字符和特殊符号的识别能力。
- 支持超过15000个字符,提升了文档相关文本和通用文本的识别能力。
📚 详细文档
属性 | 详情 |
---|---|
模型类型 | PP-OCRv4_server_rec_doc |
训练数据 | 更多中文文档数据和PP-OCR训练数据的混合数据集 |
📄 许可证
本项目采用Apache-2.0许可证。
🔗 相关链接
⚠️ 重要提示
如果一行中的任何字符(包括标点符号)识别错误,则整行将被标记为错误。这确保了在实际应用中具有更高的准确性。










