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;
}``