Quite a lot of fastai users were interested in batch prediction such as from here and some other webpages. Either the solutions are for FastAI v1 (which the solution no longer applicable in v2 by comparing the keyword arguments passed into the function not available) or… no or.
Hence, looking into how learn.predict()
works, the simplest solution one found is to modify it and do monkey patching. Here is the code.
from fastai.vision.all import *def predict_batch(self, item, rm_type_tfms=None, with_input=False):
dl = self.dls.test_dl(item, rm_type_tfms=rm_type_tfms, num_workers=0)
ret = self.get_preds(dl=dl)
return retLearner.predict_batch = predict_batch
Then, this could be done in batch prediction now, returning what originally learn.get_preds()
would return.