英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论