Lesson2 download - predict returns tensor(0) or 1 or 2

Well I go through the lesson2_download and my model trains ok and I have cleaned the images and then I try to do the final actual prediction by

pred_class,pred_idx,outputs = learn.predict(img)
pred_class

and it gives me tensor(0) (for black bears), tensor(1) for (grizzlys) or tensor(2) (for teddys)

so it is working just it is not returning the class name its returning this tensor(n) - I don’t know how to get the name right?

Frustrating - luckily I did see it is actually working by trying different images.

So weird that the notebook does not match the lecture, for newbies, this is extremely frustrating - just let the lecture match the notebook, why let them go out of sync? Put up a new notebook if there are different methods and new functions that have been introduced since the lecture, but have the lecture’s notebook stay pure. This is a major problem I have trying to get into python, everything is changing nothing is constant, I struggle to get something to work and then when I’ve finally half figured it out things have changed and now I have to relearn, with nothing working so it feels like a waste of effort … enough of my rant.

1 Like

Can you please post a Gist or Colab showing this behavior?
What does learn.predict(img) return in your case?

1 Like

Hello Stephen,

I guess you can get the name with the following:

learn.data.classes[to_data(pred_class)]

I don’t know if there is a simpler way to do it, but I tried this one and it works.

Getting tensor(n) is normal, you can read details here: https://docs.fast.ai/basic_train.html#Learner.predict

And, please don’t get frustrated. The more errors you find the more you learn and you get expertise with time.

I hope you find this helpful,

Good luck!

2 Likes

Thanks Hajar
It took quite a few trys, and then

pred_class,pred_idx,outputs = learn.predict(img)
learn.data.classes[to_data(pred_class)]

Worked correctly.

2 Likes

Thanks FraPochetti

I’m going to work on learning how to post to a ‘gist’ .