How to show the validation loss in progress bar?
Hi.
I'm trying to come up with ways to get my validation loss shown in the progress bar. My model is defined like this:
class DummyNet(pl.LightningModule):
    def __init__(self, batch_size):
        super().__init__()
        self.batch_size = batch_size
        self.fc = nn.Sequential(
            nn.Dropout(0.5),
            nn.Linear(512, 2)
        )
        # loss
        self.loss_fn = nn.CrossEntropyLoss()
        # metrics
        metrics = torchmetrics.MetricCollection(
            {
                "accuracy": torchmetrics.Accuracy(),
                "precision": torchmetrics.Precision(),
                "recall": torchmetrics.Recall(),
                "auc": torchmetrics.AUC(reorder=True),
            }, 
        )
        self.f1 = nn.ModuleDict({
            "train_f1": torchmetrics.F1(),
            "val_f1": torchmetrics.F1(),
            "test_f1": torchmetrics.F1(),
        })
        self.metrics = nn.ModuleDict({
            f"{k}_metrics": metrics.clone(prefix=k) for k in "train val test".split()
        })
    def forward(self, x):
        x = self.fc(x)
        return x
    
    def loop_step(self, batch, stage):
        x, targets = batch["windows"], batch["diagnosis"]
        logits = self(x)
        loss = self.loss_fn(logits, targets)
        preds = logits.argmax(-1)
        # computing metrics
        f1_str = f"{stage}_f1"
        metric_str = f"{stage}_metrics"
        self.f1[f1_str](preds, targets)
        self.metrics[metric_str](preds, targets)
        # logging metrics
        on_step = False if stage != "train" else True
        self.log(f1_str, self.f1[f1_str], on_step=on_step, on_epoch=True)
        self.log_dict(self.metrics[metric_str], on_step=False, on_epoch=True)   
        self.log(f"{stage}_loss", loss, on_step=on_step, on_epoch=True)
        return loss
    
    def training_step(self, batch, batch_idx):
        return self.loop_step(batch, "train")
    
    def validation_step(self, batch, batch_idx):
        return self.loop_step(batch, "val")

    def testing_step(self, batch, batch_idx):
        return self.loop_step(batch, "test")

    def configure_optimizers(self):
        return torch.optim.AdamW(self.parameters(), lr=0.001, weight_decay=0.01)

But as of now none of my metrics nor my validation loss comes up in the progress bar. Is it because I'm returning loss in the dictionary and not "{stage}_loss"?
Thank you.
Hi @FeryET, I believe the below should work as documented in https://pytorch-lightning.readthedocs.io/en/latest/extensions/logging.html#automatic-logging.
self.log(..., prog_bar=True)