【发布时间】:2018-10-03 09:52:30
【问题描述】:
我正在 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 秒,这似乎有点不正常。我错过了什么吗?
【问题讨论】:
-
如果您将推理内容包装在一个循环中(从
start = time.time()行开始并在 sn-p 的末尾结束)并运行它,例如 5 次,那么每次调用都很慢,还是只有第一个? -
每次调用都很慢(我让它循环了 10 次并对结果取平均值)。起初我以为是热身,但后来平均需要 30 秒。
标签: tensorflow tensorflow-lite