0

我正在尝试使用 cpp tflite API 来查询开发板上的模型。该代码已使用 USB 棒进行了测试,并且可以正常工作,但是,在开发板上,我在此行出现错误:

model_interpreter_ = coral::BuildEdgeTpuInterpreter(*model_, this->edgetpu_context_.get());

这是错误:

INFO: Initialized TensorFlow Lite runtime.
ERROR: Failed to retrieve TPU context.
ERROR: Node number 0 (edgetpu-custom-op) failed to prepare.

相同的模型使用 python API 可以正常工作。

开发板上是否支持 tflite cpp API?

在开发板上,我有最新版本(12-1),这就是我为构建 tflite lib 所做的:

  1. 在本地为 arm64 构建 tflite(使用构建通用脚本,不像这里描述的那样)我使用了分支 v.2.0。*原因是在开发板上构建的虚拟内存和磁盘空间不足。

  2. 在开发板上安装了 flatbuffer。

编辑: 我能够从开发板上的 tensorflow 分支 v2.0 构建 tflite,更新为链接到本地​​构建的 lib ,仍然得到相同的错误......

编辑2: 我能够用tflite编译形式tf-r1.15重现相同的行为。我还尝试按照@Nam Vu 的建议添加可用 tpus 数量的打印。所以这是一个代码片段:

cout << "check num available tpus\n";
    cout << available_tpus.size() << "\n";
    cout << "get edge session\n";
    this->edgetpu_context_ = edgetpu::EdgeTpuManager::GetSingleton()->OpenDevice();
    cout << "check num available tpus again:\n";
    cout << available_tpus.size() << "\n";
    cout << "get model buffer\n";
    this->model_ = tflite::FlatBufferModel::BuildFromFile(model_path.c_str());
    cout << "build model interpeter\n";
    this->model_interpreter_ = coral::BuildEdgeTpuInterpreter(*model_, this->edgetpu_context_.get());

导致:

Hello
check num available tpus
3689348814741910324
get edge session
check num available tpus again:
3689348814741910324
get model buffer
build model interpeter
Segmentation fault
4

1 回答 1

0

想知道它是否以某种方式没有检测到 tpu,你可以试试这个:

const auto& available_tpus = edgetpu::EdgeTpuManager::GetSingleton()->EnumerateEdgeTpu();
cout << available_tpus.size() << "\n"; // hopefully we'll see 1 here

然后创建上下文:

std::shared_ptr<edgetpu::EdgeTpuContext> edgetpu_context =
          edgetpu::EdgeTpuManager::GetSingleton()->OpenDevice(
            available_tpus[0].type, available_tpus[0].path);
于 2019-10-31T17:35:08.167 回答