首页 > 解决方案 > 将 .h5 转换为 .tflite 会降低我的模型预测精度

问题描述

大家好,我尝试使用以下代码将我的模型从 .h5(keras) 转换为 .tflite

import tensorflow as tf
keras_model = tf.keras.models.load_model("model06.h5")
converter = tf.lite.TFLiteConverter.from_keras_model(keras_model)
tflite_model = converter.convert()
with open('model06.tflite', 'wb') as f:
     f.write(tflite_model)

但是在转换为 .tflite 后,我的预测在精度上有一些损失,有没有更好的方法来转换模型而不会损失模型的精度

标签: tensorflowkerasprecision

解决方案


精度下降是正常的;实际上这是预期会发生的现象,它是速度和准确性之间的权衡。

您唯一可以做的就是使用float16而不是int8在转换时使用,以减轻精度损失。


推荐阅读