Usage of Trainer.test #10218
Unanswered
Keredu
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 2 comments 1 reply
-
hey, I think this was resolved over slack right? is it the same one? |
Beta Was this translation helpful? Give feedback.
1 reply
-
For some reason, my test method doesn't print out the metric. def test_step(self, batch, batch_idx):
x, y, _ = batch
preds = self.forward(x)
test_losses = self.valid_loss(preds, y)
focal = test_losses["focal"] * self.focal_strength
dice_loss = test_losses["dice_loss"] * (1 - self.focal_strength)
test_loss = focal + dice_loss
self.log('test_loss', test_loss, prog_bar=True)
self.valid_metric(preds, y)
return {
'test_loss': test_loss.sum(),
'test_mean_dist': self.valid_metric
} Meanwhile, validate works, but the labels are strange: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussed in #10218
Originally posted by Keredu October 28, 2021
Hi,
I would like to ask about how to use Trainer.test correctly. In this google colab link, I have developed a minimal example using MNIST Dataset where:
trainer.test(model=model, datamodule=datamodule)
, which returns the same metrics thattrainer.test(model=model, datamodule=datamodule, ckpt_path='.best.ckpt')
andtrainer.test(model=model, datamodule=datamodule, ckpt_path='best')
, as expected.for
loop to evaluate my model and it gives me different results:3.1. Evaluate using the model trained some chunks before: I get the same result that using trainer.test. I expected to obtain the results of the last epoch instead.
3.2 Evaluate using
model.resume_from_checkpoint('best.ckpt')
: I get a completely different result than in the previous approaches.3.3 Evaluate using
model.resume_from_checkpoint('last.ckpt)
: I get the same result than 3.1.Thanks in advance for your time.
Trainer.test used:
Loop used to evaluate the model:
and returns:
Beta Was this translation helpful? Give feedback.
All reactions