"""Generate per-label composite verification images from the dataset. Creates composites//label_.png for each digit and split. These are checked into the repo for visual verification. Usage: uv run python scripts/make_composites.py """ import os import io import pandas as pd from PIL import Image if __name__ != "__main__": import sys; sys.exit(0) CELL = 36 MAX_COLS = 50 def make_composite(images, cell=CELL, max_cols=MAX_COLS): if not images: return None cols = min(max_cols, len(images)) rows = (len(images) + cols - 1) // cols sheet = Image.new("L", (cols * cell, rows * cell), 0) for idx, img in enumerate(images): r, c = idx // cols, idx % cols sheet.paste(img.resize((cell, cell)), (c * cell, r * cell)) return sheet for split in ["train", "validation"]: df = pd.read_parquet(f"data/{split}-00000-of-00001.parquet") out_dir = f"composites/{split}" os.makedirs(out_dir, exist_ok=True) for label in sorted(df["label"].unique()): subset = df[df["label"] == label] # Only racing sources (skip mnist, racing_aug) racing = subset[~subset["source"].isin(["mnist", "racing_aug"])] if len(racing) == 0: continue images = [ Image.open(io.BytesIO(row["image"]["bytes"])).convert("L") for _, row in racing.iterrows() ] sheet = make_composite(images) if sheet: path = f"{out_dir}/label_{label}.png" sheet.save(path) print(f"{split} label={label}: {len(images)} racing images -> {path}") print("\nDone")