Pytorch-lightning: trainer.evaluate() without trainer.fit()

Created on 8 Oct 2019  路  4Comments  路  Source: PyTorchLightning/pytorch-lightning

Describe the bug
I'd like to only evaluate fitted model with Trainer instance by calling its evaluate method

To Reproduce
Steps to reproduce the behavior:

model = MyLightningModule()
trainer = Trainer()
trainer.evaluate(model, model.val_dataloader(), max_batches=100)

Gets TypeError: 'NoneType' object is not callable when it tries to call trainer.get_val_dataloaders which is does not have, because fit wasn't called before
Expected behavior
Passing the model and dataloader into evaluate should be enough to evaluate model's performance.

bug / fix

All 4 comments

Perhaps evaluate is not meant to be used like that. Maybe use test instead?
Define the test methods and then call trainer.test(): see here and here

You can then limit the size of your dataset inside the test_dataloader method.

Or do I misundestand?

Evaluate should really be a private method. not meant to be used externally

Got it, thanks!

Can I get metrics named 'val_*' without training?
Trainer.test(test_dataloaders...) will produce metrics called test_ with my current code. The easiest way I can think of is to make an empty train dataset?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Vichoko picture Vichoko  路  3Comments

versatran01 picture versatran01  路  3Comments

srush picture srush  路  3Comments

chuong98 picture chuong98  路  3Comments

baeseongsu picture baeseongsu  路  3Comments