Skip to main content

onnxmodel-utils

utils for working with onnx models

Example

Simple if model

from onnxmodel_utils import Model, build_if_model


model1 = Model.load('model1.onnx')
model2 = Model.load('model2.onnx')

model = build_if_model(
    "if_model",
    "cond",
    model1,
    model2,
)
model.save('if_model.onnx')


import onnxruntime

sess = onnxruntime.InferenceSession('if_model.onnx')
inps = {
    "input": np.random.randn(1, 3, 224, 224).astype(np.float32),
    "cond": np.array([True]).astype(np.bool),
}
out1 = sess.run(None, inps)

inps["cond"] = np.array([False]).astype(np.bool)
out2 = sess.run(None, inps)

Optional cache model

from onnxmodel_utils import Model, build_if_model_with_cache


decoder = Model.load("decoder.onnx")
decoder_init = Model.load("decoder_init.onnx")

model = build_if_model_with_cache(
    name="merged_model",
    cache_model=decoder,
    cacheless_model=decoder_init,
    cache_names=["pasts", "pasts_st"],
)
model.save("merged_model.onnx")


import onnxruntime
import numpy as np

sess = onnxruntime.InferenceSession("merged_model.onnx")
inps = {
    "input_ids": np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], dtype=np.int64),
    "target_ids": np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], dtype=np.int64),
    "pasts": None,
    "pasts_st": None,
}

init_out = sess.run(None, inps)
inps["pasts"] = init_out[1]
inps["pasts_st"] = init_out[2]

out = sess.run(None, inps)

Installation

pip install onnxmodel-utils

Metadata

Release files for onnxmodel-utils 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onnxmodel-utils 0.0.12
File Size Uploaded Provenance Actions
onnxmodel-utils-0.0.12.tar.gz 25.8 kB Without provenance Details for onnxmodel-utils-0.0.12.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for onnxmodel-utils 0.0.12
File Interpreter ABI Platform Actions
onnxmodel_utils-0.0.12-py3-none-any.whl Python 3 none any Details for onnxmodel_utils-0.0.12-py3-none-any.whl

Total release size: 52.2 kB

Release files / onnxmodel-utils-0.0.12.tar.gz

Download URL onnxmodel-utils-0.0.12.tar.gz
Size 25.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ca3b448cbe500c58352aec3374a686e5da0b3554fe2be502e149187fc263d9c7
BLAKE2b-256 checksum
How to use checksums
93b0bc90bc2c33ae4d22ea7b7dbc9eca3c0d682a05681e6519bc4058981a96e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / onnxmodel_utils-0.0.12-py3-none-any.whl

Download URL onnxmodel_utils-0.0.12-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57ece08f5c0119d91f69d0938dab4bcfe8b84bb4a0f706967971b25fdf3b1304
BLAKE2b-256 checksum
How to use checksums
19cea73f38b48484c2354280b791dc742a3829865830793f1e2e90e22fdbfbad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Security for onnxmodel-utils 0.0.12

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page