Lesson 1 Bird_or_not

In lesson one we collect a images of birds and forrest (in various lighting condintions). Then we fine tune the model. In the las section we see how well the model porformed.

#TEST FOR CAT BY PASSING IN ‘BIRD.JPG’
is_bird,_,probs = learn.predict(PILImage.create(‘bird.jpg’))
print(f"This is a: {is_bird}.“)
print(f"Probability it’s a bird: {probs[0]:.4f}”)

This is a: bird.
Probability it’s a bird: 1.0000

My question is if we asked to predict if input image was forest.jpg like:

#TEST FOR FOREST BY PASSING IN ‘FOREST.JPG’
is_forest,_,probs = learn.predict(PILImage.create(‘forest.jpg’))
print(f"This is a: {is_forest}.“)
print(f"Probability it’s a forest: {probs[0]:.4f}”)

This is a: forest.
Probability it’s a forest: 0.0000

Where in the code/learning did configure the model to learn to predict and bird but not a forest?
When I pass in a forest you can it determine it’s a forest but Probability it’s a forest IS 0?

What did you miss?

Thanks so much
Saurabh

1 Like

Hello. In this case:

is_forest,_,probs = learn.predict(PILImage.create('forest.jpg'))
print(probs)

will return tensor([0.00, 1.00])

It seems like:
probs - something similar to a python list, with probabilities, that something belongs to each class
prob[0] - the probability that something is a bird
prob[1] - the probability that something is a forest

Why are they in that order? Because here:

dls = DataBlock(
    blocks=(ImageBlock, CategoryBlock), 

We are using CategoryBlock, which default sorts the categories alphabetically, and ‘bird’ is earlier than ‘forest’ ; )

So you should do this instead:

print(f"Probability it’s a forest: {probs[1]:.4f}")

Data block – fastai

Thank you so much for your precise answer. Clearly I need to understand the data structures better. I wish however that:
print(f"Probability it’s a forest: {probs[1]:.4f}")
could have been used like:
print(f"Probability it’s a forest: {probs(‘is_forest’):.4f}")

STILL LOST
I am having difficulty navigating forum! Like how do I find the page to post a question. For instance I could not find my original question from the forums page. I had to ‘reply’ to you answer to navigate to/find my question.

I am also having trouble understanding the structure of the course. Part 1 should be completed before Part 2. So, Part one has
Part 1:Getting Started;
Part 1:Deployment
Part 1:Neural Net Foundations
Part 1:…
Part 1:…
.
Where do chapters or lessons it into this hierarchy??
Part 1:Getting Started:Lesson (bird_or_not)1 → Where/What is lesson 2 ???
Part 1:Deployment:Lesson1 1???

Hi Saurabh! The course is here https://course.fast.ai/. You can find the lesson structure on the left side of that page. Then you can post questions here Part 1 2022 - fast.ai Course Forums. You can find topics for each lesson that are named like “Lesson X official topic”.