peal.data.dataset_generators.OnlySparseNumbersDatasetGenerator

class peal.data.dataset_generators.OnlySparseNumbersDatasetGenerator[source]

Bases: object

Generates a dataset of 128x128 synthetic images with a 2×4 grid of numbers.

Dataset Properties: - Images: 128×128 RGB, white background, black text - Grid: 2 columns × 4 rows = 8 slots per image - Numbers: Configurable range (e.g., 000–999) - Uniqueness: Each number appears at most once per image

Typical Configuration: - num_samples: 12,500 images (default) - output_split: 1,000 unique numbers (000–999, default) - occupancy: ~50% (approximately 4 numbers per image on average)

CSV Output Format: - imgs: image filename - Num1–Num8: per-slot labels (-1 if empty)

Algorithm Overview: 1. Generate a pool of numbers with repetition to achieve target occupancy 2. Assign numbers to sample × slot pairs, ensuring uniqueness within each image 3. Render each image with centered, sized-to-fit text in each slot 4. Write CSV with per-sample labels

Methods

generate_dataset

Generate the dataset: images, masks, and CSV labels.

__init__(data_config, **kwargs)[source]
Parameters:
  • data_config – Config object with attributes

  • **kwargs – optional ‘font_path’ (default: DejaVu Sans)

generate_dataset()[source]

Generate the dataset: images, masks, and CSV labels.

Workflow: 1. Prepare output directory (backup existing data with timestamp) 2. Build number pool with target occupancy 3. Assign numbers to slots, ensuring uniqueness per image 4. Pre-compute optimal font size for all cells 5. For each sample:

  • Create blank 128×128 image

  • For each slot: draw number if present, else leave empty

  • Save PNG and update CSV

  1. Write final CSV