tqdm_progress_bar
TQDMProgressBar
Classes
TQDMProgressBar
TQDMProgressBar(metrics_separator: str = ' - ', overall_bar_format: str = '{l_bar}{bar} {n_fmt}/{total_fmt} ETA: {remaining}s, {rate_fmt}{postfix}', epoch_bar_format: str = '{n_fmt}/{total_fmt}{bar} ETA: {remaining}s - {desc}', metrics_format: str = '{name}: {value:0.4f}', update_per_second: int = 10, leave_epoch_progress: bool = True, leave_overall_progress: bool = True, show_epoch_progress: bool = True, show_overall_progress: bool = True)
TQDM Progress Bar callback.
Parameters:
-
metrics_separator
(str
, default:' - '
) –Custom separator between metrics. Defaults to ' - '.
-
overall_bar_format
(str
, default:'{l_bar}{bar} {n_fmt}/{total_fmt} ETA: {remaining}s, {rate_fmt}{postfix}'
) –Custom bar format for overall (outer) progress bar, see https://github.com/tqdm/tqdm#parameters for more detail.
-
epoch_bar_format
(str
, default:'{n_fmt}/{total_fmt}{bar} ETA: {remaining}s - {desc}'
) –Custom bar format for epoch (inner) progress bar, see https://github.com/tqdm/tqdm#parameters for more detail.
-
update_per_second
(int
, default:10
) –Maximum number of updates in the epochs bar per second, this is to prevent small batches from slowing down training. Defaults to 10.
-
metrics_format
(str
, default:'{name}: {value:0.4f}'
) –Custom format for how metrics are formatted. See https://github.com/tqdm/tqdm#parameters for more detail.
-
leave_epoch_progress
(bool
, default:True
) –True
to leave epoch progress bars. -
leave_overall_progress
(bool
, default:True
) –True
to leave overall progress bar. -
show_epoch_progress
(bool
, default:True
) –False
to hide epoch progress bars. -
show_overall_progress
(bool
, default:True
) –False
to hide overall progress bar.
Example:
import time
import neuralspot_edge as nse
# Create a TQDM progress bar
pb_callback = nse.callbacks.TQDMProgressBar(
overall_bar_format="{l_bar}{bar} {n_fmt}/{total_fmt}, {rate_fmt}{postfix}",
epoch_bar_format="{n_fmt}/{total_fmt}{bar} - {desc}",
metrics_format="{name}: {value:0.4f}",
update_per_second=10,
leave_epoch_progress=True,
)
# Simulate training
epochs = 10
steps = 5
pb_callback.set_params(dict(epochs=epochs, steps=steps))
pb_callback.on_train_begin()
loss = 1.0
accuracy = 0.0
for epoch in range(epochs):
pb_callback.on_epoch_begin(epoch)
for step in range(steps):
loss -= epoch * step / (epochs * steps)
accuracy += epoch * step / (epochs * steps)
pb_callback.on_batch_end(step, {"loss": loss, "accuracy": accuracy})
time.sleep(0.1)
pb_callback.on_epoch_end(epoch, {"loss": loss, "accuracy": accuracy})
pb_callback.on_train_end()
Source code in neuralspot_edge/callbacks/tqdm_progress_bar.py
Functions
format_metrics
Format metrics in logs into a string.
Parameters:
-
logs
(dict
, default:{}
) –dictionary of metrics and their values. Defaults to empty dictionary.
-
factor
(int
, default:1
) –The factor we want to divide the metrics in logs by, useful when we are computing the logs after each batch. Defaults to 1.
Returns:
-
metrics_string
(str
) –a string displaying metrics using the given
-
str
–formators passed in through the constructor.