Cannot make Individual prediction work

I am trying to check if my dog is really a Border Collie!
I get the following error

I believe I am copying exactly what Jeremy did in lesson 3. can enybody help?
Alan

I have tried “everything” but cannot get it to work. I have copied exactly (I think) what Jeremy did with a photo from the training set (fn) and that does not work either.

My hack was to create a new folder (test1) which i put bseide the test folder which contained 2 pictures of my dog. I then ran get data with the test name pointing to test1 rather than test.
Then, after training I ran

<
log_preds,y = learn.TTA(is_test = True)
probs = np.exp(log_preds)
ans = probs.sum(axis = 0)/5
a = np.argmax(ans[0,:])
print(data.classes[a])

/>

which tells me that my dog is a border collie. He is very happy to know this!

Alan

Try converting the PIL image to a numpy array before calling val_tfms:

im = val_tfms(np.array(Image.open(...)))

Hi @AlanJ try using the open_image(filename) provided by fastai in dataset.py instead of Image.open(…) . Ex: im = val_tfms(open_image(f’{PATH}’+fn))

3 Likes

+1

open_image will convert your image to np.float32 and divide by 255, which is probably the version of your images you trained with (e.g. if you used the from_paths function).

1 Like

I am afraid it does not seem to work!!

Below is the code and the error. Using the alternative that is commented out gives the same error message.
Using im = np.array(Image.open(‘data/IMG_0074.JPG’)) also gives the same error message!

AlanCapture|690x303

Try setting learn.precompute = False. This will enable the full model rather than only the FC part.

Hi @AlanJ Please look at these other discussion where I posted my solution that worked for me. I have the predictSingleImage as a helper function. Give it a try. Here is the link to that solution. How do we use our model against a specific image?

That works, thanks. Rather annoying because I thought I had set precompute to False and that was the problem.
Alan