我使用来自Tensorflow集线器的预训练模型训练数据,这使我的val_acc大大提高。我将模型另存为.hdf5文件,并打算将其转换为.tflite,以便可以导入到我的android应用程序中。这是我在转换时使用的代码:
from tensorflow_core.lite.python.lite import TFLiteConverter
model_path = 'C:/Users/1/Desktop/data_sets/86%.hdf5'
converter = TFLiteConverter.from_keras_model_file(model_path)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
它输出“ ValueError:未知图层:KerasLayer”
我正在使用tf版本2.0。 这就是我保存模型的方式。下面的代码在回调中。
ModelCheckpoint(filepath=data_dir + '/weights.hdf5', monitor='val_accuracy',
verbose=1, save_best_only=True, save_weights_only=False, mode='auto', period=1)