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)
if __name__ == '__main__':
import asyncio
asyncio.run(main())
批量推理
import cv2
from PIL import Image
from paddleONNXOCR import PredictSystem
async def main():
"""
推理在线图片
:return:
"""
async with PredictSystem() as predictor_system:
ocr_result =await predictor_system.predict_batch([
"https://wx2.sinaimg.cn/mw690/005AKOR6ly1hvv14x3e1rj30j615hwfl.jpg",
cv2.imread("test.png"),
Image.open("test.png")
])
print(ocr_result)
if __name__ == '__main__':
import asyncio
asyncio.run(main())
单例调用
from paddleONNXOCR import PredictSystem
async def main():
predictor_system = PredictSystem()
await predictor_system.__aenter__()
return predictor_system
# 外部拿到实力调用推理,参考api/__init__.py中的lifespan
默认情况下,会自动从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
deskew
modelscope
filetype
pdfplumber
aiofiles
Project details
Release history Release notifications | RSS feed
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.10.tar.gz
(89.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file paddle_onnxocr-0.0.10.tar.gz.
File metadata
- Download URL: paddle_onnxocr-0.0.10.tar.gz
- Upload date:
- Size: 89.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
839ed21c610f1c1cd8a01a9260381bf126a598fec8c3aa99363851b8240ae16a
|
|
| MD5 |
f1cf177b65c33469cdd36c662a77a5c0
|
|
| BLAKE2b-256 |
740019ec495ea103ce875184a2abf02e4f933006928c422b3328004a7927e043
|
File details
Details for the file paddle_onnxocr-0.0.10-py3-none-any.whl.
File metadata
- Download URL: paddle_onnxocr-0.0.10-py3-none-any.whl
- Upload date:
- Size: 98.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
baeba1a8e05cce6f29fb0fba15d7f4a0e19b0dfb0b3ac40b7d84b2204bbf8b3d
|
|
| MD5 |
3266e674cf4de1e19f6da7d1e4a89573
|
|
| BLAKE2b-256 |
c8b96eb7e337f44dbdd125a1ad82f1ffa25d4b4e99cf1c0b17bb5b05eba7e40c
|