Repository: pytorch/vision

Issue:
DatasetFolder incorrectly specifies required folder structure
## 📚 Documentation

<!-- A clear and concise description of what content in https://pytorch.org/docs is an issue. If this has to do with the general https://pytorch.org website, please file an issue at https://github.com/pytorch/pytorch.github.io/issues/new/choose instead. If this has to do with https://pytorch.org/tutorials, please file an issue at https://github.com/pytorch/tutorials/issues/new -->

The documentation for [DatasetFolder](https://pytorch.org/docs/stable/torchvision/datasets.html#datasetfolder) specifies the following required folder organization:

```
root/class_x/xxx.ext
root/class_x/xxy.ext
root/class_x/xxz.ext

root/class_y/123.ext
root/class_y/nsdf3.ext
root/class_y/asd932_.ext
```

However, the [source code for DatasetFolder](https://pytorch.org/docs/stable/_modules/torchvision/datasets/folder.html#DatasetFolder) shows that `make_dataset()` uses `os.walk()` to discover the files in each class' folder. This means that any file within the class folder **or its subfolders** that passes `is_valid_file()` will be included. To me, this behavior was unexpected.

A more complete specification of the format could be:

```
root/class_x/xxx.ext
root/class_x/xxy.ext
root/class_x/[...]/xxz.ext

root/class_y/123.ext
root/class_y/nsdf3.ext
root/class_y/[...]/asd932_.ext
```

cc @pmeier
DatasetFolder incorrectly specifies required folder structure
## 📚 Documentation

<!-- A clear and concise description of what content in https://pytorch.org/docs is an issue. If this has to do with the general https://pytorch.org website, please file an issue at https://github.com/pytorch/pytorch.github.io/issues/new/choose instead. If this has to do with https://pytorch.org/tutorials, please file an issue at https://github.com/pytorch/tutorials/issues/new -->

The documentation for [DatasetFolder](https://pytorch.org/docs/stable/torchvision/datasets.html#datasetfolder) specifies the following required folder organization:

```
root/class_x/xxx.ext
root/class_x/xxy.ext
root/class_x/xxz.ext

root/class_y/123.ext
root/class_y/nsdf3.ext
root/class_y/asd932_.ext
```

However, the [source code for DatasetFolder](https://pytorch.org/docs/stable/_modules/torchvision/datasets/folder.html#DatasetFolder) shows that `make_dataset()` uses `os.walk()` to discover the files in each class' folder. This means that any file within the class folder **or its subfolders** that passes `is_valid_file()` will be included. To me, this behavior was unexpected.

A more complete specification of the format could be:

```
root/class_x/xxx.ext
root/class_x/xxy.ext
root/class_x/[...]/xxz.ext

root/class_y/123.ext
root/class_y/nsdf3.ext
root/class_y/[...]/asd932_.ext
```

cc @pmeier


Discussion:
Hi @rjbruin. Indeed you are correct. I think the easiest way is to adjust the documentation as you proposed. Do you want to submit a PR? If so ping me within that, so I can review.
Hi @rjbruin. Indeed you are correct. I think the easiest way is to adjust the documentation as you proposed. Do you want to submit a PR? If so ping me within that, so I can review.

Resolving patch:
diff --git a/torchvision/datasets/folder.py b/torchvision/datasets/folder.py
--- a/torchvision/datasets/folder.py
+++ b/torchvision/datasets/folder.py
@@ -85,11 +85,11 @@ class DatasetFolder(VisionDataset):
 
         root/class_x/xxx.ext
         root/class_x/xxy.ext
-        root/class_x/xxz.ext
+        root/class_x/[...]/xxz.ext
 
         root/class_y/123.ext
         root/class_y/nsdf3.ext
-        root/class_y/asd932_.ext
+        root/class_y/[...]/asd932_.ext
 
     Args:
         root (string): Root directory path.
@@ -211,11 +211,11 @@ class ImageFolder(DatasetFolder):
 
         root/dog/xxx.png
         root/dog/xxy.png
-        root/dog/xxz.png
+        root/dog/[...]/xxz.png
 
         root/cat/123.png
         root/cat/nsdf3.png
-        root/cat/asd932_.png
+        root/cat/[...]/asd932_.png
 
     Args:
         root (string): Root directory path.


Test patch: