Fastai-v4_"05_pet_breeds" FileNotFoundError

I am getting error while i try to run this piece of code from the fastbook,here is the code

    dblock1 = DataBlock(blocks=(ImageBlock(), CategoryBlock()),
   dls1 = dblock1.dataloaders([(Path.cwd()/'images'/'grizzly.jpg')]*100, bs=8)
   dls1.train.get_idxs = lambda: Inf.ones
   x,y = dls1.valid.one_batch()
   _,axs = subplots(1, 2)

and the error being -

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

error being specificly for the line-

dls1 = dblock1.dataloaders([(Path.cwd()/'images'/'grizzly.jpg')]*100, bs=8)

Could anyone clarify what is going wrong?i am running it on google colab

sessions on colab get recycled pretty quickly if you leave them idle which means all the files vanish. when you come back it automatically reconnects but you’ll need to re-run previous cells which your current cell depends on. in your case probably just re-run everything from the top.

i tried re-running the notebook but the error persisted,could you try it once yourself just in case you face the same issue

Are you working on the cloned directory? It shows the path /content/images/ as the directory where the grizzly.jpg was not found. Maybe you have cloned the github repository but aren’t working where the grizzly.jpg is present.
If you have cloned the course-v4 on the google drive i.e. within content/My Drive/course-v4, then you need to go there to access the file or you could copy the course-v4 directory to content/ to access the files where you are right now.


Hi, I have the impression that the folder we just uploaded/untared is with pets not with bears. Perhaps this line is from a previous notebook. I have tried the following succesfully:

dls1 = dblock1.dataloaders([(path/'images'/'samoyed_167.jpg')]*100, bs=8)
instead of
dls1 = dblock1.dataloaders([(Path.cwd()/'images'/'grizzly.jpg')]*100, bs=8)


1 Like