【问题标题】:TensorFlow Lite Inference on a PC very slowPC 上的 TensorFlow Lite 推理非常慢
【发布时间】: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


【解决方案1】:

对于性能问题,请在 Github 上提交跟踪问题,因为可能存在错误。

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

【讨论】:

  • 要考虑的另一件事是多线程。您使用的线程数应与您的其他基准测试相匹配。 30s 听起来非常慢,所以提出问题是合适的
猜你喜欢
  • 1970-01-01
  • 2020-07-21
  • 2019-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-09
  • 2021-08-22
相关资源
最近更新 更多