ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
JetTagging
FlavorTagDiscriminants
util
get-onnx-metadata.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <onnxruntime_cxx_api.h>
6
#include <iostream>
7
#include <cstdint>
8
9
int
main
(
int
narg,
char
* argv[]) {
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
}
main
int main()
Definition
hello.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0