ATLAS Offline Software
Loading...
Searching...
No Matches
get-onnx-metadata.cxx File Reference
#include <onnxruntime_cxx_api.h>
#include <iostream>
#include <cstdint>
Include dependency graph for get-onnx-metadata.cxx:

Go to the source code of this file.

Functions

int main (int narg, char *argv[])

Function Documentation

◆ main()

int main ( int narg,
char * argv[] )

Definition at line 9 of file get-onnx-metadata.cxx.

9 {
10 if (narg != 3 && narg != 2) {
11 std::cout << "usage: " << argv[0] << " <onnx_file> [key]" << std::endl;
12 return 1;
13 }
14
15 //load the onnx model to memory using the path
16 auto env = std::make_unique< Ort::Env >(ORT_LOGGING_LEVEL_ERROR, "");
17
18 // initialize session options if needed
19 Ort::SessionOptions session_options;
20 session_options.SetIntraOpNumThreads(1);
21 session_options.SetGraphOptimizationLevel(
22 GraphOptimizationLevel::ORT_DISABLE_ALL);
23
24 // create session and load model into memory
25 auto session = std::make_unique< Ort::Session >(*env, argv[1],
26 session_options);
27
28 // get metadata
29 Ort::AllocatorWithDefaultOptions allocator;
30 Ort::ModelMetadata metadata = session->GetModelMetadata();
31 if (narg == 2) {
32 std::cout << "keys: ";
33 auto keys = metadata.GetCustomMetadataMapKeysAllocated(allocator);
34 for (uint64_t i = 0; i < keys.size(); i++) {
35 std::cout << keys[i].get();
36 if (i+1 < keys.size()) std::cout << ", ";
37 }
38 std::cout << std::endl;
39 return 2;
40 }
41 auto val = metadata.LookupCustomMetadataMapAllocated(argv[2], allocator);
42 std::cout << val.get() << std::endl;
43
44 return 0;
45}