TypeError: on_validation_end() missing 1 required positional argument: 'outputs' #17182
-
Hello, When I train my model, I get this error: TypeError: on_validation_end() missing 1 required positional argument: 'outputs' This is the function inside my model class:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
hey @dimgag! I had the same problem recently. As of class MyLightningModule(L.LightningModule):
def __init__(self):
super().__init__()
self.validation_step_outputs = []
def validation_step(self, ...):
loss = ...
self.validation_step_outputs.append(loss)
return loss
def on_validation_epoch_end(self):
epoch_average = torch.stack(self.validation_step_outputs).mean()
self.log("validation_epoch_average", epoch_average)
self.validation_step_outputs.clear() # free memory |
Beta Was this translation helpful? Give feedback.
-
Thank you very much, my same problem has been solved! |
Beta Was this translation helpful? Give feedback.
-
So how do you solve it at last |
Beta Was this translation helpful? Give feedback.
hey @dimgag! I had the same problem recently. As of
lightning>=2.0.0
you have to define thevalidation_step_outputs
in the init clause of your module to store the validation outputs of each epoch. Here's an example (from this PR).