我想在 android studio 中使用我的 keras 训练模型。我在互联网上获得了这段代码,可以将我的代码从 keras 转换为 tensorflow-lite。但是当我尝试代码时,我得到了这个错误:
OSError: SavedModel file does not exist at: C:\Users\Munib\New folder/{saved_model.pbtxt|saved_model.pb}
我从 keras 转换为 tensorflow-lite 时使用的代码:
import tensorflow as tf
# Converting a SavedModel to a TensorFlow Lite model.
saved_model_dir = r"C:\Users\Munib\New folder"
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
# Converting a tf.Keras model to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# Converting ConcreteFunctions to a TensorFlow Lite model.
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
tflite_model = converter.convert()
原文由 Mirza Munib 发布,翻译遵循 CC BY-SA 4.0 许可协议
首先最好使用相对路径而不是绝对路径。其次,如果您使用
model.save('my_model')
那么 keras 将为您创建一个名为my_model
pbtxt
目录,您应该在其中找到一个文件pb
或---
扩展名,这是你应该用于tflite转换器的目录