Datasets:
File size: 1,229 Bytes
9f22904 | 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 | 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
# --- SETTINGS ---
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}") |