Onnx Donut
Package to export a Donut model from pytorch to ONNX, then run it with onnxruntime.
Installation
pip install onnx-donut
Export to onnx
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
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)
Metadata
Release files for onnx-donut 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| onnx_donut-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for onnx_donut-0.1.0-py3-none-any.whl |
Release files / onnx_donut-0.1.0-py3-none-any.whl
| Download URL | onnx_donut-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4bc5811952ccd82b2efda75ec02a1fb7680a099ff41d0629c8c2a8ecbd7c6e7
|
|
BLAKE2b-256 checksum How to use checksums |
61b4451832aa4ee719e68b6d155b7544f502a3c4b0859fe2b03020f9a1b87ca6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for onnx-donut 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.