-1

This in the c++ code where I try to extract and print the metadata of a ONNX model. Loading the onnx model works perfectly but I can't extract the model's metadata. I am using ort version 1.14.0

`

// Load the ONNX model
    Ort::SessionOptions session_options;
    std::string instanceName{ "Cut-in prediction inference" };
    Ort::Env env{ OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING, instanceName.c_str() };

Ort::Session onnx_session{ nullptr };

onnx_session = { env, L"CIP.onnx", Ort::SessionOptions{nullptr}};

//Extract the metadata 

Ort::ModelMetadata model_metadata = onnx_session.GetModelMetadata(); //this is the only part of `your text`extarcting metadata that doesn't generate an error `

I tried to solve the problem using CustomMetadataMap& and metadata.custom_metadata property, but both implementation generae errors like 'CustomMetadataMap': is not a member of 'Ort::ModelMetadata'.

Some code I tried:

1)------

`Ort::ModelMetadata model_metadata = onnx_session.GetModelMetadata();
    
    std::stringstream metadata_ss;
    metadata_ss << "ONNX model metadata:" << std::endl;
    for (auto& kv : model_metadata.custom_metadata_map) {
        metadata_ss << "    " << kv.first << ": " << kv.second << std::endl;
    }`

2)------

`td::unique_ptr<Ort::CustomMetadataProvider> metadata_provider = session.GetModelMetadata().LookupCustomMetadataMapAllocated();

if (metadata_provider) {
    // Get the metadata properties
    const std::unordered_map<std::string, std::string>& metadata_map = metadata_provider->GetMetadata();
    for (auto it = metadata_map.begin(); it != metadata_map.end(); ++it) {
        std::string key = it->first;
        std::string value = it->second;
        std::cout << "Metadata property: " << key << " = " << value << std::endl;
    }``
bb45678
  • 1
  • 1

1 Answers1

0

I tried with following steps by creating Metadata instance and the using session API. Still MetaData is giving this value -- > 000001FE692A1260

bool CheckStatus(const OrtApi* g_ort, OrtStatus* status) {
    if (status != nullptr) {
        const char* msg = g_ort->GetErrorMessage(status);
        std::cerr << msg << std::endl;
        g_ort->ReleaseStatus(status);
        throw Ort::Exception(msg, OrtErrorCode::ORT_EP_FAIL);
    }
    return true;
}

    OrtModelMetadata* Meta_data;
    CheckStatus(g_ort, g_ort->SessionGetModelMetadata(session, &Meta_data));
  • Since this doesn't sound like a solution, it shouldn't be an answer, but provided as an update to your question. – Opux Mar 21 '23 at 20:30