-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_data.py
More file actions
45 lines (35 loc) · 1.56 KB
/
verify_data.py
File metadata and controls
45 lines (35 loc) · 1.56 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from PIL import Image
import os
from config import DATA_PATH
def verify_dataset_images():
print(f"Verifying images in dataset directory: {DATA_PATH}")
if not os.path.exists(DATA_PATH):
print(f"Error: Dataset path '{DATA_PATH}' does not exist.")
return
corrupted_count = 0
total_count = 0
for person_name in os.listdir(DATA_PATH):
person_dir = os.path.join(DATA_PATH, person_name)
if not os.path.isdir(person_dir):
continue
print(f"Checking images for subject: {person_name}")
for img_name in os.listdir(person_dir):
if img_name.lower().endswith((".jpg", ".png", ".jpeg")):
total_count += 1
img_path = os.path.join(person_dir, img_name)
try:
# Check if the image is valid
with Image.open(img_path) as img:
img.verify()
# Also try converting PNGs to standard saving format if needed
if img_name.endswith(".png"):
with Image.open(img_path) as img_save:
img_save.save(img_path, "PNG")
except Exception as e:
print(f"-> {img_name}: Corrupted or wrong format ({e})")
corrupted_count += 1
print("-" * 30)
print(f"Verification Complete. Total images: {total_count}")
print(f"Corrupted images found: {corrupted_count}")
if __name__ == "__main__":
verify_dataset_images()