Inference learner on multiple test datasets

In the fastai inference learner tutorial, we can load a trained learner to predict on a test set by

learn = load_learner(path, test=ImageList.from_folder(path/'test'))
preds,y = learn.get_preds(ds_type=DatasetType.Test)

If I’m using the same learner to make predictions on multiple folders of images, i.e. I have


etc. I don’t want to have to reload the learner each time, as that can take up a lot of time, particularly if the model is big.

If I use'test1')
preds,y = learn.get_preds(ds_type=DatasetType.Test)'test2')
preds,y = learn.get_preds(ds_type=DatasetType.Test)

Will the predictions from path/'test2' contain the predictions from the 1st test folder?

No, the command is maybe misnamed, but the second add_test_folder will replace the first.

When I tried'test1'), I get the following error

AttributeError                            Traceback (most recent call last)
<ipython-input-13-eceb0409aed8> in <module>()
----> 1'test')
      2 preds,y = learn.get_preds(ds_type=DatasetType.Test)

~/anaconda3/lib/python3.6/site-packages/fastai/ in __getattr__(self, k)
    120         return cls(*dls, path=path, device=device, dl_tfms=dl_tfms, collate_fn=collate_fn, no_check=no_check)
--> 122     def __getattr__(self,k:int)->Any: return getattr(self.train_dl, k)
    123     def __setstate__(self,data:Any): self.__dict__.update(data)

~/anaconda3/lib/python3.6/site-packages/fastai/ in __getattr__(self, k)
     37     def __len__(self)->int: return len(self.dl)
---> 38     def __getattr__(self,k:str)->Any: return getattr(self.dl, k)
     39     def __setstate__(self,data:Any): self.__dict__.update(data)

~/anaconda3/lib/python3.6/site-packages/fastai/ in DataLoader___getattr__(dl, k)
     18 = intercept_args
---> 20 def DataLoader___getattr__(dl, k:str)->Any: return getattr(dl.dataset, k)
     21 DataLoader.__getattr__ = DataLoader___getattr__

~/anaconda3/lib/python3.6/site-packages/fastai/ in __getattr__(self, k)
    641         res = getattr(y, k, None)
    642         if res is not None: return res
--> 643         raise AttributeError(k)
    645     def __setstate__(self,data:Any): self.__dict__.update(data)

AttributeError: add_test_folder

Yes, add_test_folder is a method on LabelLists (the thing you have before calling .databunch in the data block API) not DataBunch. You need to use add_test instead.

1 Like