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
lucasvw
(Lucas)
February 10, 2023, 9:15am
466
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
danwash
(Dan W)
February 16, 2023, 10:54pm
467
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
raz
February 17, 2023, 2:51am
468
I’m getting the exact same error
bencoman
(Ben Coman)
February 17, 2023, 1:10pm
469
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
danwash
(Dan W)
February 17, 2023, 1:43pm
470
@bencoman Thanks for the help! I used your code to switch it to 2.7.10 and can confirm that it works.
1 Like
Raphomet
(Raph)
February 17, 2023, 8:05pm
471
@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
raz
February 18, 2023, 9:14pm
472
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
lucasvw
(Lucas)
February 19, 2023, 11:58am
474
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
Akindele
(Akindele Michael)
February 19, 2023, 1:08pm
475
Thanks to @lucasvw for sharing where!
bencoman
(Ben Coman)
February 21, 2023, 9:57am
477
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.
gizzard
February 22, 2023, 9:54am
478
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!
montanoj14
(Joel Montano)
February 22, 2023, 2:22pm
479
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:
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.
Seems like the newest release no longer supports PIL images being passed as parameter.
Instead, the predict method takes care of all of that for you. You can just pass the name of the file:
img_filename = 'bird.jpg'
is_bird,_,probs = learn.predict(image_filename)
3 Likes
bencoman
(Ben Coman)
February 22, 2023, 2:54pm
480
Following up my own post, rather than revert to 2.7.10, zerosingularity found a better solution…
Seems like the newest release no longer supports PIL images being passed as parameter.
Instead, the predict method takes care of all of that for you. You can just pass the name of the file:
img_filename = 'bird.jpg'
is_bird,_,probs = learn.predict(image_filename)
3 Likes
gizzard
February 22, 2023, 9:36pm
481
@montanoj14 and @bencoman thanks very much for your assistance, much appreciated. All working now!
SRS-One
February 24, 2023, 6:50pm
482
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
SRS-One
February 24, 2023, 6:56pm
483
(above - referencing the recent discussion by montanoj14, bencoman, and gizzard)
gmjn
(Germjan Bosma)
February 24, 2023, 7:09pm
484
@SRS-One the bug is noted on the fastai github.
opened 06:57AM - 22 Feb 23 UTC
As of the fastai 2.7.11 release, there are reports on the fastai [discord](https… ://discord.com/channels/689892369998676007/748330524556132364/1075861042875334738) and [forums](https://forums.fast.ai/t/beginner-basics-of-fastai-pytorch-numpy-etc/96285/47) that the [Is it a bird? Creating a model from your own data](https://www.kaggle.com/code/jhoward/is-it-a-bird-creating-a-model-from-your-own-data) Kaggle notebook errors out on the prediction step.
Specifically, here, due to passing in a `PILImage` instead of a Pillow Image or file name:
```python
is_bird,_,probs = learn.predict(PILImage.create('bird.jpg'))
```
Rolling back to fastai 2.7.10 is supposed to [prevent the issue from occurring on Kaggle](https://forums.fast.ai/t/lesson-1-official-topic/95287/469), but when I created a new conda env locally with 2.7.10 I still ran into the error. It's possible that this error occurred due to #3872, or maybe a difference in Pillow versions as I think `PILBase.create` should behave the same in 2.7.10 and 2.7.11 if passed a `PILImage`.
There is a PR to fix the course notebook fastai/course22#52, but I think `learn.predict` should accept a `PILBase` instance, and this issue should be fixed in fastai.
P.S. You can edit your post afterwards. By clicking the pencil button
Reuben
(Reuben B)
February 25, 2023, 8:04am
485
“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