from ignite.engine import Engine, Events from ignite.contrib.handlers import ProgressBar def train_step(engine, batch): # your custom training logic here return loss_value trainer = Engine(train_step) # create a ProgressBar instance pbar = ProgressBar() # Attach the ProgressBar to the trainer to show training progress pbar.attach(trainer, output_transform=lambda x: {'loss': x}) # start training trainer.run(train_loader, max_epochs=10)
from ignite.engine import Engine, Events from ignite.contrib.handlers import ProgressBar def train_step(engine, batch): # your custom training logic here message = f"Learning rate: {optimizer.param_groups[0]['lr']:.4f}" pbar.log_message(message) return loss_value trainer = Engine(train_step) # create a ProgressBar instance pbar = ProgressBar() # Attach the ProgressBar to the trainer to show training progress pbar.attach(trainer, output_transform=lambda x: {'loss': x}) # start training trainer.run(train_loader, max_epochs=10)In this code example, we have added a custom message to the progress bar inside the training function using the `log_message` method of the ProgressBar instance. We use this method to display the learning rate of the optimizer at each step of the training process.