[英]How to measure training time per batches during Deep Learning in Tensorflow?
I want to measure training time per batches during Deep Learning in Tensorflow.我想在 Tensorflow 中测量深度学习期间每批次的训练时间。 There are several ways to measure training time per epochs, but I cannot find how to measure training time per batches.
有几种方法可以测量每个时期的训练时间,但我找不到如何测量每批次的训练时间。
I tried Tensorboard, but I don't know how to add some kind of 'execution time' scalars in tensorboard callbacks.我试过 Tensorboard,但我不知道如何在 tensorboard 回调中添加某种“执行时间”标量。
And I also tried to override the function 'train_step' but it didn't work the way I want.而且我还尝试覆盖 function 'train_step' 但它没有按我想要的方式工作。
You can do this by creating a keras custom callback.您可以通过创建 keras 自定义回调来做到这一点。 The code below will print out the time it takes to process each batch, the training accuracy for that batch and the loss for that batch
下面的代码将打印出处理每个批次所需的时间、该批次的训练准确度以及该批次的损失
class batch_timer(keras.callbacks.Callback):
def __init__(self ):
super(batch_timer, self).__init__()
def on_train_batch_begin(self, batch, logs=None):
self.start_time=time.time()
def on_train_batch_end(self, batch, logs=None):
stop_time=time.time()
duration =stop_time-self.start_time
acc=logs.get('accuracy')* 100 # get training accuracy
loss=logs.get('loss')
msg='processing batch {0:6s} duration= {1:12.4f} accuracy= {2:8.3f} loss: {3:8.5f}'.format(str(batch), duration, acc, loss)
print(msg )
Now you are going to get tons of data.现在您将获得大量数据。 When you run model.fit include
当你运行 model.fit 包括
history=model.fit(etc.... ,verbose=0, callbacks=[batch_timer()]
I set verbose=0 because if you don't the printout gets a bit messy because model.fit printing gets messed up by the callback printing我设置了 verbose=0 因为如果你不这样做打印输出会有点乱,因为 model.fit 打印被回调打印搞砸了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.