Skip to content

Commit 7cbdd87

Browse files
author
liumingyue
committed
Update C++ example code
1 parent 08f2c82 commit 7cbdd87

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

docs/execution-providers/Vitis-AI-ExecutionProvider.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ To leverage the C++ APIs, use the following example as a reference:
102102

103103
```c++
104104
// ...
105-
#include <experimental_onnxruntime_cxx_api.h>
105+
#include <onnxruntime_cxx_api.h>
106106
// include user header files
107107
// ...
108108

109-
auto onnx_model_path = "resnet50.onnx" // Replace resnet50.onnx with your model name
109+
std::basic_string<ORTCHAR_T> model_file = "resnet50.onnx" // Replace resnet50.onnx with your model name
110110
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "resnet50_pt");
111111
auto session_options = Ort::SessionOptions();
112112

@@ -119,19 +119,28 @@ options["log_level"] = "info";
119119
// Create an inference session using the Vitis AI execution provider
120120
session_options.AppendExecutionProvider_VitisAI(options);
121121

122-
auto session = Ort::Experimental::Session(env, model_name, session_options);
123-
124-
auto input_shapes = session.GetInputShapes();
125-
// preprocess input data
126-
// ...
127-
122+
auto session = Ort::Session(env, model_file.c_str(), session_options);
123+
124+
// get inputs and outputs
125+
Ort::AllocatorWithDefaultOptions allocator;
126+
std::vector<std::string> input_names;
127+
std::vector<std::int64_t> input_shapes;
128+
auto input_count = session.GetInputCount();
129+
for (std::size_t i = 0; i < input_count; i++) {
130+
input_names.emplace_back(session.GetInputNameAllocated(i, allocator).get());
131+
input_shapes = session.GetInputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape();
132+
}
133+
std::vector<std::string> output_names;
134+
auto output_count = session.GetOutputCount();
135+
for (std::size_t i = 0; i < output_count; i++) {
136+
output_names.emplace_back(session.GetOutputNameAllocated(i, allocator).get());
137+
}
128138
// Create input tensors and populate input data
129139
std::vector<Ort::Value> input_tensors;
130-
input_tensors.push_back(Ort::Experimental::Value::CreateTensor<float>(
131-
input_data.data(), input_data.size(), input_shapes[0]));
140+
...
132141

133-
auto output_tensors = session.Run(session.GetInputNames(), input_tensors,
134-
session.GetOutputNames());
142+
auto output_tensors = session.Run(Ort::RunOptions(), input_names.data(), input_tensors.data(),
143+
input_count, output_names.data(), output_count);
135144
// postprocess output data
136145
// ...
137146

0 commit comments

Comments
 (0)