Predict the results for single image

I have completed lesson 1 (2019). I have all GPC setup and lesson1-pets.ipynb is working on my env. I want to predict for a single image. I have tried to get help from the forum but all results I got are for 2018 course. Some of the core structure is changed i.e. ImageClassifierData is not in 2019 course (I may be wrong).

What I am doing to predict for a single image?

learn.load('stage-1');
img = open_image('common-pomeranian-health-issues_canna-pet-1024x683.jpg').resize(224)
learn.predict(img)

I am getting the following results: (Category 3, tensor(0), tensor([9.9999e-01, 1.4821e-05]))

How to update my code to get result that given image is pomeranian dog?

Thanks.

It’s my bad. I just went through Lesson 1 notebook and run the predict method on learn object. This learn object was trained to identify the letters 3 and 7 so, this was showing wrong results. I figure it out today and rerun my notebook to train my model to identify the breed of dogs. then I downloaded different images from the internet and predict the result. I was surprised with the results.

Below is my code for predict:

# Pmmeranian
# !wget https://g77v3827gg2notadhhw9pew7-wpengine.netdna-ssl.com/wp-content/uploads/2017/09/common-pomeranian-health-issues_canna-pet-1024x683.jpg
# img = open_image('common-pomeranian-health-issues_canna-pet-1024x683.jpg')

# staffordshire_bull_terrier
!wget https://vetstreet.brightspotcdn.com/dims4/default/d121991/2147483647/crop/0x0%2B0%2B0/resize/645x380/quality/90/?url=https%3A%2F%2Fvetstreet-brightspot.s3.amazonaws.com%2F66%2F01e5c0a80811e0a0d50050568d634f%2Ffile%2FStaffordshire-Bull-Terrier-4-645mk062811.jpg
mv 'index.html?url=https%3A%2F%2Fvetstreet-brightspot.s3.amazonaws.com%2F66%2F01e5c0a80811e0a0d50050568d634f%2Ffile%2FStaffordshire-Bull-Terrier-4-645mk062811.jpg' 'staffordshire_bull_terrier.jpg'

img = open_image('staffordshire_bull_terrier.jpg')
img
learn.predict(img)

And below is the result:

(Category staffordshire_bull_terrier,
tensor(34),
tensor([2.8822e-07, 2.1651e-06, 2.4436e-07, 2.3763e-04, 2.0907e-05, 4.2072e-06,
     2.9036e-07, 2.8348e-06, 3.6598e-07, 2.0248e-05, 2.1426e-06, 9.0087e-07,
     5.1045e-04, 8.4238e-02, 1.6496e-06, 1.0291e-06, 1.2406e-04, 1.3355e-05,
     1.2869e-05, 6.3776e-07, 9.0699e-04, 5.5025e-06, 2.5859e-05, 5.7784e-06,
     3.1623e-06, 9.7203e-06, 6.5508e-05, 2.0064e-03, 8.3936e-07, 8.3686e-04,
     3.5783e-06, 1.1229e-06, 4.7360e-05, 2.1268e-06, 9.1088e-01, 1.4059e-06,
     7.8550e-06]))
1 Like