record the computation time for each epoch in Keras during model.fit()

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)