🚀 阿拉伯语PP-OCRv3移动识别模型
arabic_PP-OCRv3_mobile_rec是PaddleOCR团队开发的PP-OCRv3_rec系列中的文本行识别模型。该模型是基于PP-OCRv3_mobile_rec训练的特定于阿拉伯字母的模型,支持阿拉伯字母识别。关键准确率指标如下:
模型 |
识别平均准确率(%) |
模型存储大小 (M) |
介绍 |
arabic_PP-OCRv3_mobile_rec |
73.55 |
7.8 M |
基于PP-OCRv3识别模型训练的超轻量级阿拉伯字母识别模型,支持阿拉伯字母和数字字符识别。 |
注意:如果一行中的任何字符(包括标点符号)识别错误,则整行标记为错误。这确保了在实际应用中具有更高的准确性。
🚀 快速开始
📦 安装指南
1. 安装PaddlePaddle
请参考以下命令,使用pip安装PaddlePaddle:
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
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 arabic_PP-OCRv3_mobile_rec \
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/EPkFpN_xkKTh1URMOsjE6.png
你也可以将文本识别模块的模型推理集成到你的项目中。在运行以下代码之前,请将示例图像下载到本地机器。
from paddleocr import TextRecognition
model = TextRecognition(model_name="arabic_PP-OCRv3_mobile_rec")
output = model.predict(input="EPkFpN_xkKTh1URMOsjE6.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/EPkFpN_xkKTh1URMOsjE6.png', 'page_index': None, 'rec_text': 'ددعتم يبرع صن رابتخا ةلاح', 'rec_score': 0.9411801695823669}}
有关使用命令和参数说明的详细信息,请参考文档。
高级用法
单个模型的能力是有限的。但由多个模型组成的管道可以提供更强的能力来解决现实场景中的难题。
PP-OCRv3
通用OCR管道用于解决文本识别任务,通过从图像中提取文本信息并以字符串格式输出。管道中有5个模块:
- 文档图像方向分类模块(可选)
- 文本图像去畸变模块(可选)
- 文本行方向分类模块(可选)
- 文本检测模块
- 文本识别模块
运行以下单个命令,快速体验OCR管道:
paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/Z1WF0PAh9lBnXZdOYE9QL.png \
--text_recognition_model_name arabic_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/Z1WF0PAh9lBnXZdOYE9QL.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([[[ 6, 5],
...,
[ 6, 38]],
[[199, 32],
...,
[200, 68]]], 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([0, 0]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['ددعتم يبرع صن رابتخاةلاح', 'رطسألا'], 'rec_scores': array([0.98472452, 0.99996692]), 'rec_polys': array([[[ 6, 5],
...,
[ 6, 38]],
[[199, 32],
...,
[200, 68]]], dtype=int16), 'rec_boxes': array([[ 6, ..., 38],
[199, ..., 68]], dtype=int16)}}
命令行方法用于快速体验。对于项目集成,也只需要几行代码:
from paddleocr import PaddleOCR
ocr = PaddleOCR(
text_recognition_model_name="arabic_PP-OCRv3_mobile_rec",
use_doc_orientation_classify=False,
use_doc_unwarping=False,
use_textline_orientation=True,
device="gpu:0",
)
result = ocr.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/Z1WF0PAh9lBnXZdOYE9QL.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
指定为arabic_PP-OCRv3_mobile_rec
。你也可以通过参数text_recognition_model_dir
使用本地模型文件。有关使用命令和参数说明的详细信息,请参考文档。
📚 详细文档
📄 许可证
本项目采用Apache-2.0许可证。