How to get predictions?


After I have trained a model, I want to use the model to get predictions on a (large) number of unlabeled images. How would I go about doing this? I can do it with learn.get_preds() but this expects a dataloader. How do I create a test dataloader with no “y” and no loss?

You should be able to do learn.predict(image).

No, that gives me a prediction for a single image. I want to get predictions for a large amount of images at the same time (so a for loop is out of the question).

I know I can do a pytorch dataloader on my own, but I want to use fastai’s transforms.

There was another thread about speed of predictions. Trying to reproduce that here:

dl = learn.dls.test_dl(images)
inp, preds,_,dec_preds = learn.get_preds(dl=dl, with_input=True, with_decoded=True)
full_list = learn.dls.decode_batch((*tuplify(inp),*tuplify(dec_preds)), max_n=9)

And my code for inference:
preds= [ pred[1] for pred in full_list]



  1. ‘images’ are the ‘Path’ to the test images
  2. 9 is the number of records. You could give more.
1 Like