Getting Error: NotADirectoryError: [WinError 267] The directory name is invalid. File and folder both are valid

manoj_kumar: <p>am getting the following error<br>
Getting Error: NotADirectoryError: [WinError 267] The directory name is invalid. File and folder both are valid<br>
I am using the following code:</p>
<p>data_dir = os.getcwd()<br>
folder_name = “train”<br>
image_folders = os.path.join(data_dir, folder_name)<br>
transform = transforms.Compose([transforms.Resize((512,512)), transforms.ToTensor()])<br>
images = []<br>
for file in os.listdir(image_folders):<br>
<span class="hashtag">#print</span>(“1–&gt;”+file)<br>
images.append(ImageFolder(os.path.join(image_folders, file), transform=transform))<br>
datasets = torch.utils.data.ConcatDataset(images)</p>
<p>Please help here.</p>

Usama_Hasan: <p>Hy <a class="mention" href="/u/manoj_kumar">@manoj_kumar</a>, In some cases os.getcwd() behave very strange. Please run a quick check and print the output of os.getcwd(). Check if its printing the right directory.</p>

manoj_kumar: <p>Hi <a class="mention" href="/u/usama_hasan">@Usama_Hasan</a>,  I checked that also and found it is giving the correct path to the file name.  I am not sure where I making mistake.</p>
<p>Refer the screenshot<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/d/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2.png" data-download-href="https://discuss.pytorch.org/uploads/default/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2" title="Error"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/d/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2_2_689x287.png" alt="Error" data-base62-sha1="tivYsMESSdPB5OMgAN0IIiGacv0" width="689" height="287" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/d/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2_2_689x287.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/d/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2_2_1033x430.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/d/cd56dbd0247ea27ce85b61b9e3fda7b89d0f94c2.png 2x" data-dominant-color="F4F4F4"><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">Error</span><span class="informations">1346×560 30.9 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>

Usama_Hasan: <p>So Basically the ImageFolder is raising this error, because you’re providing it with a file path and It requires a Directory/Folder to work on. The path printed in the terminal block is pointing towards a .jpg file</p>

manoj_kumar: <p>Hi <a class="mention" href="/u/usama_hasan">@Usama_Hasan</a><br>
I have tried with only folder name which has all images but still, I am getting the error.</p>
<p>RuntimeError: Found 0 files in subfolders of: D:\MS_Program\DR\Code\train<br>
Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp<br>
while train folder has all the images which I want read by the program.</p>
<p>Sample: code:</p>
<p>transform = transforms.Compose([transforms.Resize((512,512)), transforms.ToTensor()])<br>
images = []</p>
<p>images.append(ImageFolder(image_folders), transform=transform)</p>
<p>datasets = torch.utils.data.ConcatDataset(images)</p>

Usama_Hasan: <p><a class="mention" href="/u/manoj_kumar">@manoj_kumar</a> , Image folder looks for image/examples in a predefined way/hierarchy. Please look at the documentation. It takes a root folder, which contains sub folders, with class name and looks for images inside these subfolders<br>
<a href="https://pytorch.org/docs/stable/torchvision/datasets.html#imagefolder" rel="noopener nofollow ugc">https://pytorch.org/docs/stable/torchvision/datasets.html#imagefolder</a>.<br>
The pattren is like this.</p>
<p><strong>root/class_name/example.png</strong></p>