How to get prediction using get_preds in fastai 2?

Hello, I have used Imagedataloader to load the train images and also trained my learner on it, but now i want to get prediction using get_preds() on my test images my test images are in a TEST Folder this folder has 300 mixed images. How to do it using get_preds and also how to set test path data loader.

Thanks!!

1 Like

you can use fastai learner’s add_test() method to replace the learner’s original test set with your data.

you can do:

files = get_image_files(TEST_FOLDER)
test_dl = learn.dls.test_dl(files)
preds = learn.get_preds(dl=test_dl)
5 Likes

add_test does not work anymore.

Thanks for sharing this .

It is strange. I’ve done as you describe but there the tuple has been returned with the 2nd ‘None’ element.

It confusing me, when I use simple

learn.get_preds()

I get validation set results. The 1st elemnt of the tuple return result of the last activation layer I guess (to use it in activation function) and the 2nd return the prediction values (in my case it 0-1 classification).

When I use your code

files = get_image_files(TEST_FOLDER)
test_dl = learn.dls.test_dl(files)
preds = learn.get_preds(dl=test_dl)

the 2nd val of tuple doesn’t return anything.