Shortcuts

ProgressBar

class lightning.pytorch.callbacks.ProgressBar[source]

Bases: Callback

The base class for progress bars in Lightning. It is a Callback that keeps track of the batch progress in the Trainer. You should implement your highly custom progress bars with this as the base class.

Example:

class LitProgressBar(ProgressBar):

    def __init__(self):
        super().__init__()  # don't forget this :)
        self.enable = True

    def disable(self):
        self.enable = False

    def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx):
        super().on_train_batch_end(trainer, pl_module, outputs, batch, batch_idx)  # don't forget this :)
        percent = (batch_idx / self.total_train_batches) * 100
        sys.stdout.flush()
        sys.stdout.write(f'{percent:.01f} percent complete \r')

bar = LitProgressBar()
trainer = Trainer(callbacks=[bar])
disable()[source]

You should provide a way to disable the progress bar.

Return type:

None

enable()[source]

You should provide a way to enable the progress bar.

The Trainer will call this in e.g. pre-training routines like the learning rate finder. to temporarily enable and disable the training progress bar.

Return type:

None

get_metrics(trainer, pl_module)[source]

Combines progress bar metrics collected from the trainer with standard metrics from get_standard_metrics. Implement this to override the items displayed in the progress bar.

Here is an example of how to override the defaults:

def get_metrics(self, trainer, model):
    # don't show the version number
    items = super().get_metrics(trainer, model)
    items.pop("v_num", None)
    return items
Return type:

Dict[str, Union[int, str, float, Dict[str, float]]]

Returns:

Dictionary with the items to be displayed in the progress bar.

print(*args, **kwargs)[source]

You should provide a way to print without breaking the progress bar.

Return type:

None

setup(trainer, pl_module, stage)[source]

Called when fit, validate, test, predict, or tune begins.

Return type:

None

property total_predict_batches_current_dataloader: Union[int, float]

The total number of prediction batches, which may change from epoch to epoch for current dataloader.

Use this to set the total number of iterations in the progress bar. Can return inf if the predict dataloader is of infinite size.

property total_test_batches_current_dataloader: Union[int, float]

The total number of testing batches, which may change from epoch to epoch for current dataloader.

Use this to set the total number of iterations in the progress bar. Can return inf if the test dataloader is of infinite size.

property total_train_batches: Union[int, float]

The total number of training batches, which may change from epoch to epoch.

Use this to set the total number of iterations in the progress bar. Can return inf if the training dataloader is of infinite size.

property total_val_batches: Union[int, float]

The total number of validation batches, which may change from epoch to epoch for all val dataloaders.

Use this to set the total number of iterations in the progress bar. Can return inf if the predict dataloader is of infinite size.

property total_val_batches_current_dataloader: Union[int, float]

The total number of validation batches, which may change from epoch to epoch for current dataloader.

Use this to set the total number of iterations in the progress bar. Can return inf if the validation dataloader is of infinite size.