Name | onnx-donut JSON |
Version |
0.1.0
JSON |
| download |
home_page | |
Summary | Export Donut model to onnx and run it with onnxruntime |
upload_time | 2023-11-20 14:39:29 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.9 |
license | |
keywords |
donut
onnx
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Onnx Donut
Package to export a [Donut](https://github.com/clovaai/donut) model from pytorch to ONNX, then run it with onnxruntime.
## Installation
```shell
pip install onnx-donut
```
## Export to onnx
```python
from onnx_donut.exporter import export_onnx
from onnx_donut.quantizer import quantize
# Hugging Face model card or folder
model_path = "naver-clova-ix/donut-base-finetuned-docvqa"
# Folder where the exported model will be stored
dst_folder = "converted_donut"
# Export from Pytorch to ONNX
export_onnx(model_path, dst_folder, opset_version=16)
# Quantize your model to int8
quantize(dst_folder, dst_folder + "_quant")
```
## Model inference with onnxruntime
```python
from onnx_donut.predictor import OnnxPredictor
import numpy as np
from PIL import Image
# Image path to run on
img_path = "/path/to/your/image.png"
# Folder where the exported model will be stored
onnx_folder = "converted_donut"
# Read image
img = np.array(Image.open(img_path).convert('RGB'))
# Instantiate ONNX predictor
predictor = OnnxPredictor(model_folder=onnx_folder, sess_options=options)
# Write your prompt accordingly to the model you use
prompt = f"<s_docvqa><s_question>what is the title?</s_question><s_answer>"
# Run prediction
out = predictor.generate(img, prompt)
# Display prediction
print(out)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "onnx-donut",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "donut,onnx",
"author": "",
"author_email": "Ambroise Berthe <ambroise.berthe@ikomia.ai>",
"download_url": "",
"platform": null,
"description": "# Onnx Donut\n\nPackage to export a [Donut](https://github.com/clovaai/donut) model from pytorch to ONNX, then run it with onnxruntime.\n\n## Installation\n\n```shell\npip install onnx-donut\n```\n\n## Export to onnx\n\n```python\nfrom onnx_donut.exporter import export_onnx\nfrom onnx_donut.quantizer import quantize\n\n# Hugging Face model card or folder\nmodel_path = \"naver-clova-ix/donut-base-finetuned-docvqa\"\n\n# Folder where the exported model will be stored\ndst_folder = \"converted_donut\"\n\n# Export from Pytorch to ONNX\nexport_onnx(model_path, dst_folder, opset_version=16)\n\n# Quantize your model to int8\nquantize(dst_folder, dst_folder + \"_quant\")\n\n```\n\n## Model inference with onnxruntime\n\n```python\nfrom onnx_donut.predictor import OnnxPredictor\nimport numpy as np\nfrom PIL import Image\n\n# Image path to run on\nimg_path = \"/path/to/your/image.png\"\n\n# Folder where the exported model will be stored\nonnx_folder = \"converted_donut\"\n\n# Read image\nimg = np.array(Image.open(img_path).convert('RGB'))\n\n# Instantiate ONNX predictor\npredictor = OnnxPredictor(model_folder=onnx_folder, sess_options=options)\n\n# Write your prompt accordingly to the model you use\nprompt = f\"<s_docvqa><s_question>what is the title?</s_question><s_answer>\"\n\n# Run prediction\nout = predictor.generate(img, prompt)\n\n# Display prediction\nprint(out)\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Export Donut model to onnx and run it with onnxruntime",
"version": "0.1.0",
"project_urls": null,
"split_keywords": [
"donut",
"onnx"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "61b4451832aa4ee719e68b6d155b7544f502a3c4b0859fe2b03020f9a1b87ca6",
"md5": "776de58e1fd007355bacb68c1bd038a7",
"sha256": "e4bc5811952ccd82b2efda75ec02a1fb7680a099ff41d0629c8c2a8ecbd7c6e7"
},
"downloads": -1,
"filename": "onnx_donut-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "776de58e1fd007355bacb68c1bd038a7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10714,
"upload_time": "2023-11-20T14:39:29",
"upload_time_iso_8601": "2023-11-20T14:39:29.888395Z",
"url": "https://files.pythonhosted.org/packages/61/b4/451832aa4ee719e68b6d155b7544f502a3c4b0859fe2b03020f9a1b87ca6/onnx_donut-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-20 14:39:29",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "onnx-donut"
}