-
Here is an example of what I'm trying to translate to C: auto outputTensors = session.onnx.Run(
Ort::RunOptions {nullptr},
inputNames.data(),
inputTensors.data(),
inputTensors.size(),
outputNames.data(),
outputNames.size()
); everything has this API of running a session and the return value is the output tensors, but in C, it returns an here are other examples of similar languages that all have a similar API: audio = self.sess.run(
None,
dict(
tokens=tokens, style=voice, speed=np.ones(1, dtype=np.float32) * speed
),
)[0] let outputs: Vec<Value> = {
let mut inputs = vec![
Value::from_array(session.allocator(), &phoneme_inputs).unwrap(),
Value::from_array(session.allocator(), &input_lengths).unwrap(),
Value::from_array(session.allocator(), &scales).unwrap(),
];
if let Some(ref sid_tensor) = speaker_id {
inputs.push(Value::from_array(session.allocator(), sid_tensor).unwrap());
}
match session.run(inputs) {
Ok(out) => out,
Err(e) => {
return Err(PiperError::OperationError(format!(
"Failed to run model inference. Error: {}",
e
)))
}
}
}; my code in Zig: pub fn run(self: *Self) !void {
// this is just directly calling the C api here
const status = self.ort_api.Run.?(
self.session,
self.run_opts,
self.input_names.ptr,
self.ort_inputs.?.ptr,
self.ort_inputs.?.len,
self.output_names.ptr,
self.output_names.len,
self.ort_outputs.?.ptr,
);
try checkError(self.ort_api, status);
} I would guess that 'output' would be something that I pass into this function and that would be filled with the output, but I have no idea what that is supposed to look like and I'm having trouble finding any information or real world examples of this. If this is the case, I have no idea how I would know the length of the output tensor, either. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can look at how the Java binding calls the C API, it shows how the inputs and outputs are passed in - https://github.com/microsoft/onnxruntime/blob/main/java/src/main/native/ai_onnxruntime_OrtSession.c#L349. |
Beta Was this translation helpful? Give feedback.
You can look at how the Java binding calls the C API, it shows how the inputs and outputs are passed in - https://github.com/microsoft/onnxruntime/blob/main/java/src/main/native/ai_onnxruntime_OrtSession.c#L349.