PC上的TensorFlow Lite推理非常慢

时间:2018-10-03 09:52:30

标签: tensorflow tensorflow-lite

我正在PC上试用TensorFlow Lite:

from tensorflow.contrib.lite.python import interpreter as interpreter_wrapper


model_path = os.path.join(ROOT_DIR, 'model', 'yolov3.tflite')

interpreter = interpreter_wrapper.Interpreter(model_path=model_path)
interpreter.allocate_tensors()

input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

if input_details[0]['dtype'] == np.float32:
    floating_model = True

orig = cv2.imread('data/dog-cycle-car.png')

height = input_details[0]['shape'][1]
width = input_details[0]['shape'][2]

image, image_data = preprocess_image(orig, (height, width))

start = time.time()
interpreter.set_tensor(input_details[0]['index'], image_data)
interpreter.invoke()
end = time.time()

output_data = interpreter.get_tensor(output_details[0]['index'])

# Takes around 30 seconds on a PC
print("Inference time: {:.2f}s".format((end - start)))

但是,推断大约需要30秒,这似乎有点异常。我想念什么吗?

1 个答案:

答案 0 :(得分:0)

关于性能方面的问题,由于可能存在错误,请在Github上提交跟踪问题。

另一个问题是性能差异有多少?一个因素是,Tensorflow Lite中的优化未针对x86(Tensorflow的目标更多),而我们针对的是与移动/嵌入式(例如arm)更相关的架构。