【问题标题】:Tensorflow Lite on Raspberry Pi - InstallationRaspberry Pi 上的 Tensorflow Lite - 安装
【发布时间】:2018-04-04 08:19:15
【问题描述】:

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

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

TIA

【问题讨论】:

标签: tensorflow raspberry-pi tensorflow-lite


【解决方案1】:

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

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

最好的,

--吉姆

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      您可以使用“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)
      

      希望这会有所帮助。

      【讨论】:

        【解决方案4】:

        我会建议下一个链接:

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

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

        # 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. Build from source for the Raspberry Pi

        2. Install TensorFlow with pip

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-03-20
          • 1970-01-01
          • 2015-10-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-24
          • 2015-05-16
          相关资源
          最近更新 更多