2020 Lesson 2 / 02_production FileNotFoundError images/grizzly.jpg

Hello,

I was seeing a minor issue with some of the example code in the ‘Gathering Data’ section of 02_production.

The cell reads:
dest = ‘images/grizzly.jpg’
download_url(ims[0], dest)

This fails with a File Not Found error.

I’m using Google Colab, and the courses v4 repo.
I think the issue was the fact there was no ‘images’ folder.
and in Colab I could not just use a terminal to create one.

The solution appeared to be just:
import os
os.mkdir(‘images’)

The above seemed to stop the issue.
Thanks
Pete

22 Likes

Thanks! This worked for me too as I got the same issue in paperspace!

Andy

Thanks Andy - sport on

Anyone wondering where they can locate their “images” directory can use the following code

os.path.abspath("images")    

Also you can list all the files in your directory

os.listdir("images")

I just found out these.

2 Likes

Hello i had a simillar problem than i fixed it like you described,
but i have the problem that when i download the images it does download the images but my
fns = get_image_files(path)
fns
has no elements in it the output is : (#0) [] instead of smthing like:
[Path(‘bears/black/00000095.jpg’),Path(‘bears/black/00000133.jpg’),Path(‘bears/black/00000062.jpg’),Path(‘bears/black/00000023.jpg’),Path(‘bears/black/00000029.jpg’),Path(‘bears/black/00000094.jpg’),Path(‘bears/black/00000124.jpg’),Path(‘bears/black/00000056.jpeg’),Path(‘bears/black/00000046.jpg’),Path(‘bears/black/00000045.jpg’)…
probably i have selected the wrong or no directory

Thanks, Pete! This helped me.

Refresh your browser and rerun everything, this should solve your problem…I had the same problem but then I did a hard restart.

I tried your method but it didn’t work, I am using gradient, after restart the kernel and rerun, I still got this output:

(#0) [ ]

Since the condition for the if statement to execute the code is if path.exist() is not True, which means the code below the if state can only be executed if the condition is False.

If you already create the path and thus path.exist() is True then the if block won’t be executed, means it will not create separate folders for each type of bear and it won’t download bear images either

So all you have to do is remove these 2 lines of code and it will work just fine:

if not path.exist():
path.mkdir()

Unfortunately that does not work for me either. I am getting following error code:

RemoteTraceback Traceback (most recent call last)
_RemoteTraceback:
“”"
Traceback (most recent call last):
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 239, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 198, in _process_chunk
return [fn(*args) for args in chunk]
File “/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py”, line 198, in
return [fn(*args) for args in chunk]
File “/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/xtras.py”, line 367, in _call
return g(item)
File “/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/vision/utils.py”, line 13, in _download_image_inner
suffix = re.findall(r’.\w+?(?=(?:?|$))’, url)
File “/opt/conda/envs/fastai/lib/python3.8/re.py”, line 241, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or bytes-like object
“”"

The above exception was the direct cause of the following exception:

TypeError Traceback (most recent call last)
in
3 dest.mkdir(exist_ok=True)
4 results = search_images_bing(key, f’{o} bear’)
----> 5 download_images(dest, urls=results.attrgot(‘content_url’))

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastai/vision/utils.py in download_images(dest, url_file, urls, max_pics, n_workers, timeout)
22 dest = Path(dest)
23 dest.mkdir(exist_ok=True)
—> 24 parallel(partial(_download_image_inner, dest, timeout=timeout), list(enumerate(urls)), n_workers=n_workers)
25
26 # Cell

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/xtras.py in parallel(f, items, n_workers, total, progress, pause, threadpool, timeout, chunksize, *args, **kwargs)
418 if total is None: total = len(items)
419 r = progress_bar(r, total=total, leave=False)
–> 420 return L®
421
422 # Cell

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/foundation.py in call(cls, x, *args, **kwargs)
161 def call(cls, x=None, *args, **kwargs):
162 if not args and not kwargs and x is not None and isinstance(x,cls): return x
–> 163 return super().call(x, *args, **kwargs)
164
165 # Cell

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/foundation.py in init(self, items, use_list, match, *rest)
171 if items is None: items = []
172 if (use_list is not None) or not is_array(items):
–> 173 items = list(items) if use_list else listify(items)
174 if match is not None:
175 if is_coll(match): match = len(match)

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastcore/basics.py in listify(o)
49 if isinstance(o, list): return o
50 if isinstance(o, str) or is_array(o): return [o]
—> 51 if is_iter(o): return list(o)
52 return [o]
53

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastprogress/fastprogress.py in iter(self)
45 except Exception as e:
46 self.on_interrupt()
—> 47 raise e
48
49 def update(self, val):

/opt/conda/envs/fastai/lib/python3.8/site-packages/fastprogress/fastprogress.py in iter(self)
39 if self.total != 0: self.update(0)
40 try:
—> 41 for i,o in enumerate(self.gen):
42 if i >= self.total: break
43 yield o

/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/process.py in _chain_from_iterable_of_lists(iterable)
482 careful not to keep references to yielded objects.
483 “”"
–> 484 for element in iterable:
485 element.reverse()
486 while element:

/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/_base.py in result_iterator()
609 # Careful not to keep a reference to the popped future
610 if timeout is None:
–> 611 yield fs.pop().result()
612 else:
613 yield fs.pop().result(end_time - time.monotonic())

/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/_base.py in result(self, timeout)
430 raise CancelledError()
431 elif self._state == FINISHED:
–> 432 return self.__get_result()
433
434 self._condition.wait(timeout)

/opt/conda/envs/fastai/lib/python3.8/concurrent/futures/_base.py in __get_result(self)
386 def __get_result(self):
387 if self._exception:
–> 388 raise self._exception
389 else:
390 return self._result

TypeError: expected string or bytes-like object

Can anyone help with that? Much appreciate it

I seem to be getting a response to os.path.abspath(“images”)

But not to the second query os.listdir(“images”)

@koray.yesilli @ayukoizgosu I’ve managed to have both of these errors at different times. Were either of you able to find a solution?