【问题标题】:Object detection in TensorFlow Lite C++ with the MobileNet-SSD v1 model使用 MobileNet-SSD v1 模型在 TensorFlow Lite C++ 中进行对象检测
【发布时间】:2018-05-17 11:26:54
【问题描述】:

根据此信息link,TensorFlow Lite 现在支持使用 MobileNet-SSD v1 模型进行对象检测。这个link 中有一个Java 示例,但是如何在C++ 中解析输出?我找不到任何关于此的文档。此代码显示了一个示例。

.......
(fill inputs)
.......

intepreter->Invoke();
const std::vector<int>& results = interpreter->outputs();
TfLiteTensor* outputLocations = interpreter->tensor(results[0]);
TfLiteTensor* outputClasses   = interpreter->tensor(results[1]);
float *data = tflite::GetTensorData<float>(outputClasses);
for(int i=0;i<NUM_RESULTS;i++)
{
   for(int j=1;j<NUM_CLASSES;j++)
   {
      float score = expit(data[i*NUM_CLASSES+j]); // ¿? This does not seem to be correct.
    }
}

【问题讨论】:

标签: tensorflow tensorflow-lite


【解决方案1】:

如果您需要计算 expit,您需要定义一个函数来执行此操作。在顶部添加:

#include <cmath>

然后

intepreter->Invoke();
const std::vector<int>& results = interpreter->outputs();
TfLiteTensor* outputLocations = interpreter->tensor(results[0]);
TfLiteTensor* outputClasses   = interpreter->tensor(results[1]);
float *data = tflite::GetTensorData<float>(outputClasses);
for(int i=0;i<NUM_RESULTS;i++)
{
   for(int j=1;j<NUM_CLASSES;j++)
   {
      auto expit = [](float x) {return 1.f/(1.f + std::exp(-x));};
      float score = expit(data[i*NUM_CLASSES+j]); // ¿? This does not seem to be correct.
    }
}

【讨论】:

  • 嗨 aselle,是的,我计算了 expit。获取分数的源代码确实是正确的。我很困惑,因为我期待 Tensorflow Lite 的结果与 Tensorflow 给出的结果相同。问题似乎是用于对象检测的 TensorFlow Lite 在某些情况下会产生过多的噪音,而在其他情况下它会丢失良好的检测,这在此处进行了讨论,github.com/tensorflow/tensorflow/issues/…。所以,我知道即使是移动设备我仍在使用 Tensorflow。由于 Tensorflow Lite 省略了一些后处​​理节点,这是预期的行为吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-17
  • 2021-11-06
  • 2021-01-26
  • 2021-09-20
  • 1970-01-01
  • 2020-12-11
相关资源
最近更新 更多