标签: tensorflow-lite

如何在Raspi 3上使用libtensorflow-lite.a?

我想在Raspi上安装TensorFlow Lite.

我假设我可以先pip install为Raspi预建TensorFlow.我正在阅读这里交叉编译TensorFlow Lite的说明,但我不知道在生成之后该怎么做libtensorflow-lite.a.

tensorflow raspberry-pi3 tensorflow-lite

8
推荐指数
1
解决办法
329
查看次数

在 Keras 中加载由 callbakcs.ModelCheckpoint() 保存的模型时出错

callbacks.ModelCheckpoint()使用 HDF5 文件自动保存了我的模型。

# Checkpoint In the /output folder
filepath = "./model/mnist-cnn-best.hd5"

# Keep only a single checkpoint, the best over test accuracy.
checkpoint = keras.callbacks.ModelCheckpoint(filepath, monitor='val_acc', 
                                             verbose=1, save_best_only=True,
                                             mode='max')

# Train
model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_data=(x_test, y_test),
          callbacks=[checkpoint])
Run Code Online (Sandbox Code Playgroud)

当我加载模型时,发生了错误。

  model = keras.models.load_model("./mnist-cnn-best.hd5")

  File "D:\Program Files\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\saving.py", line 251, in load_model
    training_config['weighted_metrics'])
KeyError: 'weighted_metrics'
Run Code Online (Sandbox Code Playgroud)

如果我使用参数 ' compile=False '加载模型,它可以正常工作。

我知道在 keras 中保存模型的正常方法是:

from keras.models import load_model

model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'
del model  # deletes the existing …
Run Code Online (Sandbox Code Playgroud)

hdf5 keras tensorflow-lite

8
推荐指数
1
解决办法
4195
查看次数

我们可以在 linux 上运行 tensorflow lite 吗?或者它仅适用于 android 和 ios

嗨,有没有可能在 linux 平台上运行 tensorflow lite?如果是,那么我们如何在 java/C++/python 中编写代码以在 linux 平台上加载和运行模型?我熟悉bazel,并成功使用tensorflow lite制作了Android和ios应用程序。

linux tensorflow-lite

8
推荐指数
2
解决办法
6598
查看次数

Tensorflow lite 模型在推理过程中比常规模型慢。为什么?

我有一个常规模型,我用来tf.lite.TFLiteConverter.from_keras_model_file将其转换为 .tflite 模型。然后我使用解释器来进行图像的推理。

tf.logging.set_verbosity(tf.logging.DEBUG)
interpreter = tf.lite.Interpreter(model_path)
interpreter.allocate_tensors()
input_index = interpreter.get_input_details()[0]["index"]
output_index= interpreter.get_output_details()[0]["index"]
for loop:
    (read image)
    interpreter.set_tensor(input_index, image)
    interpreter.invoke()
    result = interpreter.get_tensor(output_index)
Run Code Online (Sandbox Code Playgroud)

对于常规模型,我使用以下方法进行预测。

model = keras.models.load_model({h5 model path}, custom_objects={'loss':loss})
for loop:
    (read image)
    result = model.predict(image)
Run Code Online (Sandbox Code Playgroud)

然而,推理 .tflite 模型所花费的时间比常规模型要长得多。我还尝试了 .tflite 上的训练后量化,但与其他两个模型相比,该模型是最慢的。是否有意义?为什么会出现这种情况?有没有办法让 TensorFlow Lite 模型比常规模型更快?谢谢。

tensorflow tensorflow-lite

8
推荐指数
0
解决办法
5648
查看次数

tflite 量化推理非常慢

我正在尝试将训练有素的模型从检查点文件转换为tflite. 我正在使用tf.lite.LiteConverter. 浮点转换顺利进行,推理速度合理。但是INT8转换的推理速度很慢。我试图通过输入一个非常小的网络来调试。我发现 INT8 模型的推理速度通常比浮点模型慢。

在 INT8 tflite 文件中,我发现了一些叫做 ReadVariableOp 的张量,在 TensorFlow 的官方 mobilenet tflite 模型中并不存在。

我想知道是什么导致了 INT8 推理的缓慢。

quantization tensorflow tensorflow-lite

8
推荐指数
1
解决办法
898
查看次数

有没有办法将tensorflow lite(.tflite)文件转换回keras文件(.h5)?

我由于一个粗心的错误而丢失了我的数据集。我手里只剩下 tflite 文件了。有没有办法反转h5文件。我对此进行了很好的研究,但没有找到解决方案。

tensorflow tensorflow-datasets tensorflow-lite tensorflow2.0

8
推荐指数
1
解决办法
1万
查看次数

Keras模型AttributeError:'str'对象没有属性'call'

我正在尝试使用以下代码将 Keras hdf5 文件转换为 TensorFlow Lite 文件:

import tensorflow as tf

# Convert the model.
converter = tf.lite.TFLiteConverter.from_keras_model("/content/best_model_11class.hdf5")
tflite_model = converter.convert()

# Save the TF Lite model.
with tf.io.gfile.GFile('model.tflite', 'wb') as f:
  f.write(tflite_model)
Run Code Online (Sandbox Code Playgroud)

我收到此错误from_keras_model

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-14-26467c686751> in <module>()
      2 
      3 # Convert the model.
----> 4 converter = tf.lite.TFLiteConverter.from_keras_model("/content/best_model_11class.hdf5")
      5 tflite_model = converter.convert()
      6 

/usr/local/lib/python3.6/dist-packages/tensorflow/lite/python/lite.py in from_keras_model(cls, model)
    426     # to None.
    427     # Once we have better support for dynamic shapes, …
Run Code Online (Sandbox Code Playgroud)

python-3.x keras tensorflow-lite tf.keras tensorflow2.0

8
推荐指数
1
解决办法
6815
查看次数

BufferQueueProducer:[SurfaceTexture-1-12105-10]断开连接:未连接(req = 1)

连接完成后 USB 设备断开连接时应用程序崩溃。我收到以下 logcat 错误消息。我对此不太了解。

日志猫错误:

E/tflite: Can not open OpenCL library on this device - dlopen failed: library "libOpenCL.so" not found
E/tflite: Falling back to OpenGL
E/BufferQueueProducer: [SurfaceTexture-1-8293-2] disconnect: not connected (req=1)
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x57 in tid 8884 (Thread-11), pid 8293
Run Code Online (Sandbox Code Playgroud)

如果 USB 设备未断开连接,则应用程序工作正常,但有时在 USB 设备连接和连接完成后会断开连接。

android opencv tensorflow-lite

8
推荐指数
0
解决办法
6000
查看次数

处理 YOLOv5 TFlite 的输出数据

\xe2\x9d\x94问题

\n

您好,我已经成功训练了一个基于 YOLOv5s 的自定义模型,并将该模型转换为 TFlite。我觉得这个问题很傻,但是你如何使用输出数据呢?

\n

我得到的输出:

\n\n

但我期望输出如下:

\n
    \n
  • StatefulPartitionedCall:3 = [1, 10, 4] # 个框
  • \n
  • StatefulPartitionedCall:2 = [1, 10] # 类
  • \n
  • StatefulPartitionedCall:1 = [1, 10] #scores
  • \n
  • StatefulPartitionedCall:0 = [1] #count\n(这个来自 TensorFlow lite mobilenet 模型(训练为提供 10 个输出数据,默认为 tflite))\n Netron mobilenet.tflite 模型
  • \n
\n

它也可能是其他形式的输出,但老实说,我不知道如何从 [1,25200,7] 数组中获取框、类、分数。\n(2021 年 1 月 15 日,我更新了 pytorch、tensorflow和yolov5到最新版本)

\n

[1, 25200, 7]数组中包含的数据可以在这个文件中找到:outputdata.txt

\n
0.011428807862102985, 0.006756599526852369, 0.04274776205420494, 0.034441519528627396, …
Run Code Online (Sandbox Code Playgroud)

tensorflow pytorch tensorflow-lite yolov5

8
推荐指数
1
解决办法
8024
查看次数

如何在Python中导入tensorflow lite解释器?

我正在运行Raspbian Stretch的Raspberry Pi 3b上使用TF lite开发Tensorflow嵌入式应用程序。我已将图形转换为平面缓冲区(精简版)格式,并在Pi上本地构建了TFLite静态库。到目前为止,一切都很好。但是该应用程序是Python,并且似乎没有可用的Python绑定。Tensorflow Lite开发指南(https://www.tensorflow.org/mobile/tflite/devguide)指出:“已经计划了Python绑定和演示应用程序。” 但是/ tensorflow / contrib / lite / python / interpreter_wrapper中有包装器代码,其中包含所有必需的解释器方法。但是,从Python调用它使我难以理解。

我已经生成了SWIG包装器,但是构建步骤失败并出现许多错误。没有readme.md描述解释器包装器的状态。因此,我想知道包装器是否为其他人工作,我应该坚持还是从根本上破坏它,而应该在其他地方使用(PyTorch)?有没有人找到Pi3的TFLite Python绑定的路径?

python tensorflow raspberry-pi3 pytorch tensorflow-lite

7
推荐指数
2
解决办法
7927
查看次数