File size: 550 Bytes
c3d8a68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from PIL import Image
import os

folder_path = "categorized_images"  # Update with your dataset folder

for root, _, files in os.walk(folder_path):
    for file in files:
        file_path = os.path.join(root, file)
        try:
            with Image.open(file_path) as img:
                img.verify()  # Verify if it's a valid image
        except Exception as e:
            print(f"Corrupt image found: {file_path}, Error: {e}")
            os.remove(file_path)  # Remove corrupt image
            print(f"Deleted: {file_path}")