microsoft / microsoft/onnxruntime

[Documentation] How to get correct outputTensor shape in C++?

Open
#13,133 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api documentation
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 8h
Merged PRs (30d)
179

Description

Describe the documentation issue

I have inference on a model like this:

image

the input is fixed, while in model the output didn't have a ostensive output shape but in python I get this OK, since I can get the correct output.

But in C++, I need to get certain output of tensor (or at least get from model,) then some operation can be done.

I get the output shape from ORT C++ is 0:

:69] [1,0,4,]
D 9/28 11:4:27.954 ...core/backends/ort.cc infer:69] [1,0,]
D 9/28 11:4:27.954 ...core/backends/ort.cc infer:69] [1,0,]

how to do it?

std::vector<Ort::Value> ort_inputs;
  for (int i = 0; i < inputNames.size(); ++i) {
    ort_inputs.emplace_back(Ort::Value::CreateTensor<float>(
        memoryInfo, static_cast<float *>(inputs[i].data), inputs[i].get_size(),
        inputShapes[i].data(), inputShapes[i].size()));
  }

  std::vector<Ort::Value> outputTensors =
      session.Run(Ort::RunOptions{nullptr}, inputNames.data(),
                  ort_inputs.data(), 1, outputNames.data(), outputNames.size());
Page / URL

https://stackoverflow.com/questions/73875800/onnxruntime-c-how-to-get-outputtensor-dynamic-shape

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C++ entry points shown in the report: Ort::Value::CreateTensor and session.Run, and compare the reported output shapes with the linked Stack Overflow question. Document how a C++ caller should obtain dynamic output tensor shapes and identify what “correct output” means for this case; the documentation should address the reported zero dimensions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, machine-learning
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.