如何计算/测量TensorFlow模型的推理时间?

huangapple go评论65阅读模式
英文:

How to compute/measure inference time of a Tensorflow model?

问题

我有2个TF模型,我想比较它们在预测速度方面的性能。我知道TF模型有evaluate方法,可以输出每步推断的毫秒数。但是,是否有比这更高精度的方法?如果有,正确的做法是什么?

英文:

I have 2 TF models that I wanted to compare in terms of how fast they can predict. I'm aware that TF models have evaluate method that outputs ms per step inference. However, is there a way to have higher precision than this? If so, what's the proper way of doing it?

答案1

得分: 1

请尝试以下代码:

import time
start_time = time.time()
model.predict(等等......)
end_time = time.time()
duration = end_time - start_time
hours = duration // 3600
minutes = (duration - (hours * 3600)) // 60
seconds = duration - ((hours * 3600) + (minutes * 60))
msg = f'训练所用时间为 {str(hours)} 小时, {minutes:4.1f} 分钟, {seconds:4.2f} 秒'
print(msg)  # 打印出训练持续时间

如果还有其他问题需要翻译,请告诉我。

英文:

try this:

import time
start_time=time.time()
model.predict( etc.......
end_time=time.time()
duration= end_time-start_time
hours = tr_duration // 3600
minutes = (tr_duration - (hours * 3600)) // 60
seconds = tr_duration - ((hours * 3600) + (minutes * 60))
msg = f'training elapsed time was {str(hours)} hours, {minutes:4.1f} minutes, {seconds:4.2f} seconds)_
print (msg) # print out training duration time

huangapple
  • 本文由 发表于 2023年2月6日 17:09:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75359289.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定