You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I do a lot of machine learning and I very commonly want to see statistics that are updated as the progress bar passes, like below:
It's not impossible to make this by hand, but it takes a reasonable amount of code which I generally don't want to write when I just want a progress bar. So, I think it would be a worthwhile feature to add a way to set a postfix (like tqdm https://tqdm.github.io/docs/tqdm/#set_postfix).
I already implemented something that works fairly well here:
importtimefromrich.prettyimportPretty, pprint, pretty_reprfromrich.progressimport (
BarColumn,
Progress,
TextColumn,
TimeRemainingColumn,
TaskProgressColumn,
)
fromnumbersimportNumberdefformat_num(n):
""" Intelligent scientific notation (.3g). Parameters ---------- n : int or float or Numeric A Number. Returns ------- out : str Formatted number. """f='{0:.3g}'.format(n).replace('+0', '+').replace('-0', '-')
n=str(n)
returnfiflen(f) <len(n) elsenclassMyProgress(Progress):
defupdate(self, *args, postfix={}, **kwargs):
super().update(*args, **kwargs)
withself._lock:
task=self._tasks[kwargs['task_id']]
iflen(postfix):
forkeyinpostfix.keys():
ifisinstance(postfix[key], Number):
postfix[key] =format_num(postfix[key])
elifnotisinstance(postfix[key], str):
postfix[key] =str(postfix[key])
task.postfix=', '.join(f'[green]{key}[/green]=[blue]{postfix[key]}[/blue]'.strip()
forkeyinpostfix.keys()) # Need to update Task class to have a postfix field@classmethoddefget_default_columns(cls):
return (
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TaskProgressColumn(),
TimeRemainingColumn(),
TextColumn("[progress.postfix]{task.postfix}"), # new text column!
)
defexample():
withMyProgress() aspbar:
t_out=pbar.add_task('epoch', total=6)
t_in=pbar.add_task('step', total=200)
foriinrange(6):
pbar.update(task_id=t_in, completed=0)
forjinrange(200):
time.sleep(.01)
pbar.update(task_id=t_in, advance=1, postfix={'loss': 100/(i*150+j+1)})
pbar.update(task_id=t_out, advance=1, postfix={"best_accuracy": f"{i*5}%", 'mode': "train"ifi%2==0else"validation"})
if__name__=="__main__":
pprint({'a':5})
example()
Other than updating the Task class by adding a str postfix field, this is the complete code
I think this would be a pretty useful feature for quite a few people. I can open a pull request if this sounds like a good feature. Or maybe it would be better to implement it another way, one problem with this design is that posfixes won't work on custom progress bars unless you add a textcolumn like TextColumn("[progress.postfix]{task.postfix}").
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I do a lot of machine learning and I very commonly want to see statistics that are updated as the progress bar passes, like below:
It's not impossible to make this by hand, but it takes a reasonable amount of code which I generally don't want to write when I just want a progress bar. So, I think it would be a worthwhile feature to add a way to set a postfix (like tqdm https://tqdm.github.io/docs/tqdm/#set_postfix).
I already implemented something that works fairly well here:
Other than updating the Task class by adding a str postfix field, this is the complete code
I think this would be a pretty useful feature for quite a few people. I can open a pull request if this sounds like a good feature. Or maybe it would be better to implement it another way, one problem with this design is that posfixes won't work on custom progress bars unless you add a textcolumn like TextColumn("[progress.postfix]{task.postfix}").
Beta Was this translation helpful? Give feedback.
All reactions