#include <onnxruntime_cxx_api.h>
#include <iostream>
#include <cstdint>
Go to the source code of this file.
|
| int | main (int narg, char *argv[]) |
◆ 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
16 auto env = std::make_unique< Ort::Env >(ORT_LOGGING_LEVEL_ERROR,
"");
17
18
19 Ort::SessionOptions session_options;
20 session_options.SetIntraOpNumThreads(1);
21 session_options.SetGraphOptimizationLevel(
22 GraphOptimizationLevel::ORT_DISABLE_ALL);
23
24
25 auto session = std::make_unique< Ort::Session >(*env, argv[1],
26 session_options);
27
28
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}