在model.fit()期间记录Keras中每个纪元的计算时间(record the computation time for each epoch in Keras during model.fit())
我想比较不同模型之间的计算时间。 在拟合期间,每个纪元的计算时间被打印到控制台。
Epoch 5/5 160000/160000 [==============================] - **10s** ......我正在寻找一种方法来存储这些时间,类似于在每个时期保存并通过历史对象可用的模型指标。
I want to compare the computation time between different models. During the fit the computation time per epoch is printed to the console.
Epoch 5/5 160000/160000 [==============================] - **10s** ......I'm looking for a way to store these times in a similar way to the model metrics that are saved in each epoch and avaliable through the history object.
最满意答案
尝试以下回调:
class TimeHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.times = [] def on_epoch_begin(self, batch, logs={}): self.epoch_time_start = time.time() def on_epoch_end(self, batch, logs={}): self.times.append(time.time() - self.epoch_time_start)然后:
time_callback = TimeHistory() model.fit(..., callbacks=[..., time_callback],...) times = time_callback.times在这种情况下, times应该存储纪元计算时间。
Try the following callback:
class TimeHistory(keras.callbacks.Callback): def on_train_begin(self, logs={}): self.times = [] def on_epoch_begin(self, batch, logs={}): self.epoch_time_start = time.time() def on_epoch_end(self, batch, logs={}): self.times.append(time.time() - self.epoch_time_start)Then:
time_callback = TimeHistory() model.fit(..., callbacks=[..., time_callback],...) times = time_callback.timesIn this case times should store the epoch computation times.
更多推荐
发布评论