| import os |
| from collections import Counter |
|
|
| def count_yolo_stats(label_dir, class_names): |
| counts = Counter() |
| files = [f for f in os.listdir(label_dir) if f.endswith('.txt')] |
| image_count = len(files) |
| |
| for file in files: |
| with open(os.path.join(label_dir, file), 'r') as f: |
| for line in f: |
| parts = line.split() |
| if parts: |
| class_id = int(parts[0]) |
| if class_id < len(class_names): |
| counts[class_id] += 1 |
| |
| instance_counts = {class_names[i]: counts[i] for i in range(len(class_names))} |
| return image_count, instance_counts |
|
|
| |
| CLASSES = ["bubble"] |
|
|
| for split in ['train', 'val']: |
| path = f'../../tinybubble/yolo_det/{split}/labels' |
| |
| if os.path.exists(path): |
| img_qty, inst_qty = count_yolo_stats(path, CLASSES) |
| |
| print(f"\n--- {split.upper()} SET ---") |
| print(f"Total Images: {img_qty}") |
| for cls, count in inst_qty.items(): |
| print(f"Total {cls}s: {count}") |
| avg = count / img_qty if img_qty > 0 else 0 |
| print(f"Avg per Image: {avg:.2f}") |
| else: |
| print(f"Path not found: {path}") |