python图像分类出现错误PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000001

阙俊友
2023-12-01
import os
from PIL import Image
folder_path = 'F:\\PetImages\\test_image'
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])

对所有图片进行遍历,找出错误图片

 类似资料: