Skip to main content

paddleOCR的onnx实现

Project description

paddle-onnxocr

安装

pip install --no-cache-dir paddle-onnxocr

使用示例

单次推理

from paddleONNXOCR import PredictSystem
from paddleONNXOCR.predict.ocr_dataclass import OCRResult


async def main():
    """
    推理在线图片
    :return:
    """
    async with PredictSystem() as predictor_system:
        ocr_result: OCRResult = await predictor_system.predict(
            "https://wx2.sinaimg.cn/mw690/005AKOR6ly1hvv14x3e1rj30j615hwfl.jpg"
        )
        print(ocr_result.text)
        print(ocr_result.json)


if __name__ == '__main__':
    import asyncio

    asyncio.run(main())

批量推理

import cv2
from PIL import Image
from typing import AsyncGenerator
from paddleONNXOCR import PredictSystem
from paddleONNXOCR.predict.ocr_dataclass import OCRResult


async def main():
    """
    推理在线图片
    :return:
    """
    async with PredictSystem() as predictor_system:
        ocr_result: AsyncGenerator[OCRResult, None] = predictor_system.predict_batch([
            "https://wx2.sinaimg.cn/mw690/005AKOR6ly1hvv14x3e1rj30j615hwfl.jpg",
            cv2.imread("test.png"),
            Image.open("test.png")
        ])
        async for result in ocr_result:
            if result is not None:
                print(result.text)
                print(result.json)


if __name__ == '__main__':
    import asyncio

    asyncio.run(main())

默认情况下,会自动从modelscope下载以下模型:

PP-LCNet_x0_25_text_line_ori_infer.onnx-->文本行方向检测模型
PP-LCNet_x1_0_doc_ori.onnx->文档方向分类
PP-OCRv5_mobile_det_infer.onnx->文本检测mobile模型
PP-OCRv5_mobile_rec_infer.onnx->文本识别mobile模型

更改模型

from paddleONNXOCR import PredictSystem
from paddleONNXOCR.models_enum import DetModels, RecModels

# 切换成server版本
PredictSystem(det_model_name=DetModels.SERVER, rec_model_name=RecModels.SERVER)

传递本地模型路径

from paddleONNXOCR import PredictSystem

PredictSystem(det_model_path="testDir/xxx.onnx")

模型启用

from paddleONNXOCR import PredictSystem

PredictSystem()
# use_angle_cls: 启用文本放方向检测,默认True
# use_deskew: 启用倾斜图像旋转矫正,默认False
# use_uvdoc: 启用图像矫正,默认False
# use_doc_cls: 启用图像方向分类,默认True

PS:具体参数请点到每一个方法内,有完整解释。

api接口服务

提供了dokcer构建启动的方式. 执行bash命令,自动构建docker服务启动. windows下请使用wsl子系统.

bash run.sh

依赖项目

opencv-python-headless
shapely
pyclipper
onnxruntime
pillow
validators
aiohttp
psutil
deskew
modelscope

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

paddle_onnxocr-0.0.4.tar.gz (73.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paddle_onnxocr-0.0.4-py3-none-any.whl (77.8 kB view details)

Uploaded Python 3

File details

Details for the file paddle_onnxocr-0.0.4.tar.gz.

File metadata

  • Download URL: paddle_onnxocr-0.0.4.tar.gz
  • Upload date:
  • Size: 73.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for paddle_onnxocr-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b6a79db753b90ee7c83601f888d79d796fa514632fa1ec718e6ef6ced3ca8548
MD5 36d80d11a1e2ceb842fc5ce2efbe3994
BLAKE2b-256 f00b073fbc7be0ecc7702931b72ce7c34c1f198ffb766de396c396524b79bc9e

See more details on using hashes here.

File details

Details for the file paddle_onnxocr-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: paddle_onnxocr-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 77.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for paddle_onnxocr-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bb5a260248d51a1e4ce5c7f42915835f0413a1854fcb09232e80e9bbb549e713
MD5 2dff38e54085e538ba6545cc6d9b1e1e
BLAKE2b-256 0280e935bbffd98c3b73a1d832ce6f1ca50188c4418175ea4ed1b51a8926b215

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page