Hello, I just finished with lesson 1 of the course (Newbie here). While executing this code :
searches = ‘happy person’,‘sad person’,‘angry person’
path = Path(‘happy_sad_angry’)
for o in searches:
dest = (path/o)
dest.mkdir(exist_ok=True, parents=True)
download_images(dest, urls=search_images(f’{o} photo’))
resize_images(path/o, max_size=400, dest=path/o)
I’m getting the error -
---------------------------------------------------------------------------
_RemoteTraceback Traceback (most recent call last)
_RemoteTraceback:
"""
Traceback (most recent call last):
File "/root/mambaforge/lib/python3.9/concurrent/futures/process.py", line 246, in _process_worker
r = call_item.fn(*call_item.args, **call_item.kwargs)
File "/root/mambaforge/lib/python3.9/concurrent/futures/process.py", line 205, in _process_chunk
return [fn(*args) for args in chunk]
File "/root/mambaforge/lib/python3.9/concurrent/futures/process.py", line 205, in <listcomp>
return [fn(*args) for args in chunk]
File "/root/mambaforge/lib/python3.9/site-packages/fastcore/parallel.py", line 58, in _call
return g(item)
File "/root/mambaforge/lib/python3.9/site-packages/fastai/vision/utils.py", line 93, in resize_image
else: shutil.copy2(file, dest_fname)
File "/root/mambaforge/lib/python3.9/shutil.py", line 444, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/root/mambaforge/lib/python3.9/shutil.py", line 244, in copyfile
raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
shutil.SameFileError: Path('happy_sad_angry/happy person/bea49f63-fa26-431c-9853-1d487d692591.jpg') and Path('happy_sad_angry/happy person/bea49f63-fa26-431c-9853-1d487d692591.jpg') are the same file
"""
The above exception was the direct cause of the following exception:
SameFileError Traceback (most recent call last)
Input In [25], in <cell line: 4>()
6 dest.mkdir(exist_ok=True, parents=True)
7 download_images(dest, urls=search_images(f'{o} photo'))
----> 8 resize_images(path/o, max_size=400, dest=path/o)
File ~/mambaforge/lib/python3.9/site-packages/fastai/vision/utils.py:105, in resize_images(path, max_workers, max_size, recurse, dest, n_channels, ext, img_format, resample, resume, **kwargs)
103 files = get_image_files(path, recurse=recurse)
104 files = [o.relative_to(path) for o in files]
--> 105 parallel(resize_image, files, src=path, n_workers=max_workers, max_size=max_size, dest=dest, n_channels=n_channels, ext=ext,
106 img_format=img_format, resample=resample, resume=resume, **kwargs)
File ~/mambaforge/lib/python3.9/site-packages/fastcore/parallel.py:123, in parallel(f, items, n_workers, total, progress, pause, threadpool, timeout, chunksize, *args, **kwargs)
121 if total is None: total = len(items)
122 r = progress_bar(r, total=total, leave=False)
--> 123 return L(r)
File ~/mambaforge/lib/python3.9/site-packages/fastcore/foundation.py:97, in _L_Meta.__call__(cls, x, *args, **kwargs)
95 def __call__(cls, x=None, *args, **kwargs):
96 if not args and not kwargs and x is not None and isinstance(x,cls): return x
---> 97 return super().__call__(x, *args, **kwargs)
File ~/mambaforge/lib/python3.9/site-packages/fastcore/foundation.py:105, in L.__init__(self, items, use_list, match, *rest)
103 def __init__(self, items=None, *rest, use_list=False, match=None):
104 if (use_list is not None) or not is_array(items):
--> 105 items = listify(items, *rest, use_list=use_list, match=match)
106 super().__init__(items)
File ~/mambaforge/lib/python3.9/site-packages/fastcore/basics.py:59, in listify(o, use_list, match, *rest)
57 elif isinstance(o, list): res = o
58 elif isinstance(o, str) or is_array(o): res = [o]
---> 59 elif is_iter(o): res = list(o)
60 else: res = [o]
61 if match is not None:
File ~/mambaforge/lib/python3.9/concurrent/futures/process.py:562, in _chain_from_iterable_of_lists(iterable)
556 def _chain_from_iterable_of_lists(iterable):
557 """
558 Specialized implementation of itertools.chain.from_iterable.
559 Each item in *iterable* should be a list. This function is
560 careful not to keep references to yielded objects.
561 """
--> 562 for element in iterable:
563 element.reverse()
564 while element:
File ~/mambaforge/lib/python3.9/concurrent/futures/_base.py:609, in Executor.map.<locals>.result_iterator()
606 while fs:
607 # Careful not to keep a reference to the popped future
608 if timeout is None:
--> 609 yield fs.pop().result()
610 else:
611 yield fs.pop().result(end_time - time.monotonic())
File ~/mambaforge/lib/python3.9/concurrent/futures/_base.py:439, in Future.result(self, timeout)
437 raise CancelledError()
438 elif self._state == FINISHED:
--> 439 return self.__get_result()
441 self._condition.wait(timeout)
443 if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]:
File ~/mambaforge/lib/python3.9/concurrent/futures/_base.py:391, in Future.__get_result(self)
389 if self._exception:
390 try:
--> 391 raise self._exception
392 finally:
393 # Break a reference cycle with the exception in self._exception
394 self = None
SameFileError: Path('happy_sad_angry/happy person/bea49f63-fa26-431c-9853-1d487d692591.jpg') and Path('happy_sad_angry/happy person/bea49f63-fa26-431c-9853-1d487d692591.jpg') are the same file
I checked in my folder, and don’t see any duplicate files downloaded. Can someone pls help here. Thanks!