2021-03-09 18:21:38 +00:00
|
|
|
|
|
|
|
|
.. DO NOT EDIT.
|
|
|
|
|
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
|
|
|
|
|
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
|
|
|
|
|
.. "auto_examples/plot_metadata.py"
|
|
|
|
|
.. LINE NUMBERS ARE GIVEN BELOW.
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
.. only:: html
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
:class: sphx-glr-download-link-note
|
2019-12-21 01:11:46 +00:00
|
|
|
|
2021-03-09 18:21:38 +00:00
|
|
|
Click :ref:`here <sphx_glr_download_auto_examples_plot_metadata.py>`
|
|
|
|
|
to download the full example code
|
2019-12-21 01:11:46 +00:00
|
|
|
|
2021-03-09 18:21:38 +00:00
|
|
|
.. rst-class:: sphx-glr-example-title
|
|
|
|
|
|
|
|
|
|
.. _sphx_glr_auto_examples_plot_metadata.py:
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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*.
|
|
|
|
|
|
2021-03-09 18:21:38 +00:00
|
|
|
.. GENERATED FROM PYTHON SOURCE LINES 16-31
|
2019-12-21 01:11:46 +00:00
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
.. code-block:: default
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
from onnxruntime.datasets import get_example
|
|
|
|
|
example = get_example("logreg_iris.onnx")
|
|
|
|
|
|
|
|
|
|
import onnx
|
|
|
|
|
model = onnx.load(example)
|
|
|
|
|
|
|
|
|
|
print("doc_string={}".format(model.doc_string))
|
|
|
|
|
print("domain={}".format(model.domain))
|
|
|
|
|
print("ir_version={}".format(model.ir_version))
|
|
|
|
|
print("metadata_props={}".format(model.metadata_props))
|
|
|
|
|
print("model_version={}".format(model.model_version))
|
|
|
|
|
print("producer_name={}".format(model.producer_name))
|
|
|
|
|
print("producer_version={}".format(model.producer_version))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. rst-class:: sphx-glr-script-out
|
|
|
|
|
|
|
|
|
|
Out:
|
|
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
|
|
doc_string=
|
|
|
|
|
domain=onnxml
|
|
|
|
|
ir_version=3
|
|
|
|
|
metadata_props=[]
|
|
|
|
|
model_version=0
|
|
|
|
|
producer_name=OnnxMLTools
|
|
|
|
|
producer_version=1.2.0.0116
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-09 18:21:38 +00:00
|
|
|
.. GENERATED FROM PYTHON SOURCE LINES 32-33
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
With *ONNX Runtime*:
|
|
|
|
|
|
2021-03-09 18:21:38 +00:00
|
|
|
.. GENERATED FROM PYTHON SOURCE LINES 33-44
|
2019-12-21 01:11:46 +00:00
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
.. code-block:: default
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
|
2022-01-04 17:32:40 +00:00
|
|
|
import onnxruntime as rt
|
|
|
|
|
sess = rt.InferenceSession(example, providers=rt.get_available_providers())
|
2019-12-21 01:11:46 +00:00
|
|
|
meta = sess.get_modelmeta()
|
|
|
|
|
|
|
|
|
|
print("custom_metadata_map={}".format(meta.custom_metadata_map))
|
|
|
|
|
print("description={}".format(meta.description))
|
|
|
|
|
print("domain={}".format(meta.domain, meta.domain))
|
|
|
|
|
print("graph_name={}".format(meta.graph_name))
|
|
|
|
|
print("producer_name={}".format(meta.producer_name))
|
|
|
|
|
print("version={}".format(meta.version))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. rst-class:: sphx-glr-script-out
|
|
|
|
|
|
|
|
|
|
Out:
|
|
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
|
|
custom_metadata_map={}
|
|
|
|
|
description=
|
|
|
|
|
domain=onnxml
|
|
|
|
|
graph_name=3c59201b940f410fa29dc71ea9d5767d
|
|
|
|
|
producer_name=OnnxMLTools
|
|
|
|
|
version=0
|
|
|
|
|
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. rst-class:: sphx-glr-timing
|
|
|
|
|
|
2022-03-16 01:13:11 +00:00
|
|
|
**Total running time of the script:** ( 0 minutes 0.008 seconds)
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
.. _sphx_glr_download_auto_examples_plot_metadata.py:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. only :: html
|
|
|
|
|
|
|
|
|
|
.. container:: sphx-glr-footer
|
|
|
|
|
:class: sphx-glr-footer-example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
.. container:: sphx-glr-download sphx-glr-download-python
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
:download:`Download Python source code: plot_metadata.py <plot_metadata.py>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
.. container:: sphx-glr-download sphx-glr-download-jupyter
|
2019-12-21 01:11:46 +00:00
|
|
|
|
|
|
|
|
:download:`Download Jupyter notebook: plot_metadata.ipynb <plot_metadata.ipynb>`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.. only:: html
|
|
|
|
|
|
|
|
|
|
.. rst-class:: sphx-glr-signature
|
|
|
|
|
|
2020-08-13 02:12:50 +00:00
|
|
|
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
|