4

在我当前的项目中,我在 Raspberry Pi 上使用机器学习来进行传感器融合。自从我听说了 Tensorflow Lite 的发布后,我对部署和使用它在平台上运行 Lite 模型非常感兴趣。

Tensorflow 网站上有 Android 和 iOS 的提示,但我找不到任何其他平台的提示。是否有(WIP)安装/编译指南将 TF Lite 引入 Raspi?

TIA

4

4 回答 4

1

@all,如果您仍在尝试让 tensorflow lite 在 Raspberry Pi 3 上运行,那么我的“拉取请求”可能会很有用。请查看https://github.com/tensorflow/tensorflow/pull/24194

按照这些步骤,可以在 Raspberry Pi 3 上运行 2 个应用程序(label_image 和 camera)。

最好的,

——吉姆

于 2018-12-15T12:04:17.077 回答
0

https://www.tensorflow.org/mobile/tflite/devguide#raspberry_pi的 TFLite 文档中有一小部分关于 Raspberry PI 。该部分链接到此 GitHub 文档,其中包含在 Raspberry PI - tensorflow/rpi.md上构建 TFLite 的说明。

目前还没有正式的演示应用程序,但第一个位置说有一个计划。准备好后,它可能会在同一位置共享(即描述 Android 和 iOS 演示应用程序的位置)。

于 2018-09-12T00:37:44.223 回答
0

我建议下一个链接:

  1. 最简单的方法是仅使用 TensorFlowLite 解释器。您可以通过以下链接找到更多信息:仅安装 TensorFlow Lite 解释器

你必须记住,如果你只使用解释器,你必须遵循一些不同的逻辑。

# Initiate the interpreter
interpreter = tf.lite.Interpreter(PATH_TO_SAVED_TFLITE_MODEL)

# Allocate memory for tensors
interpreter.allocate_tensors()

# Get input and output tensors
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

# Add a batch dimension if needed (data_tensor - your data input)
input_data = tf.extend.dims(data_tensor, axis=0)

# Predict
interpreter.set_tensor(input_details[0]['index'], data_tensor)
interpreter.invoke()

# Obtain results
predictions = interpreter.get_tensor(output_details[0]['index'])
  1. 从 Raspberry Pi 的源代码构建

  2. 使用 pip 安装 TensorFlow

于 2020-01-14T13:37:17.967 回答
0

您可以使用“pip install tensorflow”在 Raspberry pi 上安装 TensorFlow PIP,但是,如果您只想要 TFLite,您可以构建一个只有 tflite 解释器的较小 pip(然后您可以在另一台大型机器上进行转换)。

关于如何做到这一点的信息在这里: https ://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/tools/pip_package

然后,您可以使用它。这是一个如何使用它的示例!


import tflite_runtime as tflr

interpreter = tflr.lite.Interpreter(model_path="mobilenet_float.tflite")
interpreter.allocate()
input = interpreter.get_input_details()[0]
output = interpreter.get_input_details()[0]

cap = cv2.VideoCapture(0)  # open 0th web camera

while 1:
  ret, frame = cap.read()
  frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  frame = cv2.resize(frame, input.shape[2],input.shape[1])
  frame = np.reshape(im, input.shape).astype(np.float32)/128.0-1.0
  interpreter.set_tensor(input["index"], frame)
  interpreter.invoke()
  labels = interpreter.get_tensor(output["index"])
  top_label_index = np.argmax(labels, axis=-1)

希望这可以帮助。

于 2019-02-07T23:26:27.593 回答