pytorch / examples

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.
https://pytorch.org/examples
BSD 3-Clause "New" or "Revised" License
22.23k stars 9.52k forks source link

FileNotFoundError: Couldn't find any class folder in /content/train2014. #1039

Open sevaroy opened 2 years ago

sevaroy commented 2 years ago

Your issue may already be reported! Please search on the issue tracker before creating one.

I wanna train new style model run this cmd

!unzip train2014.zip -d /content

!python /content/examples/fast_neural_style/neural_style/neural_style.py train --dataset /content/train2014 --style-image /content/A.jpg --save-model-dir /content --epochs 2 --cuda 1

Context

Your Environment

Colab https://colab.research.google.com/github/pytorch/xla/blob/master/contrib/colab/style_transfer_inference.ipynb#scrollTo=EozMXwIV9iOJ

got this error

Traceback (most recent call last): File "/content/examples/fast_neural_style/neural_style/neural_style.py", line 249, in main() File "/content/examples/fast_neural_style/neural_style/neural_style.py", line 243, in main train(args) File "/content/examples/fast_neural_style/neural_style/neural_style.py", line 43, in train train_dataset = datasets.ImageFolder(args.dataset, transform) File "/usr/local/lib/python3.7/dist-packages/torchvision/datasets/folder.py", line 316, in init is_valid_file=is_valid_file, File "/usr/local/lib/python3.7/dist-packages/torchvision/datasets/folder.py", line 145, in init classes, class_to_idx = self.find_classes(self.root) File "/usr/local/lib/python3.7/dist-packages/torchvision/datasets/folder.py", line 219, in find_classes return find_classes(directory) File "/usr/local/lib/python3.7/dist-packages/torchvision/datasets/folder.py", line 43, in find_classes raise FileNotFoundError(f"Couldn't find any class folder in {directory}.") FileNotFoundError: Couldn't find any class folder in /content/train2014.

How can I fix it? thx

hudeven commented 2 years ago

@sevaroy good catch! datasets.ImageFolder requires folder in this format: root/label_name/xxx.png. Here is a quick workaround: create a sub folder containing all images under train2014. e.g. train2014/no_label/xxx.png. The labels are not used in this examples anyway.

Please feel free to submit a PR to update the README accordingly. Otherwise, I will update it next week.

pramodhrachuri commented 1 year ago

Looks like this is not fixed yet. Right? I can try fixing it and make a PR if no one else is working on it

Edit: I realized I mishandled the dataset which led to this error. After deleting the extracted folders, it was fixed. So, I guess there is no need to fix anything.