Repository: pytorch/vision

Issue:
Imagefolder none descriptive error message
## 🐛 Bug

You get an weird python error:
`TypeError: can only join an iterable`

If you make an Imagefolder dataset with no samples in the directory and a is_valid_file. Because the extensions variable is set to none because is_valid_file which causes the TypeError.

## To Reproduce

Steps to reproduce the behavior:

1. Use Imagefolder in torchvision.datasets with no samples in the directory and a is_valid_file function.


<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
```
 is_type = lambda x: x.startswith(name)
    print(dir_in)
    data_set = datasets.ImageFolder(root=dir_in,
                                    transform=transforms.Compose([transforms.CenterCrop(IMG_SIZE),
                                               # transforms.Resize(IMAGE_SIZE),
                                               transforms.ToTensor(),
                                               transforms.Normalize(0.5, 0.5)]),
                                    is_valid_file=is_type)
```

## Expected behavior

Should display an RunTimeError saying that no samples were found.

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).
PyTorch version: 1.5.0
Is debug build: No
CUDA used to build PyTorch: 10.2

OS: Manjaro Linux
GCC version: (Arch Linux 9.3.0-1) 9.3.0
CMake version: version 3.17.1

Python version: 3.8
Is CUDA available: Yes
CUDA runtime version: 10.0.130
GPU models and configuration: GPU 0: Quadro M1200
Nvidia driver version: 440.82
cuDNN version: /usr/lib/libcudnn.so.7.6.5

Versions of relevant libraries:
[pip3] numpy==1.18.3
[pip3] torch==1.5.0
[pip3] torch-utils==0.1.2
[pip3] torchvision==0.5.0
[conda] Could not collect


Discussion:

Resolving patch:
diff --git a/torchvision/datasets/folder.py b/torchvision/datasets/folder.py
--- a/torchvision/datasets/folder.py
+++ b/torchvision/datasets/folder.py
@@ -94,8 +94,10 @@ def __init__(self, root, loader, extensions=None, transform=None,
         classes, class_to_idx = self._find_classes(self.root)
         samples = make_dataset(self.root, class_to_idx, extensions, is_valid_file)
         if len(samples) == 0:
-            raise (RuntimeError("Found 0 files in subfolders of: " + self.root + "\n"
-                                "Supported extensions are: " + ",".join(extensions)))
+            msg = "Found 0 files in subfolders of: {}\n".format(self.root)
+            if extensions is not None:
+                msg += "Supported extensions are: {}".format(",".join(extensions))
+            raise RuntimeError(msg)
 
         self.loader = loader
         self.extensions = extensions


Test patch:
diff --git a/test/test_datasets.py b/test/test_datasets.py
--- a/test/test_datasets.py
+++ b/test/test_datasets.py
@@ -84,6 +84,16 @@ def test_imagefolder(self):
             outputs = sorted([dataset[i] for i in range(len(dataset))])
             self.assertEqual(imgs, outputs)
 
+    def test_imagefolder_empty(self):
+        with get_tmp_dir() as root:
+            with self.assertRaises(RuntimeError):
+                torchvision.datasets.ImageFolder(root, loader=lambda x: x)
+
+            with self.assertRaises(RuntimeError):
+                torchvision.datasets.ImageFolder(
+                    root, loader=lambda x: x, is_valid_file=lambda x: False
+                )
+
     @mock.patch('torchvision.datasets.mnist.download_and_extract_archive')
     def test_mnist(self, mock_download_extract):
         num_examples = 30