【问题标题】:tensorflow and keras - fast inference in production from SQStensorflow 和 keras - 从 SQS 进行生产中的快速推理
【发布时间】:2020-05-02 15:47:22
【问题描述】:

我的模型是在 Keras 中编写和训练的。我正在尝试将其用于生产中的推理。我收到包含 (path_in, path_out) 元组的 SQS“任务”消息。

我显然可以使用:

BATCH_SIZE = 10
batch_messages = []


while True:
  while len(batch_messages) < BATCH_SIZE:
    msg = sqs.read_messsage()  
    batch_messages.apend(msg)

  assert len(batch_messages) == BATCH_SIZE
  batch = np.array([read_image(msg.path_in) for msg in batch_messages]) 

  output_batch = model.predict(batch)

  for i in range(BATCH_SIZE):
    write_output(output_batch[i], path=batch_messages[i].path_out)

  batch_messages = []

问题在于代码浪费了大部分时间从 SQS 读取、从磁盘读取图像并在最后将其写回。这意味着 GPU 在这段时间内一直处于空闲状态。

我知道 Keras 的 Sequence,但不确定它是否也适用于这种情况,以及用于推理(而不是训练)

【问题讨论】:

    标签: python-3.x tensorflow amazon-sqs


    【解决方案1】:

    我建议您使用Tensorflow Serving 解决方案,因为它实现了服务器端批处理策略,可优化推理速度和 GOU 利用率。此外,如果您想加快管道速度,您应该将模型转换为 TensorRT 模型,该模型将模型操作优化到特定的 GPU(它还可以做更多的事情)。

    【讨论】:

      猜你喜欢
      • 2020-03-04
      • 2021-12-26
      • 2020-03-15
      • 2013-03-27
      • 2018-03-27
      • 2017-06-30
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多