def get_metadata(self):
        try:
            sess = InferenceSession(self.saved_path + self.file_name)
        except os.error as err:
            print("OS error: {0}".format(err))
            sys.exit()
        except:
            print("Error: Load " + self.file_name + " model first.")
            sys.exit()

        try:
            meta = sess.get_modelmeta()
        except os.error as err:
            print("OS error: {0}".format(err))
            sys.exit()
        except:
            print("Error: " + self.file_name + " model metadata is too big.")
            sys.exit()

        if meta is not None:
            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))
        else:
            print("Metadata does not exist")
Beispiel #2
0
*scikit-learn* and converted with *onnxmltools*.
"""

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))

#############################
# With *ONNX Runtime*:

from onnxruntime import InferenceSession
sess = InferenceSession(example)
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))