出現:
PIL.UnidentifiedImageError: cannot identify image filegoogle 一下,有人說用
import os
from PIL import Image
folder_path = 'data\img'
extensions = []
for fldr in os.listdir(folder_path):
sub_folder_path = os.path.join(folder_path, fldr)
for filee in os.listdir(sub_folder_path):
file_path = os.path.join(sub_folder_path, filee)
print('** Path: {} **'.format(file_path), end="\r", flush=True)
im = Image.open(file_path)
rgb_im = im.convert('RGB')
if filee.split('.')[1] not in extensions:
extensions.append(filee.split('.')[1])
檢查 image 是不是合格。果然,出現:
Traceback (most recent call last):in/cats/666.jpg ** File "checkimage.py", line 10, in用 mediainfo 看 666.jpg,沒有內容。一看 file size 是 0im = Image.open(file_path) File "/home/charles-chang/miniconda3/envs/tensorflow-gpu/lib/python3.8/site-packages/PIL/Image.py", line 2967, in open raise UnidentifiedImageError( PIL.UnidentifiedImageError: cannot identify image file './cats_and_dogs_small/train/cats/666.jpg'
再加上 666 來 google ,出現這一篇。
甚至把影像都看一下,確認真的是 Cats, Dogs,發現有些不正確的影像...
沒有留言:
張貼留言