Lesson 1 official topic

Hi everyone.

Stupid question1/n

In lesson1-pets.ipynb I am unable to fic the error that pops up when I try to run help(untar_data) line, even with the help of Chat GPT.

I have installed fastai and tried to import it as well
!pip install fastai

from fastai.datasets import untar_data

I get this error
NameError Traceback (most recent call last)

in
----> 1 help(untar_data)

NameError: name ‘untar_data’ is not defined

untar_data is not inside of fastai.datasets but in fastai.data.external, at least in the latest version of fastai.

See also this page which says that it’s deprecated.

You can do:

from fastai.data.external import untar_data

doc(untar_data)

Alternatively, you can also do

from fastai.vision.all import *

doc(untar_data)
1 Like

Hi! I’ve just started the course and I’m getting an error on the final step of the first notebook. I copied the “Is it a bird? Creating a model from your own data” notebook and haven’t edited anything. Everything runs fine until I get the last step that does the actual prediction. It fails with the error below. The full error is much longer but I didn’t want to paste 100+ lines in here.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_17/1213330699.py in <module>
----> 1 is_bird,_,probs = learn.predict(PILImage.create('bird.jpg'))
      2 print(f"This is a: {is_bird}.")
      3 print(f"Probability it's a bird: {probs[0]:.4f}")

/opt/conda/lib/python3.7/site-packages/fastai/learner.py in predict(self, item, rm_type_tfms, with_input)
    319     def predict(self, item, rm_type_tfms=None, with_input=False):
    320         dl = self.dls.test_dl([item], rm_type_tfms=rm_type_tfms, num_workers=0)
--> 321         inp,preds,_,dec_preds = self.get_preds(dl=dl, with_input=True, with_decoded=True)
    322         i = getattr(self.dls, 'n_inp', -1)
    323         inp = (inp,) if i==1 else tuplify(inp)

I tried creating a new notebook with the same code and ended up with the same result. Any ideas?

Here’s a link to the notebook: Is it a bird? Creating a model from your own data | Kaggle

3 Likes

I’m getting the exact same error

I can confirm the error. This is by taking my own new copy of Jeremy’s notebook.
It seems the issue is only with version 2.7.11, adding the line two lines here to cell 2…

if iskaggle:
    !pip install -Uqq fastai duckduckgo_search
import fastai
fastai.__version__

2.7.11

It works using the following in cell 2…

if iskaggle:
    !pip install -Uqq fastai==2.7.10 duckduckgo_search
import fastai
fastai.__version__

2.7.10
If it doesn’t say 2.7.10, try a restart or factory reset.

I’m not much practiced at debugging more deeply on kaggle.
@jeremy, you may want to have a look.

4 Likes

@bencoman Thanks for the help! I used your code to switch it to 2.7.10 and can confirm that it works.

1 Like

@bencoman 's fix worked for me as well. I had to “Factory reset” the session (I’m using Kaggle) for it to take.

1 Like

I fixed it by just using bird.jpg instead of PILImage.create('bird.jpg').
So the line would be is_bird,_,probs = learn.predict('bird.jpg')
Cheers!

4 Likes

This seems to have to do with the newest version of fastai, see here Beginner: Basics of fastai, PyTorch, numpy, etc ✅ - #50 by zerotosingularity as well as some messages directly above yours in this thread

2 Likes

Thanks to @lucasvw for sharing where!

Thanks!

You must have missed the immediately preceeding post in your research…

btw, could you please edit your post so that its length doesn’t clutter the page in perpetuity.

Hello, my first day of looking at the fastai course and forums (also in bed with COVID). Stuck at the first exercise of Lesson 1, go figure…

Wondering if anyone can help please?

When I run this line:

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

I get an error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_23/1585674285.py in <module>
      1 uploader = SimpleNamespace(data = ['/kaggle/input/images/IMG_6049.jpg'])
      2 img = PILImage.create(uploader.data[0])
----> 3 is_cat = learn.predict(img)
      4 # print(f"Is this a cat?: {is_cat}.")
      5 # print(f"Probability it's a cat: {probs[1].item():.6f}")

Copied straight from the book, so not sure what’s wrong here??
Thanks!

hey @gizzard I believe the issue is coming from line 2 due to PILImage not having a read attribute, after searching the forums for a bit, I wasn’t able to conclude on how to get the read attribute imported.

My workaround was to include the file path directly like so:
image

I’ll get back to you if I can get the read attribute to work

edit:
After searching the forum some more I found that the newest fastAI version doesn’t support PIL image being passed into the learn.predict() method anymore.

3 Likes

Following up my own post, rather than revert to 2.7.10, zerosingularity found a better solution…

3 Likes

@montanoj14 and @bencoman thanks very much for your assistance, much appreciated. All working now!

I thank you all for the assistance, as I was in need of this same bit of help.

Should I/we seek to alert JHoward (or some Fast AI person/entity) to this difficulty? It’s very early in the course, and it seems this could easily “derail” many people just getting their start.

I look forward to any replies.

Again, I thank you.

1 Like

(above - referencing the recent discussion by montanoj14, bencoman, and gizzard)

@SRS-One the bug is noted on the fastai github.

P.S. You can edit your post afterwards. By clicking the pencil button

“You must have missed the immediately preceding post in your research…”. - no shit.

I deleted my question so it does not clutter the forum in perpetuity.

1 Like