PIL.UnidentifiedImageError: cannot identify image file

I’m getting an unidentified image error in running a dataloader on a PNG file (which should be covered by PIL image readers I thought. Further the reader seems to append a leading "._’ to the file name (error and actual file name below). Any suggestions appreciated.

The error:
PIL.UnidentifiedImageError: cannot identify image file <_io.BufferedReader name=’…/DiaperImagesMoire/parameter_screen_20200324/gray_img/._J153_brickGrid_5.15_9.5_4.76_8.5_ellipse_2.24_2.0_1.2_0.6_300ppi_gray.png’>

Actual file name (no leading characters before J153):
J153_brickGrid_5.15_9.5_4.76_8.5_ellipse_2.24_2.0_1.2_0.6_300ppi_gray.png**

The code:
dataset = datasets.ImageFolder(root=’…/DiaperImagesMoire/parameter_screen_20200324/’, transform=transforms.Compose([
transforms.Grayscale(),
transforms.Resize(64),
transforms.ToTensor(),
transforms.Normalize(mean=[0.5], std=[0.5])
]))

train_loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=True, num_workers=2)
train_iter = iter(train_loader)
images, labels = train_iter.next()

Hi,

There seems to be a problem with the ImageFolder root path, there are three dots (…/DiaperImagesMoire/parameter_screen_20200324/) in the path instead of two. I would also suggest using an absolute path for the ImageFolder root.

Actually I got the same issue. Check if there is a hidden file “._J153_brickGrid_5.15_9.5_4.76_8.5_ellipse_2.24_2.0_1.2_0.6_300ppi_gray.png” under your directory.