Part 1 - intro.ipynb

I get an error when I run this code…please advise a solution!

img = PILImage.create(uploader.data[0])

is_cat,_,probs = learn.predict(img)

print(f"Is this a cat?: {is_cat}.")

print(f"Probability it's a cat: {probs[1].item():.6f}")

error

FileNotFoundError: [Errno 2] No such file or directory: 'images/chapter1_cat_example.jpg'

You don’t say where you are running this. Is it on, colab or your own machine. Have you run all the preceding cells?

Either way you may need to adjust the path in the code to point to where the cat image is located.

You can find the image in the repo. GitHub - fastai/fastbook: The fastai book, published as Jupyter Notebooks

I am running this from the course notebook itself (on colab) that is here

[Google Colab]

I ran the preceding cells as follows:

uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg'])
uploader.data[0]

You can ignore that cell / don’t run it, it was for the book

# For the book, we can't actually click an upload button, so we fake it
uploader = SimpleNamespace(data = ['images/chapter1_cat_example.jpg']) #don't run this

As you are on Kaggle, you run the upload and choose any image from your machine. (You can download the cat image from the repo to your home machine and try that, if you want). Unlike the book, this bit does not need to be faked, you can interact with it and upload any image to test.

Run this part. …

uploader = widgets.FileUpload()
uploader

Then click on the upload button that just appeared and select an image to test.
then run

img = PILImage.create(uploader.data[0])
is_cat,_,probs = learn.predict(img)
print(f"Is this a cat?: {is_cat}.")
print(f"Probability it's a cat: {probs[1].item():.6f}")

1 Like

Thanks Allen

Just one notebook related question - is it ok to work in colab or does one need to necessarily work in kaggle notebook ?

Either is fine. It is good to get some experience with both. There will be times when you use up your free GPU hours on one or the other or you want to enter a Kaggle competition. You’ll discover your own reasons for preferring one over the other at any given time.

If you follow along the course in conjunction with the book, you will get to use both. :grinning:

Thanks Allen

As for the course, I am simply following the colab content on this link

https://course.fast.ai/Resources/book.html#colab

Thank you! This wasn’t obvious to me. I kept getting stuck here.