def validate_dataset(data_dir): """Scan a dataset folder and flag common data quality issues.""" corrupted = [] too_small = [] nearly_black = [] total = 0 for class_name in os.listdir(data_dir): class_path = os.path.join(data_dir, class_name) if not os.path.isdir(class_path): continue for fname in os.listdir(class_path): fpath = os.path.join(class_path, fname) total += 1 try: img = cv2.imread(fpath, cv2.IMREAD_GRAYSCALE) if img is None: corrupted.append(fpath) continue if img.shape[0] < 100 or img.shape[1] < 100: too_small.append(fpath) if img.mean() < 5: nearly_black.append(fpath) except Exception: corrupted.append(fpath) print(f"Total files scanned: {total}") print(f"Corrupted: {len(corrupted)}") print(f"Too small: {len(too_small)}") print(f"Nearly black: {len(nearly_black)}") return corrupted, too_small, nearly_black validate_dataset(TRAIN_DIR)