text_plain_output_1.png
import cv2

import os

import shutil

import warnings # попытка поймать сообщения: libpng warning: iCCP: known incorrect sRGB profile

import numpy as np
import pandas as pd
import cv2
from PIL import Image
import warnings
warnings.filterwarnings('error')
import os
import shutil
for dirname, _, filenames in os.walk('/kaggle/input/fruit-and-vegetable-image-recognition'):
    print(dirname, 'Count:', len(filenames))
    for filename in filenames:
        try:
            img = cv2.imread(os.path.join(dirname, filename))
        except:
            print('libpng warning: iCCP: known incorrect sRGB profile:', os.path.join(dirname, filename))
        try:
            if len(img.shape) != 3:
                print(os.path.join(dirname, filename), 'img.shape', img.shape)
            else:
                patchNew = dirname.replace('input', 'working')
                if not os.path.exists(patchNew):
                    os.makedirs(patchNew)
                shutil.copy(os.path.join(dirname, filename), patchNew)
        except AttributeError:
            print('Ошибочный файл:', os.path.join(dirname, filename))
            del img