Hi guys,
I just have a quick question as shown in the title of this post.
I know that keras displays the training time spent on each epoch if you turns on the 'verbose' parameter. But how can I get this training time manually and use it for other displaying purpose? Is there a builtin method for this? Because I can not seem to find it.
Thanks a lot and cheers,
Kevin
You could write a keras callback along these lines.
Cheers
from time import time
class TimingCallback(Callback):
def __init__():
self.logs=[]
def on_epoch_begin(epoch, logs={}):
self.starttime=time()
def on_epoch_end(epoch, logs={}):
self.logs.append(time()-self.starttime)
...
cb = TimingCallback()
model.fit(..., callbacks=[cb])
print(cb.logs)
Hi man, thanks. Is it better to use timeit instead of time module? I read that timeit is more accurate than time in terms of recording execution time.
Cheers
Maybe, but you don't need nanosecond accuracy for each epoch. Maybe if you were timing batches it would matter. timeit is also more accurate because you can run something repeatedly and average the timing, but that isn't what you're looking for.
In general, use timeit for trying to get accurate times of small bits of code for optimizing performance, but use something like time for just recording general time data.
Most helpful comment
Maybe, but you don't need nanosecond accuracy for each epoch. Maybe if you were timing batches it would matter. timeit is also more accurate because you can run something repeatedly and average the timing, but that isn't what you're looking for.
In general, use timeit for trying to get accurate times of small bits of code for optimizing performance, but use something like time for just recording general time data.