0 votes
1 view
in Machine Learning by (13.5k points)

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.

1 Answer

0 votes
by (33.1k points)
edited by

You should try callback in Keras:

For example:

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

Here, times should store the epoch computation times.

Hope this answer helps you!

Watch this video to know more about Keras:

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...