File: plot_metadata.py

package info (click to toggle)
onnxruntime 1.21.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 333,732 kB
  • sloc: cpp: 3,153,079; python: 179,219; ansic: 109,131; asm: 37,791; cs: 34,424; perl: 13,070; java: 11,047; javascript: 6,330; pascal: 4,126; sh: 3,277; xml: 598; objc: 281; makefile: 59
file content (46 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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.
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}")

#############################
# 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}")