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)

依赖项目

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.3.tar.gz (71.9 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.3-py3-none-any.whl (76.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for paddle_onnxocr-0.0.3.tar.gz
Algorithm Hash digest
SHA256 9dbac24098d4c0f874ad063edfa94fcfe2407760bdcd368d1e42474d86a2699c
MD5 ebf04f02d0783210a3f7ae152bcea675
BLAKE2b-256 70f2f562d718b591f8d4a818895fb129e43f9321defccb3ea0929176379528ab

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for paddle_onnxocr-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8e581797c9f691ffdc87ff6f9c5c1887935066fe583534b2de6161937e418adf
MD5 2495f53954c5b3be2ce5d1772df8ac5f
BLAKE2b-256 e57bd41ec47a501670ca24c974c9994f12a5477dd6cc58249f5ce15d8cd9f23c

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