简体   繁体   English

如何解释 tensorflow lite c++ 中的 output 张量数据打包?

[英]how to interpret output tensor data packing in tensorflow lite c++?

I am working on a tensorflow-lite model in c++ (I have it working python already) and I was confused about how my output data is packed. I am working on a tensorflow-lite model in c++ (I have it working python already) and I was confused about how my output data is packed. I couldn't find any references in the documentation.我在文档中找不到任何参考资料。 I looked in the tflite source and learned I could get the output dimension of my tensor using dims for example我查看了 tflite 源代码,了解到我可以使用 dims 获得张量的 output 维度

for(int i=0; i < size; i++){
print("%d\n", out_tensor->dims->data[i]);
}

This gives me:这给了我:

1
96
96
14

Which is exactly what I know the output data to be.这正是我所知道的 output 数据。 It is a 96x96 grid where each grid element is 14 floats.它是一个 96x96 的网格,其中每个网格元素是 14 个浮点数。 What I don't understand is how to get this data out properly.我不明白的是如何正确获取这些数据。 At first we assumed it was flat and pulled it out like this:起初我们假设它是平的,然后像这样把它拉出来:

  const float* output = interpreter->typed_output_tensor<float>(0);

  for (int j = 0; j < num_values; ++j) {
    output_data_flat[out_idx++] = output[j];
  }

But this did not seem to come out right.但这似乎并不正确。 What is the right or at least a clean way to unpack this output data?解压缩此 output 数据的正确或至少是一种干净的方法是什么?

Thank you.谢谢你。

TensorFlow Lite tensor data is stored in a continuous manner, which means that you can assume as it is flatten. TensorFlow Lite 张量数据以连续方式存储,这意味着您可以假设它是扁平的。

In the other words, you can assume interpreter->typed_output_tensor<float>(0) as float[1][96][96][14].换句话说,您可以假设interpreter->typed_output_tensor<float>(0)为float[1][96][96][14]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM