Image regression equivalent to plot_top_losses

Hi all,

I’m trying to train a model to predict age of a building from an image.

As such, it’s an image regression task (predicting numerical age) rather than image classification (predicting category).

I’ve trained the model and it has a reasonably poor mean absolute error, so I’m looking to see what it gets wrong by looking at the images where it performs worst.

On an image classification task, you can use .show_results, .plot_top_losses or cleaner and see the thumbnails in-line in the Jupyter Notebook. However, none of these seem to work for numerical outputs (example error: Exception: plot_top_losses is not implemented for <class ‘fastai.torch_core.TensorImage’>,<class ‘torch.Tensor’>).

Does anyone know if there’s a simple way to do this?

Many thanks

Did you construct an Interpretion or a ClassificationInterpretation object?
Interpretation should be agnostic to the specific task, if I understand the docs correctly (fastai - Interpretation of Predictions). Nonetheless, it shouldn’t be too hard to subclass the Interpretation class to work with regression tasks.

On another note: Did you try to formulate the problem as a multiclass classification problem by putting the building ages into buckets (10 - 20 years, 20-50 years etc.)? It often works much better than image regression.

Thanks very much for the advice. I had previously constructed an Interpretation object but got stuck when plot_top_losses didn’t work on it.

I’ve now fixed the issue using top_losses(n_losses, items=True)[2] on my Interpretation object, which returns a Dataframe with the image names in, which you can then display with PIL and matplotlib.

Interesting thought re bucketing. I chose regression as mislabelling a 200 year old building as 1 year old is ‘worse’ from a user perspective than labelling it as 150 years old, which regression captures. That said, I’ll give the bucketing a try, as the models have been pre-trained on classification tasks, so might perform better.