【问题标题】:Using cpp tflite API in coral dev-board在珊瑚开发板中使用 cpp tflite API
【发布时间】:2019-10-31 10:39:43
【问题描述】:

我正在尝试使用 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(使用构建通用脚本,不像 here 描述的那样)我使用了分支 v.2.0。 *原因是开发板上缺少虚拟内存和磁盘空间。

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

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

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

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

【问题讨论】:

    标签: tensorflow tensorflow-lite tpu google-coral


    【解决方案1】:

    不知道是不是因为某种原因没有检测到 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);
    

    【讨论】:

    • 感谢您的建议,我得到一个未定义的数字作为 num cpus。将在问题中更新
    • 嗨 Omer,如果不了解您如何构建项目的更多信息,则很难诊断。您可以尝试从该提交中签出并构建静态 tensorflow 库吗:github.com/google-coral/edgetpu/blob/master/WORKSPACE#L5
    • 或者你可以尝试从那里交叉编译它(你需要在你的主机上使用 docker 并且输出将在'out'目录中:$ make DOCKER_IMAGE=debian:strech DOCKER_CPUS="aarch64" docker-build
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多