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 get the metadata_props information from the model of onnx format with OpenVINO? #12596

Closed
2 tasks done
SWHL opened this issue Aug 17, 2022 · 2 comments
Closed
2 tasks done
Assignees

Comments

@SWHL
Copy link

SWHL commented Aug 17, 2022

Description:

I put some information into the onnx metadata_props by the onnx package (model link):

import onnx

def onnx_add_metadata(model, key, value):
    meta = model.metadata_props.add()
    meta.key = key
    meta.value = value
    return model

onnx_path = 'super_resolution.onnx'

model = onnx.load_model(onnx_path)

model = onnx_add_metadata(model, key='shape', value='[3,48,320]')
onnx.save_model(model, 'super_resolution_with_metadata.onnx')

Get metadata by the onnxruntime package.

import onnxruntime

onnx_path = 'super_resolution_with_metadata.onnx'
sess = onnxruntime.InferenceSession(onnx_path)

meta_map = sess.get_modelmeta().custom_metadata_map
print(meta_map)
# {'shape': '[3,48,320]'}

Question: How to get the metadata info by OpenVINO?

  • Have you checked the OpenVINO documentation? → Not found.
  • Have you checked whether the same issue exists? → Not found.

Thanks!

@tomdol
Copy link
Contributor

tomdol commented Aug 17, 2022

Hi,

Unfortunately the OV API doesn't allow extracting this information from the model. It's under discussion right now and it should be available in one of the future releases.

You can use the ModelProto object's API to extract the ONNX metadata though. Here's a C++ snippet which does exactly that https://gist.github.com/tomdol/8dae97218a8a9e56cb12919dd3e026d4. You can do something similar in Python by iterating over model.metadata_props where the model is a result of onnx.load_model() function call.

@SWHL
Copy link
Author

SWHL commented Aug 17, 2022

Thanks.

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

2 participants