'OSError: cannot identify image file' for custom dataset

I have made a custom dataset class based on the ImageFolder class. When I load a batch of the dataset using :

inputs, labels = next(iter(dataloaders[‘train’]))

The batch is loaded correctly. However, when I try to load the data in my training loop similarly to the Transfer Learning tutorials, i.e :

for data in dataloaders[phase]:

I get the following error :
‘OSError: cannot identify image file <_io.BufferedReader name=’/path/to/file/sample.png’>

This is not my first custom ImageFolder class, yet it is the first time that I am encountering this type of error. Any ideas as to what might be going wrong ?

PS : I am using 0.3.1

I think some of the pathes of the image are not right. Try to print every image path before load that image, and see what path encounter this error.

Good call, I had a look at the problematic paths. Turns out part of my dataset is corrupted, that’s why the files weren’t loading.

Thanks you for your help !

we also have a same problem during running the code after training the dataset.What to do now ?