The system cannot find the path specified

Hi, I tried creating a model that can classify food or identify food from their images. The code used to run completely fine but a day or two ago it randomly started giving this error.

Traceback (most recent call last):
  File "C:\Users\User\PycharmProjects\Food\main.py", line 25, in <module>
    dataloaders, dataset_sizes, class_names = preprocess_and_split_data(data_dir, batch_size)
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Food\preprocessing.py", line 21, in preprocess_and_split_data
    image_datasets = {x: datasets.ImageFolder(os.path.join(data_dir, x), data_transforms[x])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Food\.venv\Lib\site-packages\torchvision\datasets\folder.py", line 328, in __init__
    super().__init__(
  File "C:\Users\User\PycharmProjects\Food\.venv\Lib\site-packages\torchvision\datasets\folder.py", line 149, in __init__
    classes, class_to_idx = self.find_classes(self.root)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Food\.venv\Lib\site-packages\torchvision\datasets\folder.py", line 234, in find_classes
    return find_classes(directory)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\User\PycharmProjects\Food\.venv\Lib\site-packages\torchvision\datasets\folder.py", line 41, in find_classes
    classes = sorted(entry.name for entry in os.scandir(directory) if entry.is_dir())
                                             ^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:/Users/User/OneDrive/Desktop/Datasets/Food101/images\\train'

Process finished with exit code 1

I tried re-installing PyCharm and even created alternate projects to solve it, but none helped.

I have rechecked the directory multiple times, even copied and pasted it which was working fine a few days ago yet this problem didn’t solve.

Maybe it doesn’t matter, but in the final path why’s the final directory separator \\ before train, unlike all the others?

Also it’s on the OneDrive/Desktop. Not even Microsoft knows everything that could possibly go wrong with a user’s files on OneDrive.

2 Likes

Came to post similar. I’ve also heard in passing that network drives may not get along with PyCharm quite so well, e.g.. Might be useful to possibly move the training data to a local directory if the slash inconsistency is a non-issue

The path I have given is just “C:/Users/User/OneDrive/Desktop/Datasets/Food101/images”.
I have kept the dataset in the downloads folder that’s why it is in OneDrive. I thought that was the problem too so I moved it in various places, in the C: directory, in pycharm project folder as well as in this project’s files, yet it cannot find it. I don’t know what \train is. It could be that since I am trying to train the model for food identification it is showing that.

I tried the local directory as well as the directory where the project is present but it still showed the same error. It was working perfectly fine a few days ago with the exact same code. I don’t know what changed it.

Try switching the forward slashes to backslashes in a raw-string, so it looks like a standard Windows path. Then hopefully the code treats them all like dir separators, and doesn’t mistakenly think only the backslash before a t is a tab.

Otherwise, either the library expects to find a sub dir called train and it’s not there, or there’s a really weird thing going on with os.scandir returning ...//train which a subsequent call can’t find.

Are there configuration changes that must occur with moving the data?

When the notebook executed perfectly, was the data local at that point in time and eventually the network drive tool moved it off the local drive?

Tried making "/" to "\" but it’s still giving the same error. I don’t even know where is it getting the \train from as there is nothing of that name anywhere in that directory.

I don’t think that happened as the data is still in the same place where it was at the start.

I copied train from the error you posted. I would search the PyTorch and Torchvision source code for that string.

1 Like

So you’re suggesting that I search PyTorch and Torchvision for the train things popping up in the directory? I am still new to all this ML stuff so I don’t really know what I am looking for.

https://github.com/search?q=repo%3Apytorch%2Fpytorch+"\"train\""&type=code

I couldn’t find anything like the string. I am trying to completely re-install Python 3.12 to see if it works.


I had this added without realizing it. It was looking for the “train” folder for the training of the model and the “val” or “test” folder for cross-verification of the training. Removing this or moving images after creating those folders in the directory fixes it.

1 Like