我有一个常规模型,我使用tf.lite.TFLiteConverter.from_keras_model_file
将其转换为.tflite模型。然后,我使用解释器进行图像推断。
tf.logging.set_verbosity(tf.logging.DEBUG)
interpreter = tf.lite.Interpreter(model_path)
interpreter.allocate_tensors()
input_index = interpreter.get_input_details()[0]["index"]
output_index= interpreter.get_output_details()[0]["index"]
for loop:
(read image)
interpreter.set_tensor(input_index, image)
interpreter.invoke()
result = interpreter.get_tensor(output_index)
对于常规模型,我使用以下方法进行预测。
model = keras.models.load_model({h5 model path}, custom_objects={'loss':loss})
for loop:
(read image)
result = model.predict(image)
但是,推理.tflite模型所花费的时间比常规时间长得多。我也尝试在.tflite上进行训练后量化,但是与其他两个模型相比,该模型是最慢的模型。是否有意义?为什么会这样?是否可以使tensorflow lite模型比常规模型更快?谢谢。