Created
February 17, 2020 15:51
-
-
Save clauswrm/d7adff539bcd7d57d6d018d36f5fe93f to your computer and use it in GitHub Desktop.
Simple progress bar with ETA and itrs/sec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
from math import ceil | |
prev_time = 0.0 | |
def progress(total: int, current: int, steps=20): | |
""" Displays a progress bar with time information. """ | |
itrs_per_step = ceil(total / steps) | |
if current % itrs_per_step == 0: | |
global prev_time | |
cur_time = time() | |
print(f"\rTraining [{'#'*(current//itrs_per_step)}{'.'*(steps-current//itrs_per_step)}]" | |
f" {current}/{total}", end="") | |
if prev_time != 0: | |
print(f" [Eta {(cur_time-prev_time)*((total-current)/itrs_per_step):.1f} sec, " | |
f"{itrs_per_step/(cur_time-prev_time):.2f} itr/sec]", end="", flush=True) | |
else: | |
print(" [Eta -.- sec, -.- itr/sec]", end="", flush=True) | |
if current == total: | |
print("\n") | |
prev_time = cur_time |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment