Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to obtain the time spent on training each epoch manually #5105

Closed
Kevinpsk opened this issue Jan 20, 2017 · 3 comments
Closed

How to obtain the time spent on training each epoch manually #5105

Kevinpsk opened this issue Jan 20, 2017 · 3 comments

Comments

@Kevinpsk
Copy link

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

@bstriner
Copy link
Contributor

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)

@Kevinpsk
Copy link
Author

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

@bstriner
Copy link
Contributor

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.

@stale stale bot added the stale label May 23, 2017
@stale stale bot closed this as completed Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants