stouputils.data_science.models.keras_utils.callbacks.colored_progress_bar module#

class ColoredProgressBar(desc: str = 'Training', track_epochs: bool = False, show_lr: bool = False, update_frequency: int = 1, color: str = '\x1b[95m')[source]#

Bases: Callback

Progress bar using tqdm for Keras training.

A callback that displays a progress bar using tqdm during model training. Shows the training progress across steps with a customized format instead of the default Keras one showing multiple lines.

desc: str#

Description of the progress bar.

track_epochs: bool#

Whether to track epochs instead of batches.

show_lr: bool#

Whether to show the learning rate.

latest_val_loss: float#

Latest validation loss, updated at the end of each epoch.

latest_lr: float#

Latest learning rate, updated during batch and epoch processing.

batch_count: int#

Counter to update the progress bar less frequently.

update_frequency: int#

How often to update the progress bar (every N batches).

color: str#

Color of the progress bar.

pbar: tqdm[Any] | None#

The tqdm progress bar instance.

epochs: int#

Total number of epochs.

steps: int#

Number of steps per epoch.

total: int#

Total number of steps/epochs to track.

params: dict[str, Any]#

Training parameters.

on_train_begin(logs: dict[str, Any] | None = None) None[source]#

Initialize the progress bar at the start of training.

Parameters:

logs (dict | None) – Training logs.

on_batch_end(batch: int, logs: dict[str, Any] | None = None) None[source]#

Update the progress bar after each batch, based on update frequency.

Parameters:
  • batch (int) – Current batch number (0-indexed).

  • logs (dict | None) – Dictionary of logs containing metrics for the batch.

on_epoch_end(epoch: int, logs: dict[str, Any] | None = None) None[source]#

Update metrics and progress bar position at the end of each epoch.

Parameters:
  • epoch (int) – Current epoch number (0-indexed).

  • logs (dict | None) – Dictionary of logs containing metrics for the epoch.

on_train_end(logs: dict[str, Any] | None = None) None[source]#

Close the progress bar when training is complete.

Parameters:

logs (dict | None) – Training logs.