我想在Raspi上安装TensorFlow Lite.
我假设我可以先pip install为Raspi预建TensorFlow.我正在阅读这里交叉编译TensorFlow Lite的说明,但我不知道在生成之后该怎么做libtensorflow-lite.a.
我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) 嗨,有没有可能在 linux 平台上运行 tensorflow lite?如果是,那么我们如何在 java/C++/python 中编写代码以在 linux 平台上加载和运行模型?我熟悉bazel,并成功使用tensorflow lite制作了Android和ios应用程序。
我有一个常规模型,我用来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 模型比常规模型更快?谢谢。
我正在尝试将训练有素的模型从检查点文件转换为tflite. 我正在使用tf.lite.LiteConverter. 浮点转换顺利进行,推理速度合理。但是INT8转换的推理速度很慢。我试图通过输入一个非常小的网络来调试。我发现 INT8 模型的推理速度通常比浮点模型慢。
在 INT8 tflite 文件中,我发现了一些叫做 ReadVariableOp 的张量,在 TensorFlow 的官方 mobilenet tflite 模型中并不存在。
我想知道是什么导致了 INT8 推理的缓慢。
我由于一个粗心的错误而丢失了我的数据集。我手里只剩下 tflite 文件了。有没有办法反转h5文件。我对此进行了很好的研究,但没有找到解决方案。
tensorflow tensorflow-datasets tensorflow-lite tensorflow2.0
我正在尝试使用以下代码将 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) 连接完成后 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 设备连接和连接完成后会断开连接。
您好,我已经成功训练了一个基于 YOLOv5s 的自定义模型,并将该模型转换为 TFlite。我觉得这个问题很傻,但是你如何使用输出数据呢?
\n我得到的输出:
\n但我期望输出如下:
\n它也可能是其他形式的输出,但老实说,我不知道如何从 [1,25200,7] 数组中获取框、类、分数。\n(2021 年 1 月 15 日,我更新了 pytorch、tensorflow和yolov5到最新版本)
\n[1, 25200, 7]数组中包含的数据可以在这个文件中找到:outputdata.txt
\n0.011428807862102985, 0.006756599526852369, 0.04274776205420494, 0.034441519528627396, …Run Code Online (Sandbox Code Playgroud) 我正在运行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绑定的路径?
tensorflow-lite ×10
tensorflow ×6
keras ×2
pytorch ×2
android ×1
hdf5 ×1
linux ×1
opencv ×1
python ×1
python-3.x ×1
quantization ×1
tf.keras ×1
yolov5 ×1