Datasets:
File size: 1,628 Bytes
148953b | 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 46 47 48 49 50 51 52 53 54 55 56 57 | """Generate per-label composite verification images from the dataset.
Creates composites/<split>/label_<N>.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")
|