Can't predict on Tabular or Collab Learners

I am using fastai v2.0.15 and no matter what I pass into predict I get

/opt/conda/lib/python3.6/site-packages/fastai/learner.py in predict(self, item, rm_type_tfms, with_input)
    245 
    246     def predict(self, item, rm_type_tfms=None, with_input=False):
--> 247         dl = self.dls.test_dl([item], rm_type_tfms=rm_type_tfms, num_workers=0)
    248         inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
    249         i = getattr(self.dls, 'n_inp', -1) ...

... TypeError: list indices must be integers or slices, not list

I’ve tried everything from the forum & other sources & also tried even passing in None types or anything at all. Same result. I’m wondering is it something to do with my environment or something else?

Any help appreciated.

Can you post your Code please?

Hi Florian,

Sure:

It doesn’t seem to matter what I pass into the predict function as the error is always the same and points to the line in my OP

Hi, I am having the same problem as well. Did you ever find a solution? I’m trying to use my collab_learner model to make predictions on a test set.

Same issue. I load my exported collab learner:

And I create a single DataLoader object from the same DataLoaders object that was used to train the model, even trying to replicate the source code for Learner.get_preds():

But I still get an error:

Please help, I need to be able to make predictions with my collab model.

Alright, I figured it out, at least for my use case. The new DataLoader needs to be created by passing the new DataFrame into learn.dls.test_dl(). Then you can call learn.get_preds() with the new DataLoader:

4 Likes

This worked for me. Thanks. The documentation needs to be updated for this one.