dset.ImageFolder Error: Found 0 files in subfolders of: /pathLocation Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif

username: rchavezj
cooked: <p>I downloaded the jpg images for DCGAN pytorch tutorial (<a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">DCGAN Tutorial — PyTorch Tutorials 2.2.0+cu121 documentation</a>) and the ipynb cannot find the files.</p>
<p><img src="https://discuss.pytorch.org/uploads/default/original/2X/6/6f6e4c198523597b8697e2f92009b0e5a05b4f2e.png" alt="pathLocation" data-base62-sha1="fTLjdIcBOXsFmVcZFljt4CJLwU6" width="592" height="378"></p>
<p>I made sure the path location is in the right location</p>
<pre data-code-wrap="python"><code class="lang-python"># Root directory for dataset
dataroot = "/home/paperspace/Label_YT_Videos/code/img_align_celeba/"
dataset = dset.ImageFolder(root=dataroot,
                           transform=transforms.Compose([
                               transforms.Resize(image_size),
                               transforms.CenterCrop(image_size),
                               transforms.ToTensor(),
                               transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
                           ]))
</code></pre>
<p>yet I get the following error</p>
<pre><code class="lang-auto">---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-6-e26dc739e9e3&gt; in &lt;module&gt;()
      7                                transforms.CenterCrop(image_size),
      8                                transforms.ToTensor(),
----&gt; 9                                transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
     10                            ]))
     11 

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torchvision/datasets/folder.py in __init__(self, root, transform, target_transform, loader)
    176         super(ImageFolder, self).__init__(root, loader, IMG_EXTENSIONS,
    177                                           transform=transform,
--&gt; 178                                           target_transform=target_transform)
    179         self.imgs = self.samples

~/anaconda3/envs/fastai/lib/python3.6/site-packages/torchvision/datasets/folder.py in __init__(self, root, loader, extensions, transform, target_transform)
     77         if len(samples) == 0:
     78             raise(RuntimeError("Found 0 files in subfolders of: " + root + "\n"
---&gt; 79                                "Supported extensions are: " + ",".join(extensions)))
     80 
     81         self.root = root

RuntimeError: Found 0 files in subfolders of: /home/paperspace/Label_YT_Videos/code/img_align_celeba/
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif

</code></pre>

username: tumble-weed
cooked: <p>From the <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html" rel="noopener nofollow ugc">tutorial</a>:</p>
<blockquote>
<p>This is an important step because we will be using the ImageFolder dataset class, which requires there to be subdirectories in the dataset’s root folder. Now, we can create the dataset, create the dataloader, set the device to run on, and finally visualize some of the training data.</p>
</blockquote>
<p>try setting the <code>dataroot</code> as  <code>"/home/paperspace/Label_YT_Videos/code/"</code></p>

username: rchavezj
cooked: <p>But how will the program find the path for img_align_celeba?</p>

username: tumble-weed
cooked: <p><code>ImageFolder</code> ought to try and read from all the subfolders from <code>root</code></p>

username: rchavezj
cooked: <p>What if the directory I’m on has other data irrelevant to the tutorial? Honestly I’ll probaby have a folder within the data folder since the concept is a bit convoluted in my opinion. Your explanation worked tho. Thanks!</p>

username: PatrickNa
cooked: <p>I have created an extra folder, too. But I also would be interested in why it is solved that way? <a class="mention" href="/u/rchavezj">@rchavezj</a>’s question is also what I am wondering about…</p>
<aside class="quote no-group" data-username="rchavezj" data-post="7" data-topic="28221">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/rchavezj/48/16902_2.png" class="avatar"> rchavezj:</div>
<blockquote>
<p>What if the directory I’m on has other data irrelevant to the tutorial?</p>
</blockquote>
</aside>