Article ID: 000090966 Content Type: Error Messages Last Reviewed: 11/13/2023

Unable to Get Output Tensors of Custom Model That Has Three Outputs

Environment

OpenVINO™ 2022.1.0

BUILT IN - ARTICLE INTRO SECOND COMPONENT
Summary

Correct way to get output tensor for model that has more than one output

Description
  • 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.

Resolution

The ov::InferRequest::get_output_tensor method without arguments can be used for model with only one output.

  1. 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)

  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)

Related Products

This article applies to 1 products