模型概述
模型特點
模型能力
使用案例
🚀 PP-OCRv3_mobile_rec
PP-OCRv3_mobile_rec 是 PaddleOCR 團隊開發的 PP-OCRv3_rec 系列中的文本行識別模型。PP-OCRv3 是對 PP-OCRv2 的升級,整體框架保留了與 PP-OCRv2 相同的流程,並對檢測和識別模型進行了優化。檢測模塊仍基於 DB 算法進行優化,而識別模塊則用最新的文本識別算法 SVTR(該算法於 2022 年被 IJCAI 接收並已適配工業應用)取代了 CRNN。它支持一般中英文場景下的文本行識別,但主要側重於中文。關鍵準確率指標如下:
✨ 主要特性
PP-OCRv3_mobile_rec 具有以下顯著特性:
- 模型升級:PP-OCRv3 是對 PP-OCRv2 的升級版本,在檢測和識別模型上進行了優化。
- 算法改進:識別模塊採用了最新的 SVTR 算法,替代了 CRNN,提升了識別性能。
- 多語言支持:支持中文和英文文本行識別,尤其專注於中文場景。
- 輕量級設計:模型存儲大小僅為 11M,推理效率高,適合在各種硬件設備(包括邊緣設備)上部署。
模型 | 識別平均準確率(%) | 模型存儲大小 (M) | 說明 |
---|---|---|---|
PP-OCRv3_mobile_rec | 75.43 | 11 M | PP-OCRv3 的輕量級識別模型,推理效率高,適合在各種硬件設備(包括邊緣設備)上部署。 |
⚠️ 重要提示
如果一行中的任何字符(包括標點符號)識別錯誤,則整行將被標記為錯誤,以確保在實際應用中具有更高的準確性。
📦 安裝指南
安裝 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 官方網站。
安裝 PaddleOCR
從 PyPI 安裝最新版本的 PaddleOCR 推理包:
python -m pip install paddleocr
💻 使用示例
基礎用法
你可以使用單個命令快速體驗該功能:
paddleocr text_recognition \
--model_name PP-OCRv3_mobile_rec \
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/QmaPtftqwOgCtx0AIvU2z.png
你也可以將文本識別模塊的模型推理集成到你的項目中。在運行以下代碼之前,請將示例圖像下載到本地機器:
from paddleocr import TextRecognition
model = TextRecognition(model_name="PP-OCRv3_mobile_rec")
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.9425019025802612}}
可視化圖像如下:
有關使用命令和參數說明的詳細信息,請參考 文檔。
高級用法
單個模型的能力是有限的,但由多個模型組成的管道可以提供更強的能力來解決現實場景中的難題。
PP-OCRv3 管道使用
通用 OCR 管道用於通過從圖像中提取文本信息並以字符串格式輸出,來解決文本識別任務。管道中包含 5 個模塊:
- 文檔圖像方向分類模塊(可選)
- 文本圖像矯正模塊(可選)
- 文本行方向分類模塊(可選)
- 文本檢測模塊
- 文本識別模塊
運行單個命令快速體驗 OCR 管道:
paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/818ebrVG4OtH3sjLR-NRI.png \
--text_recognition_model_name PP-OCRv3_mobile_rec \
--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': ['國小00-8822668', 'SSO', '登機牌', 'BOARDING', '座位號', 'SEAT NO.', '艙位', 'CLASS', '序號', '日期 DATE', 'SERIAL NO.', '航班 FLIGHT', 'W', '035', 'MU237903DEC', '始發地', 'FROM', '登機口', 'GATE', '登機時間 BDT', '目的地TO', '福州', 'TAIYUAN', 'G11', 'FUZHOU', '身份識別IDNO.', '姓名', 'NAME', 'ZHANGQIWEI', '票號TKT NO.', '張祺偉', '票價FARE', 'ETKT7813699238489/1', '登機口於起飛前1O分鐘關閉 GATES CLOSE 1O MINUTES BEFOREDEPARTURE TIME'], 'rec_scores': array([0.51543897, ..., 0.91532207]), '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-OCRv3_mobile_rec",
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-OCRv3_mobile_rec
。你也可以通過參數 text_recognition_model_dir
使用本地模型文件。有關使用命令和參數說明的詳細信息,請參考 文檔。
📚 詳細文檔
📄 許可證
本項目採用 Apache-2.0 許可證。











