FileNotFoundError: Couldn't find any class folder

ziad: <p>Hello,</p>
<p>I’m trying to follow the <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#dcgan-tutorial" rel="noopener nofollow ugc">DCGAN tutorial</a> on PyTroch on Google Colab however I keep coming across this <code>FileNotFoundError</code>. I’m loading in data like so:</p>
<pre><code class="lang-auto"># Loading in data

dataroot = "/content/drive/MyDrive/Colab_Notebooks/celeba"
!cd /content/drive/MyDrive/Colab_Notebooks/celeba 

!unzip -q /content/drive/MyDrive/Colab_Notebooks/celeba/img_align_celeba.zip -d 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>I’m unzipping the zip that I downloaded into my G-Drive. I understand that <code>ImageFolder</code> expects subdirectories in the data’s root folder as stated <a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#data" rel="noopener nofollow ugc">here</a> however I’m still unsure whether it can handle zip file formats or requires them to be unzipped first? Furthermore, what if my dataset images do not have a particular like in my example where they are just facial images.</p>

ptrblck: <aside class="quote no-group" data-username="ziad" data-post="1" data-topic="138578">
<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/ziad/48/44608_2.png" class="avatar"> ziad:</div>
<blockquote>
<p>however I’m still unsure whether it can handle zip file formats or requires them to be unzipped first?</p>
</blockquote>
</aside>
<p><code>ImageFolder</code> expects to find valid image files in each subfolder and won’t <code>unzip</code> nested folders first.</p>
<aside class="quote no-group" data-username="ziad" data-post="1" data-topic="138578">
<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/ziad/48/44608_2.png" class="avatar"> ziad:</div>
<blockquote>
<p>Furthermore, what if my dataset images do not have a particular like in my example where they are just facial images.</p>
</blockquote>
</aside>
<p>I assume you are asking about a use case which doesn’t provide image files in each subfolder?<br>
If so, you could write a custom <code>Dataset</code> as explained <a href="https://pytorch.org/tutorials/beginner/data_loading_tutorial.html">here</a>.</p>

ziad: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a> - thanks for replying.</p>
<blockquote>
<p><code>ImageFolder</code> expects to find valid image files in each subfolder and won’t <code>unzip</code> nested folders first.</p>
</blockquote>
<p>Does it expect subfolders to be labelled such as test, train etc or is the requirement that images only exist in a subfolder? If I unzip the file provided in this PyTroch demo (<a href="https://pytorch.org/tutorials/beginner/dcgan_faces_tutorial.html#data" class="inline-onebox" rel="noopener nofollow ugc">DCGAN Tutorial — PyTorch Tutorials 2.1.1+cu121 documentation</a>) it produces a folder with all images inside - i.e. not separate into subfolders. The confusion occurs when it states the <em>…ImageFolder dataset class, which requires there to be subdirectories in the dataset’s root folder.</em></p>

ptrblck: <aside class="quote no-group" data-username="ziad" data-post="3" data-topic="138578">
<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/ziad/48/44608_2.png" class="avatar"> ziad:</div>
<blockquote>
<p>Does it expect subfolders to be labelled such as test, train etc or is the requirement that images only exist in a subfolder?</p>
</blockquote>
</aside>
<p><code>ImageFolder</code> will assign a class index to each subfolder. Usually you would thus have subfolders in the <code>train</code> and <code>test</code> folders. If you pass the <code>root</code> folder of <code>train</code> and <code>test</code> to <code>ImageFolder</code> these two folders will have a target value of 0 and 1, respectively.</p>
<aside class="quote no-group" data-username="ziad" data-post="3" data-topic="138578">
<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/ziad/48/44608_2.png" class="avatar"> ziad:</div>
<blockquote>
<p>The confusion occurs when it states the <em>…ImageFolder dataset class, which requires there to be subdirectories in the dataset’s root folder.</em></p>
</blockquote>
</aside>
<p>As you can see in the tutorial, the target is never used and the input sample is used via <code>data[0]</code>.<br>
If you don’t want to use the targets, <code>ImageFolder</code> would still be a valid approach as it would still load all samples in the subfolder(s).</p>

1152768760: <p>The folder doesn’t have any folder except the folder ’ img_align_celeba’<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/b/db33b102d8f96498b733b5f0166e574ed28bfbb8.png" data-download-href="https://discuss.pytorch.org/uploads/default/db33b102d8f96498b733b5f0166e574ed28bfbb8" title="Snipaste_2023-06-06_15-02-37"><img src="https://discuss.pytorch.org/uploads/default/original/3X/d/b/db33b102d8f96498b733b5f0166e574ed28bfbb8.png" alt="Snipaste_2023-06-06_15-02-37" data-base62-sha1="vh9juJTyZjPVrW92i12McKcrNnW" width="690" height="191" data-dominant-color="FBFBFA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Snipaste_2023-06-06_15-02-37</span><span class="informations">809×225 6.48 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

pegasi: <pre><code class="lang-python">dataroot = "/content/drive/MyDrive/Colab_Notebooks"
</code></pre>