2018-11-19 16:48:22 -08:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
# Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
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.
|
2023-03-24 15:29:03 -07:00
|
|
|
Let's see how to do that with a simple
|
2018-11-19 16:48:22 -08:00
|
|
|
logistic regression model trained with
|
2019-01-11 12:41:42 +01:00
|
|
|
*scikit-learn* and converted with *sklearn-onnx*.
|
2018-11-19 16:48:22 -08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from onnxruntime.datasets import get_example
|
2022-04-26 09:35:16 -07:00
|
|
|
|
2018-11-19 16:48:22 -08:00
|
|
|
example = get_example("logreg_iris.onnx")
|
|
|
|
|
|
2023-03-24 15:29:03 -07:00
|
|
|
import onnx # noqa: E402
|
2022-04-26 09:35:16 -07:00
|
|
|
|
2018-11-19 16:48:22 -08:00
|
|
|
model = onnx.load(example)
|
|
|
|
|
|
2023-03-24 15:29:03 -07:00
|
|
|
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}")
|
2018-11-19 16:48:22 -08:00
|
|
|
|
|
|
|
|
#############################
|
|
|
|
|
# With *ONNX Runtime*:
|
|
|
|
|
|
2023-03-24 15:29:03 -07:00
|
|
|
import onnxruntime as rt # noqa: E402
|
2022-04-26 09:35:16 -07:00
|
|
|
|
2021-11-30 15:26:10 -08:00
|
|
|
sess = rt.InferenceSession(example, providers=rt.get_available_providers())
|
2018-11-19 16:48:22 -08:00
|
|
|
meta = sess.get_modelmeta()
|
|
|
|
|
|
2023-03-24 15:29:03 -07:00
|
|
|
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}")
|