Was working on YOLO and stuck here can someone help please


FileNotFoundError Traceback (most recent call last)
File ~\AppData\Local\Programs\Python\Python39\lib\shutil.py:806, in move(src, dst, copy_function)
805 try:
→ 806 os.rename(src, real_dst)
807 except OSError:

FileNotFoundError: [WinError 3] The system cannot find the path specified: ‘dataset pascal voc\2007_000027.jpg’ → ‘train\2007_000027.jpg’

During handling of the above exception, another exception occurred:

FileNotFoundError Traceback (most recent call last)
Cell In[73], line 1
----> 1 filename_series.head(2).apply(save_data,args=(train_folder,groupby_obj_train))

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\series.py:4917, in Series.apply(self, func, convert_dtype, args, by_row, **kwargs)
4789 def apply(
4790 self,
4791 func: AggFuncType,
(…)
4796 **kwargs,
4797 ) → DataFrame | Series:
4798 “”"
4799 Invoke function on values of Series.
4800
(…)
4915 dtype: float64
4916 “”"
→ 4917 return SeriesApply(
4918 self,
4919 func,
4920 convert_dtype=convert_dtype,
4921 by_row=by_row,
4922 args=args,
4923 kwargs=kwargs,
4924 ).apply()

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\apply.py:1427, in SeriesApply.apply(self)
1424 return self.apply_compat()
1426 # self.func is Callable
→ 1427 return self.apply_standard()

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\apply.py:1507, in SeriesApply.apply_standard(self)
1501 # row-wise access
1502 # apply doesn’t have a na_action keyword and for backward compat reasons
1503 # we need to give na_action="ignore" for categorical data.
1504 # TODO: remove the na_action="ignore" when that default has been changed in
1505 # Categorical (GH51645).
1506 action = “ignore” if isinstance(obj.dtype, CategoricalDtype) else None
→ 1507 mapped = obj._map_values(
1508 mapper=curried, na_action=action, convert=self.convert_dtype
1509 )
1511 if len(mapped) and isinstance(mapped[0], ABCSeries):
1512 # GH#43986 Need to do list(mapped) in order to get treated as nested
1513 # See also GH#25959 regarding EA support
1514 return obj._constructor_expanddim(list(mapped), index=obj.index)

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\base.py:921, in IndexOpsMixin._map_values(self, mapper, na_action, convert)
918 if isinstance(arr, ExtensionArray):
919 return arr.map(mapper, na_action=na_action)
→ 921 return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\algorithms.py:1743, in map_array(arr, mapper, na_action, convert)
1741 values = arr.astype(object, copy=False)
1742 if na_action is None:
→ 1743 return lib.map_infer(values, mapper, convert=convert)
1744 else:
1745 return lib.map_infer_mask(
1746 values, mapper, mask=isna(values).view(np.uint8), convert=convert
1747 )

File lib.pyx:2972, in pandas._libs.lib.map_infer()

File c:\users\lenovo\desktop\internship\yolo\yolo_venv\lib\site-packages\pandas\core\apply.py:1496, in SeriesApply.apply_standard..curried(x)
1495 def curried(x):
→ 1496 return func(x, *self.args, **self.kwargs)

Cell In[71], line 7, in save_data(filename, folder_path, group_obj)
5 src=os.path.join(‘dataset pascal voc’,filename)
6 dst=os.path.join(‘train’,filename)
----> 7 move(src,dst)#move images to the destination folder
8 #save the labels,txt filename should be same
10 text_filename =os.path.join(folder_path,
11 os.path.splitext(filename)[0]+‘.txt’)

File ~\AppData\Local\Programs\Python\Python39\lib\shutil.py:826, in move(src, dst, copy_function)
824 rmtree(src)
825 else:
→ 826 copy_function(src, real_dst)
827 os.unlink(src)
828 return real_dst

File ~\AppData\Local\Programs\Python\Python39\lib\shutil.py:435, in copy2(src, dst, follow_symlinks)
433 if os.path.isdir(dst):
434 dst = os.path.join(dst, os.path.basename(src))
→ 435 copyfile(src, dst, follow_symlinks=follow_symlinks)
436 copystat(src, dst, follow_symlinks=follow_symlinks)
437 return dst

File ~\AppData\Local\Programs\Python\Python39\lib\shutil.py:264, in copyfile(src, dst, follow_symlinks)
262 os.symlink(os.readlink(src), dst)
263 else:
→ 264 with open(src, ‘rb’) as fsrc, open(dst, ‘wb’) as fdst:
265 # macOS
266 if _HAS_FCOPYFILE:
267 try:

FileNotFoundError: [Errno 2] No such file or directory: ‘train\2007_000027.jpg’

filename_series.head(2).apply(save_data,args=(train_folder,groupby_obj_train))

jupyter notebook
python 3.9

For the above issue there could be 2 reasons :

  1. There is no directory or file by the name which is being called in your code.
  2. There may be permission related issues in accessing the file.
    Try fixing this issue first , the others may automatically go away.

the file is availaible i checked

Can you try renaming your directory to something without a space between the 3 names , I would suggest you use underscore ( _ ) or something , instead of just blank space.

I changed to dataset_pascal_voc but still same error with just the name changed .

That is because of the two ‘\’ in your file path variable , change it to just have one slash , then it should be able to find that image.

how to change?

There’s another possible reason. Those are relative paths. They refer to files relative to the current directory, but where is the current directory? It’s much better to use absolute paths.

You can use __file__ in the program to get its path and dirname(__file__) to get the directory that the program is in, and then work from there to construct the path to the files.

Yeah I agree with this , I forgot to include this in my answer.
@y4sh try using the absolute path from the root folder to whatever folder you want to access.

I am new to this can you please tell me what to write in the programm to solve this issue

Find where in the program you’re specifying the paths to the data and change them to absolute paths. An absolute path is one that starts with a drive letter.


Now what should I do?

    src=os.path.join('C:\\Users\\Lenovo\\Desktop\\Internship\\YOLO\\dataset_pascal_voc', filename)
    src=(map(lambda x: x.replace('\\','/'),src))
    dst=os.path.join('C:\\Users\\Lenovo\\Desktop\\Internship\\YOLO\\dataset_pascal_voc\\train', filename)
    dst=(map(lambda x: x.replace('\\','/'),dst))

after using this it is showing type error
TypeError: stat: path should be string, bytes, os.PathLike or integer, not map

Why are you using map? Presumably the error is because you’re giving some function a map value when it’s expecting a path.

If you want to convert \\ to / in a path, just use the replace method.

(Not that it’s necessary anyway. On Windows the directory separator is \, but it’ll accept / too, except in dialog boxes.)