tensorflow.lite.python.convert.ConverterError:could not find toco_from_protos binary

tensorflow.lite.python.convert.ConverterError:could not find toco_from_protos binary

在 tensorflow 2.2 中,我训练了一个 mobileNetv1 模型,并得到了一个 .h5 文件,现在我想将它转换为一个 .tflite 文件用于 android 应用程序,但是我得到了一个错误,如 title 。这是我的代码:

model = load_model(h5path)
converter = tf.lite.TFLiteConverter.from_keras_model(model)
litemodel = converter.convert()
open(litepath,"wb").write(litemodel)

这是我的错误:

tensorflow.lite.python.convert.ConverterError: Could not find toco_from_protos binary, make sure your virtualenv bin directory or pip local bin directory is in your path.
In particular, if you have installed TensorFlow with --user, make sure you add the install directory to your path.


For example:
Linux: export PATH=$PATH:~/.local/bin/
Mac: export PATH=$PATH:~/Library/Python/<version#>/bin

Alternative, use virtualenv.

请帮我解开谜题。

Linux系统的服务器。

看来您的环境还没有完成所有要求的安装。

如果问题仍然存在或遇到类似问题,我会建议在 Google Colab 处检查它。在此环境中,您可以导入 Tensorflow 和 Keras 库,例如:

import tensorflow as tf
import tensorflow.keras as K
import os
import numpy as np
import sys
import matplotlib.pyplot as plt
np.set_printoptions(threshold=sys.maxsize)

print(tf.__version__)
print(K.__version__)

而且你很好地进行了转换。对于你的问题,我会使用下面的代码片段:

# WHOLE MODEL
tflite_model = tf.keras.models.load_model('my_model.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(tflite_model)
tflite_save = converter.convert()
open("my_model.tflite", "wb").write(tflite_save)

编码愉快!