Metadata#

ONNX format contains metadata related to how the model was produced. It is useful when the model is deployed to production to keep track of which instance was used at a specific time. Let’s see how to do that with a simple logistic regression model trained with scikit-learn and converted with sklearn-onnx.

from onnxruntime.datasets import get_example

example = get_example("logreg_iris.onnx")

import onnx  # noqa: E402

model = onnx.load(example)

print(f"doc_string={model.doc_string}")
print(f"domain={model.domain}")
print(f"ir_version={model.ir_version}")
print(f"metadata_props={model.metadata_props}")
print(f"model_version={model.model_version}")
print(f"producer_name={model.producer_name}")
print(f"producer_version={model.producer_version}")
doc_string=
domain=onnxml
ir_version=3
metadata_props=[]
model_version=0
producer_name=OnnxMLTools
producer_version=1.2.0.0116

With ONNX Runtime:

import onnxruntime as rt  # noqa: E402

sess = rt.InferenceSession(example, providers=rt.get_available_providers())
meta = sess.get_modelmeta()

print(f"custom_metadata_map={meta.custom_metadata_map}")
print(f"description={meta.description}")
print(f"domain={meta.domain}")
print(f"graph_name={meta.graph_name}")
print(f"producer_name={meta.producer_name}")
print(f"version={meta.version}")
custom_metadata_map={}
description=
domain=onnxml
graph_name=3c59201b940f410fa29dc71ea9d5767d
producer_name=OnnxMLTools
version=0

Total running time of the script: (0 minutes 0.004 seconds)

Gallery generated by Sphinx-Gallery