Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to populate onnx model with custom meta data map ? #214

Closed
ac4922 opened this issue Jun 28, 2019 · 7 comments
Closed

How to populate onnx model with custom meta data map ? #214

ac4922 opened this issue Jun 28, 2019 · 7 comments

Comments

@ac4922
Copy link

ac4922 commented Jun 28, 2019

I have an array which I intend to append in the onnx file itself.

In my opninion, onnxruntime provides an option to retrieve custom meta data map/

from onnxruntime import InferenceSession
sess = InferenceSession(example)
meta = sess.get_modelmeta()
print("custom_metadata_map={}".format(meta.custom_metadata_map))
source - https://microsoft.github.io/onnxruntime/auto_examples/plot_metadata.html#sphx-glr-auto-examples-plot-metadata-py

However, it is always populated empty. My goal is to append some custom_metadata when I convert a scikit learn model to onnx which is available when the onnx is read by onnxruntime.

Please suggest if that is possible and how.

@prabhat00155
Copy link
Contributor

The metadata information actually comes from onnxruntime. Could you file an issue with onnxruntime: https://github.com/microsoft/onnxruntime, they should be able to help you with this?

@ac4922
Copy link
Author

ac4922 commented Jul 15, 2019

@prabhat00155 I opened this in onnxruntime, and they want me to open here.

The information comes from onnxruntime, but that needs to be set while converting the model to the ONNX format. In this use case, I am using sklearn to onnx converter, hence I opened this here.

In my use case, I currently have a pickle file which carries some additional information. I would want to know if that could be serialized in the model itself using model metadatamap.

Thanks

@prabhat00155
Copy link
Contributor

@xadupre could clarify this.

@prabhat00155
Copy link
Contributor

By the way, this is the issue reported in onnxruntime: microsoft/onnxruntime#1315.

@xadupre
Copy link
Collaborator

xadupre commented Jul 17, 2019

skl2onnx does not add any metadata but you can do it we module onnx once the model is converted. It is a list of key value pair where key and value are strings.

meta = model_onnx.metadata_props.add()
meta.key = "key_meta"
meta.value = "value_meta"
print(model_onnx.metadata_props[0])

You need to do that after converting and before saving the ONNX model.

@xadupre
Copy link
Collaborator

xadupre commented Jul 31, 2019

Closing the issue. Feel free to reopen if the proposed solution does not fit your needs.

@xadupre xadupre closed this as completed Jul 31, 2019
@blakechi
Copy link

skl2onnx does not add any metadata but you can do it we module onnx once the model is converted. It is a list of key value pair where key and value are strings.

meta = model_onnx.metadata_props.add()
meta.key = "key_meta"
meta.value = "value_meta"
print(model_onnx.metadata_props[0])

You need to do that after converting and before saving the ONNX model.

Just to add supplemental information. If want to add more than two, one have to call meta = model_onnx.metadata_props.add() again. E.g.:

meta = model_onnx.metadata_props.add()
meta.key = "key_meta_1"
meta.value = "value_meta_1"

meta = model_onnx.metadata_props.add()
meta.key = "key_meta_2"
meta.value = "value_meta_2"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants