如何在 Python 中导入 tensorflow lite 解释器? [英] How to import the tensorflow lite interpreter in Python?

查看:166
本文介绍了如何在 Python 中导入 tensorflow lite 解释器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Raspberry Pi 3b 上使用 TF lite 开发一个 Tensorflow 嵌入式应用程序,运行 Raspbian Stretch.我已将图形转换为 flatbuffer (lite) 格式,并在 Pi 上本地构建了 TFLite 静态库.到现在为止还挺好.但是应用程序是 Python 并且似乎没有可用的 Python 绑定.Tensorflow Lite 开发指南 (https://www.tensorflow.org/mobile/tflite/devguide) 声明有 Python 绑定和演示应用程序的计划."然而,/tensorflow/contrib/lite/python/interpreter_wrapper 中有包装器代码,其中包含所有需要的解释器方法.然而,从 Python 中调用它却让我望而却步.

I'm developing a Tensorflow embedded application using TF lite on the Raspberry Pi 3b, running Raspbian Stretch. I've converted the graph to a flatbuffer (lite) format and have built the TFLite static library natively on the Pi. So far so good. But the application is Python and there seems to be no Python binding available. The Tensorflow Lite development guide (https://www.tensorflow.org/mobile/tflite/devguide) states "There are plans for Python bindings and a demo app." Yet there is wrapper code in /tensorflow/contrib/lite/python/interpreter_wrapper that has all the needed interpreter methods. Yet calling this from Python eludes me.

我生成了一个 SWIG 包装器,但构建步骤失败并出现许多错误.没有描述 interpreter_wrapper 状态的 readme.md.所以,我想知道包装器是否为其他人工作过,我应该坚持下去,还是从根本上坏了,我应该看看其他地方(PyTorch)?有没有人找到 Pi3 的 TFLite Python 绑定的路径?

I have generated a SWIG wrapper but the build step fails with many errors. There is no readme.md describing the state of the interpreter_wrapper. So, I wonder if the wrapper has worked for others and I should persist or is it fundamentally broken and I should look elsewhere (PyTorch)? Has anyone found a path to the TFLite Python bindings for the Pi3?

推荐答案

我能够编写 Python 脚本来进行分类 1,对象检测(使用 SSD MobilenetV 测试{1,2})2,以及图像语义分割3 在运行 Ubuntu 的 x86 和运行 Debian 的 ARM64 板上.

I was able to write python scripts to do classification 1, object-detection (tested with SSD MobilenetV{1,2}) 2, and image semantic segmentation 3 on an x86 running Ubuntu and an ARM64 board running Debian.

  • 如何为 TF Lite 代码构建 Python 绑定:使用最近的 TensorFlow 主分支构建 pip 并安装它(是的,这些绑定在 TF 1.8 中.但是,我不知道为什么没有安装它们).请参阅 4 了解如何构建和安装 TensorFlow pip 包.
  • How to build Python binding for TF Lite code: Build pip with recent TensorFlow master branch and install it (Yes, those binding was in TF 1.8. However, I don't know why they are not installed). See 4 for how to to build and install TensorFlow pip package.

这篇关于如何在 Python 中导入 tensorflow lite 解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆