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.
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.
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.
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.
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.