在model.fit()期间记录Keras中每个纪元的计算时间(record the computation time for each epoch in Keras during model.fit

系统教程 行业动态 更新时间:2024-06-14 17:02:17
在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.times

In this case times should store the epoch computation times.

更多推荐

本文发布于:2023-04-21 18:34:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/b4e169fca3bdc526e178c9da407eeedf.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:纪元   时间   fit   Keras   model

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!