ClassificationInterpretation.from_learner(inf_learner) gives error: TypeError: __init__() missing 1 required positional argument: 'losses'

Hello everyone,

After going throug the lesson 2 notebook, I trained my own model to try to reinforce the material. I trained and saved the model, and loaded the model, but I am getting an error when I try to create a ClassificationInterpretation object. I am able to do classifications with the model, so I know it loaded properly. I also tried calling validate on the learner (inf_learner.validate(dl=inf_learner.dls.valid), Result: (#2) [None,None]), but it did not change the error.

I also tried recreating the data loader (same seed, same data), and then doing this::
classification_interpretation = ClassificationInterpretation.from_learner(inf_learner, dl=dog_data_loader.valid), which resulted in AssertionError: ==: 1 64

Any help would be greatly appreciated :slight_smile:

Thank you.


inf_learner = load_learner(path/model_name)
classification_interpretation = ClassificationInterpretation.from_learner(inf_learner)


TypeError                                 Traceback (most recent call last)
<ipython-input-39-b56c6e7dab63> in <module>
----> 1 classification_interpretation = ClassificationInterpretation.from_learner(inf_learner)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/ in from_learner(cls, learn, ds_idx, dl, act)
     27         "Construct interpretation object from a learner"
     28         if dl is None: dl = learn.dls[ds_idx]
---> 29         return cls(dl, *learn.get_preds(dl=dl, with_input=True, with_loss=True, with_decoded=True, act=None))
     31     def top_losses(self, k=None, largest=True):

TypeError: __init__() missing 1 required positional argument: 'losses'

Were yo able to solve this?

I encountered the same problem today. I think what you are trying to do is get the classification report from the .pkl file. The problem with that is that you would need to redefine the dataloaders for train and validation.

If you want to get the classification report from the data you trained the model on, you need to assign those same dataloaders for training and validation.

dls = DataLoader().... # your defined dataloader during training

inf_learner = load_learner(path/model_name)
inf_learner.dls.train = dls.train
inf_learner.dls.valid = dls.valid