#convert from float* to vector

24 messages · Page 1 of 1 (latest)

chilly mica
karmic coyoteBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

magic mist
#

How are you supposed to constrain an unknown range into a known one?

chilly mica
# magic mist You can't
    std::vector<Ort::Value> outputTensors = _session.Run(Ort::RunOptions{ nullptr },
        _inputNames.data(), &inputTensor, 1,  _outputNames.data(), _outputNames.size());

    std::cout << outputTensors.size() << std::endl;
    std::cout << outputTensors << std::endl;
    const float* pdata = outputTensors[1].GetTensorMutableData<float>();
    std::cout << pdata << std::endl;

it's sad it only gives me outputs like this

4
0x5cf24c6edb30 0x5cf24c15e170 0x5cf24c6cd740 0x5cf24bfb1d40
0x74b8e2fea540
#

I dont even know how to utilize it
printing in python was way easier

magic mist
#

oh god it's onnx runtime

#

you just triggered my PTSD

#

I had to write code just like this

#

Yeah ok so in your case what the problem is, you don't have an array of floats

#

typically, float* means that in memory you have a float, float, float, float, etc...

#

The onnx runtime makes it so that you don't actually have floats next to each other in memory

#
auto outputs = std::vector<float>(output_tensors.size());
for (int i = 0; i < outputs.size(); i++) {
  outputs[i] = *output_tensors[i].GetTensorMutableData<float>();
}```
#

smth like this might work

chilly mica
magic mist
#

well yeah

#

pdata is a float*, it's pointing to the float value itself no?

chilly mica
#

yeah it does

magic mist
#

So if you want to get a std::vector<float> you need to dereference the pointer to get the actual value

chilly mica
#

the issue is outputTensors.size() is 4
each member of outputTensors might be an image or a bounding box vector (and its score vector)

#

I know the size of image so it is OK, I can convert the pointer to image with the sizes known

#

but for bounding box vector, its length depends on the number of objects detected, which I could not know in advance

#

that's why I say printing in python is way easier

#

oh nvm I found the .GetTensorTypeAndShapeInfo().GetShape() method for outputs