openvinotoolkit/openvino

How to get the metadata_props information from the model of onnx format with OpenVINO?

SWHL opened this issue · 2 comments

SWHL commented

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!

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 commented

Thanks.