在推理期间,Tensorflow lite模型比其常规模型慢。为什么?

时间:2019-01-17 00:47:17

标签: tensorflow tensorflow-lite

我有一个常规模型,我使用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模型比常规模型更快?谢谢。

0 个答案:

没有答案