peal.data.dataset_generators.ConfounderDatasetGenerator

class peal.data.dataset_generators.ConfounderDatasetGenerator[source]

Bases: object

Stamp a synthetic confounder onto an existing image dataset (e.g. CelebA).

Reads the source label file, alternates Confounder between samples (even index = confounded) and writes modified images plus the original attributes, Confounder and ConfounderStrength to data_config.dataset_path. Supported confounding modes: "intensity" (brightness shift), "color" (red/blue shift), "copyrighttag" (a copyright tag blended into the bottom of the image, with a hint mask) and "necklace" (young/old edits through DDPM inversion, with an _inverse twin dataset and a difference mask).

Parameters:
  • dataset_origin_path (str) – Source dataset root containing imgs/ and the label file.

  • dataset_name (str, optional) – Unused; the output path comes from data_config.dataset_path.

  • label_dir (str, optional) – Label file; defaults to <dataset_origin_path>/data.csv. The first two lines are treated as header and skipped.

  • delimiter (str) – Column delimiter of the label file.

  • confounding (str or None) – Mode as above; None takes data_config.confounding_factors[-1].

  • num_samples (int, optional) – Number of source samples to process (all when None).

  • attribute (str, optional) – Stored but unused.

  • data_config (DataConfig) – Supplies dataset_path and, optionally, inverse (a previously generated dataset whose ConfounderStrength is negated and reused).

Methods

generate_dataset

Write the confounded dataset to dataset_dir (and _inverse).

__init__(dataset_origin_path, dataset_name=None, label_dir=None, delimiter=',', confounding='copyrighttag', num_samples=None, attribute=None, data_config=None, **kwargs)[source]

Resolve paths and the confounding mode; read the inverse dataset’s ConfounderStrength column if data_config.inverse is set.

generate_dataset()[source]

Write the confounded dataset to dataset_dir (and _inverse).

The first 90 % of samples get a random confounder strength in [0, 1], the rest strength 1. data.csv is rewritten every 100 samples so a partial run is usable. Existing output folders are moved aside with a timestamp suffix.