Tensorflow lite模型在推理过程中比常规模型慢。为什么?

Tensorflow lite模型在推理过程中比常规模型慢。为什么?,tensorflow,tensorflow-lite,Tensorflow,Tensorflow Lite,我有一个常规模型,我使用tf.lite.TFLiteConverter.from\u keras\u model\u file将其转换为.tflite模型。然后我用解释器进行图像推理 tf.logging.set_verbosity(tf.logging.DEBUG) interpreter = tf.lite.Interpreter(model_path) interpreter.allocate_tensors() input_index = interpreter.get_input_de

我有一个常规模型,我使用
tf.lite.TFLiteConverter.from\u keras\u model\u 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)

然而,inference.tflite模型的运行时间比常规模型长得多。我还尝试在.tflite上进行训练后量化,但与其他两个模型相比,此模型的速度最慢。这有意义吗?为什么会发生这种情况?有没有办法使tensorflow lite模型比常规模型更快?谢谢

您是在计算机(如台式机/笔记本电脑)或移动设备(如Android/iOS)上运行此功能吗?可能是@miaout17的副本。谢谢您在另一个问题中的解释。我这里有一个问题:你说“如果苏格兰和南方能源公司可用,它将尝试使用NEON_2_SSE将NEON呼叫调整到苏格兰和南方能源公司”。这是否意味着计算机上的推理速度较慢,因为它从NEON_2_SSE传输可能需要更长的时间?@miaout17关于使用
setNumThreads
,我还有另一个问题。我有两个.tflite模型,一个是常规的.tflite模型,另一个是训练后的量化模型。我将线程数设置为4。但是,只有regular.tflite的推断速度加快了。量化模型的推断仍然很慢。你知道为什么会这样吗?非常感谢。