-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dataset.py
More file actions
27 lines (22 loc) · 1015 Bytes
/
Copy pathtest_dataset.py
File metadata and controls
27 lines (22 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
from PIL import Image
def clean_aircraft_data(root_dir):
bad_files = 0
for subdir, dirs, files in os.walk(root_dir):
for file in files:
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
file_path = os.path.join(subdir, file)
try:
with Image.open(file_path) as img:
# .verify() catches basic corruption
img.verify()
# .load() catches "broken data stream" specifically
with Image.open(file_path) as img:
img.load()
except (IOError, OSError, SyntaxError) as e:
print(f"Deleting corrupted image: {file_path}")
os.remove(file_path)
bad_files += 1
print(f"Cleanup complete. Removed {bad_files} broken images.")
# Run it on your M2 Pro
clean_aircraft_data('dataset')