ka_PP-OCRv3_mobile_rec 是 PaddleOCR 团队开发的 PP-OCRv3_rec 系列中的文本行识别模型。该模型是在 PP-OCRv3_mobile_rec 的基础上训练得到的特定于卡纳达语的模型,同时支持英文识别。关键精度指标如下:
| 模型 | 识别平均准确率(%) | 模型存储大小(M) | 说明 |
|---|---|---|---|
| ka_PP-OCRv3_mobile_rec | 96.96 | 8.0 M | 基于 PP-OCRv3 识别模型训练的超轻量级卡纳达语识别模型,支持卡纳达语及数字字符识别。 |
注意:若一行文本中存在任意字符(包括标点符号)错误,则整行文本被标记为错误。这确保了在实际应用中具有更高的准确率。
请参考以下命令使用 pip 安装 PaddlePaddle:
# for CUDA11.8
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
# for CUDA12.6
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/
# for CPU
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/关于 PaddlePaddle 的安装详情,请参考 PaddlePaddle 官方网站。
从 PyPI 安装最新版本的 PaddleOCR 推理包:
python -m pip install paddleocr您可以通过一条命令快速体验功能:
paddleocr text_recognition \
--model_name ka_PP-OCRv3_mobile_rec \
-i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/9YOfHM6UfeREpcW9lUxpX.png您还可以将文本识别模块的模型推理功能集成到您的项目中。在运行以下代码之前,请将示例图片下载到您的本地机器。
from paddleocr import TextRecognition
model = TextRecognition(model_name="ka_PP-OCRv3_mobile_rec")
output = model.predict(input="9YOfHM6UfeREpcW9lUxpX.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/9YOfHM6UfeREpcW9lUxpX.png', 'page_index': None, 'rec_text': 'ಕನೃಡಬಹು-ಸಾಲನಪಠೃ', 'rec_score': 0.9466288089752197}}有关使用命令和参数说明的详细信息,请参考文档。
单个模型的能力是有限的。而由多个模型组成的流水线则能够提供更强的能力,以解决实际场景中的复杂问题。
通用OCR流水线用于解决文本识别任务,它通过从图像中提取文本信息并将其以字符串格式输出。该流水线包含5个模块:
运行单个命令即可快速体验OCR流水线:
paddleocr ocr -i https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/yyO4lS4IRG_vwRJts5YCQ.png \
--text_recognition_model_name ka_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/yyO4lS4IRG_vwRJts5YCQ.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([[[ 3, 1],
...,
[ 3, 39]],
[[ 5, 38],
...,
[ 5, 69]]], 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.96122026, 0.99212611]), 'rec_polys': array([[[ 3, 1],
...,
[ 3, 39]],
[[ 5, 38],
...,
[ 5, 69]]], dtype=int16), 'rec_boxes': array([[ 3, ..., 42],
[ 5, ..., 69]], dtype=int16)}}命令行方式适用于快速体验。对于项目集成,同样只需少量代码即可:
from paddleocr import PaddleOCR
ocr = PaddleOCR(
text_recognition_model_name="ka_PP-OCRv3_mobile_rec",
use_doc_orientation_classify=False, # Use use_doc_orientation_classify to enable/disable document orientation classification model
use_doc_unwarping=False, # Use use_doc_unwarping to enable/disable document unwarping module
use_textline_orientation=True, # Use use_textline_orientation to enable/disable textline orientation classification model
device="gpu:0", # Use device to specify GPU for model inference
)
result = ocr.predict("https://cdn-uploads.huggingface.co/production/uploads/681c1ecd9539bdde5ae1733c/yyO4lS4IRG_vwRJts5YCQ.png")
for res in result:
res.print()
res.save_to_img("output")
res.save_to_json("output")pipeline 中使用的默认模型为 PP-OCRv5_server_rec,因此需要通过参数 text_recognition_model_name 将其指定为 ka_PP-OCRv3_mobile_rec。您也可以通过参数 text_recognition_model_dir 使用本地模型文件。有关使用命令和参数说明的详细信息,请参阅 文档。