Correct way to get output tensor for model that has more than one output
- Got output tensor for custom model that has three outputs:
from openvino.runtime import Core
core = Core()
model = core.read_model(model="model.xml")
compiled_model = core.compile_model(model, "CPU")
infer_request = compiled_model.create_infer_request()
infer_request.start_async()
infer_request.wait()
output = infer_request.get_output_tensor()
print(output) - Received error:
RuntimeError: get_output_tensor() must be called on a function with exactly one parameter.
The ov::InferRequest::get_output_tensor method without arguments can be used for model with only one output.
- Use ov::InferRequest::get_output_tensor method with argument (index: int) for model that has more than one output.
output1 = infer_request.get_output_tensor(0)
output2 = infer_request.get_output_tensor(1)
output3 = infer_request.get_output_tensor(2) - Use the data attribute of the Tensor object to access the output tensor data for the inference results.
output_buffer1 = output2.data
output_buffer2 = output2.data
output_buffer3 = output3.data
print(output_buffer1)
print(output_buffer2)
print(output_buffer3)