How to make predictions with vision learner? (solved)


#1

I have trained a model, and want to put some new arbitrary images (that were not apart of the training/testing/validation) through it.

I can’t figure out how. The ‘predict’ method does not accept a path to an image.

e.g.

learn.predict(f"{BASE}/test/0aa98293e.jpg ")

The entire notebook with the training can be found here: https://github.com/gdoteof/neuralnet_stuff/blob/master/kaggle_whales.ipynb

Ultimately what I am trying to do take that test folder and get the top 5 predictions for each image.


#2

As shown here, learn.predict takes an Image, not a filename.


#3

I appreciate the link and have looked there. That is showing how to do a prediction on data that is already “in” the learner.

I am trying to figure out how to load the image from disk into an “image” as you say.


#4

Is there a tutorial anywhere on how to use learn.predict on data that is not a part of the training?


#5

@sgugger the link you provided has reference to load_learner which doesn’t seem to exist anymore?


(Dilip Thiagarajan) #6

At the very worst, I think you could call learn.model() on your input, but I think you’d have to make sure to transform the input properly if necessary.


#7

As @sgugger has said, the function takes an Image, while you are passing a string.

Open the image and pass that instead.

You can find it here


#8

Thanks @miko

Now it looks like predict eturns the top category and a list of probabilities for all categories.

I am not sure how to map the human readable categories to the list of probabilities returned.

e.g.


cat, tensor, probs = learn.predict(open_image(f"{BASE}/test/d042ac24f.jpg"))

where probs is a tensor of length num_cats that, I presume, maps to a list of categories.

I am trying to get the top 5 (rather than top 1) most likely labels.


#9

i have too many questions about the return of predict. i will open a new thread.