icevision icon indicating copy to clipboard operation
icevision copied to clipboard

How to use Metrics class to check the performance of the trained model

Open tugot17 opened this issue 5 years ago • 12 comments

📓 New <Tutorial/Example>

Is this a request for a tutorial or for an example?
Tutorial

What is the task? Lets say I trained a model and now I want to check its performance on the brand new dataset. I don't want to retrain the whole model, I just want to check its performance. How to do it using Metric Class. Lets assume that COCO metric is fine for me.

metric = COCOMetric(metric_type=COCOMetricType.bbox)

How do I use it so I know exact performance on the new dataset?


Don't remove Main issue for examples: #39

tugot17 avatar Sep 03 '20 10:09 tugot17

Actually, there is no current easy way of doing this, can you describe the solution you would like?

Maybe a function that take the model, a dataloader, and the metrics?

lgvaz avatar Sep 04 '20 18:09 lgvaz

Maybe a list of metrics instead of a single metric?

tugot17 avatar Sep 05 '20 13:09 tugot17

@fstroth @potipot you guys both worked on COCOMetric. Is this possible? Frederik, maybe with your dashboard?

FraPochetti avatar Dec 18 '21 14:12 FraPochetti

@FraPochetti The dashboard lib already allows for evaluating a model on new (validation) data outside of training.

fstroth avatar Dec 19 '21 16:12 fstroth

Great. Closing this one, then. @tugot17 please refer to the IceVision Dashboard built by @fstroth for more info.

FraPochetti avatar Dec 19 '21 16:12 FraPochetti

There is an option to test a trained model. Assuming its weights are already loaded you can use for fastai:

learner.validate(test_dl) 

for pytorch-lightning

result = trainer.test(lightning_model, test_dl)

potipot avatar Dec 19 '21 20:12 potipot

There is an option to test a trained model. Assuming its weights are already loaded you can use for fastai:

learner.validate(test_dl) 

for pytorch-lightning

result = trainer.test(lightning_model, test_dl)

Would this calculate the COCOMetric? I guess it would compute any metric the learner (or PL Module) was instantiated with.

FraPochetti avatar Dec 19 '21 20:12 FraPochetti

I'd say this could be a FAQ so we should think of showcasing this in a notebook linked on a website.

potipot avatar Dec 19 '21 21:12 potipot

Yes I agree. Keeping it here open as a reminder

FraPochetti avatar Dec 19 '21 21:12 FraPochetti

@ai-fast-track maybe we can add a cell or two showing how to do this to the inference.ipynb

FraPochetti avatar Dec 20 '21 22:12 FraPochetti

@potipot @FraPochetti

result = trainer.test(lightning_model, test_dl)

This does not work in PL right now since IceVision PL adapters do not implement the test_step (eg: https://github.com/airctic/icevision/blob/master/icevision/models/torchvision/lightning_model_adapter.py)

pytorch_lightning.utilities.exceptions.MisconfigurationException: No `test_step()` method defined to run `Trainer.test`

AlexandreBrown avatar Jul 12 '22 14:07 AlexandreBrown

@tugot17 Just opened a PR to add support for Pytorch Lightning Trainer test with IceVision models.

Take a look https://github.com/airctic/icevision/pull/1125

This should solve your issue.

AlexandreBrown avatar Jul 22 '22 17:07 AlexandreBrown