When doing data-science, sometimes we use loops to perform repetitive and/or long-running operations (e.g. training a model). enlighten
is a Python package which simplifies printing to the command-line in multiple colors.
There are two main steps to use enlighten
progress bars: initialization and update.
To intialize a progress bar, import that enlighten manager and set the required parameters:
import englighten
manager = enlighten.get_manager( )
The parameters for get_manager
are all set by default, but can be adjusted. By default, output is piped to sys.stdout
and all the other defaults (type of counter, single-thread, etc) can be left alone.
In order to create a single progress bar, use the following:
pbar = manager.counter(
total=100,
desc='Some description',
unit='',
color='purple',
leave=False,
)
total defines how many iterations the bar should be updates by, desc defines the bar text, units defines what measure the bar should use, and the leave command defines whether the bar should remain on the console after the process has ended.
To use the progress bar in a loop:
for i in range(100):
# some important calculation here
pbar.update()
pbar.close()
This results in the following:
In order to have nested progress bars, follow whichever patter of loops is currently implemented
pbar_epoch = manager.counter(
total=1024,
desc='Epochs',
unit='',
color='purple',
leave=False,
)
pbar_batch = manager.counter(
total=64,
desc='Batch',
unit='',
color='green',
leave=False,
)
for epoch in range(1024):
for mini_batch_step in range(64):
# do batch step
pbar_batch.update()
pbar_epochs.update()
This results in the following: