无法将.h5文件转换为tflite模型

问题描述 投票:0回答:1

我已经训练了一个模型并将其保存为h5文件。由于我想在我的android应用程序中使用它,因此我希望将其转换为Colab上的tflite。这是我的代码:

import tensorflow as tf
model = tf.keras.models.load_model('Final_model.h5')
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)

我得到的错误:

AttributeError: type object 'TFLiteConverter' has no attribute 'from_keras_model'

我该如何解决?

tensorflow machine-learning keras tensorflow2.0
1个回答
0
投票

您正在使用Tensorflow 1.x,在这种情况下,其名称略为different API。您应该使用的是from_keras_model_file,即:

converter = tf.lite.TFLiteConverter.from_keras_model_file(model)
© www.soinside.com 2019 - 2024. All rights reserved.