Trainer is not attached to model

Viewed 35

I am using pytorch lightning to train a model. I want to log the performance metric, and I am using the following code in the validation_epoch_end() to do that:

def validation_epoch_end(self, outputs) -> None:
    super().__init__()
    mean_loss = torch.mean(torch.stack([o["Val_Loss"] for o in outputs]))
    mean_rocauc = np.mean(np.array([o["Score"] for o in outputs]))
  
    self.log("val_loss",mean_loss,on_epoch=True,prog_bar=True)
    self.log("val_score",mean_rocauc,on_epoch=True,prog_bar=True)

Now I fit the model to trainer using the following code:

trainer = pl.Trainer(max_epochs=2,accelerator="gpu",devices=1)
trainer.fit(model=model,train_dataloaders=train_dataloader,val_dataloaders=dev_dataloader)

I am getting the following error:

RuntimeError: MemeNet is not attached to a `Trainer`.

Note that MemeNet is the name of my model. For some reason logging is failing but I don't know why.

0 Answers
Related