What is the difference between the predict and predict_on_batch methods of a Keras model?

前端 未结 3 747
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 09:52

According to the keras documentation:

predict_on_batch(self, x)
Returns predictions for a single batch of samples.

However, there does not

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-17 10:33

    It seems predict_on_batch is a lot faster compared to predict if executed on a single batch.

    • batch & model information
      • batch shape: (1024, 333)
      • batch dtype: float32
      • model parameters: ~150k
    • timeit result:
      • predict: ~1.45 seconds
      • predict_on_batch: ~95.5 ms

    In summary, predict method has extra operations to ensure a collection of batches are processed right, whereas, predict_on_batch is a lightweight alternative to predict that should be used on a single batch.

提交回复
热议问题