peal.data.dataset_generators.ConfounderDatasetGenerator¶
- class peal.data.dataset_generators.ConfounderDatasetGenerator[source]¶
Bases:
objectStamp a synthetic confounder onto an existing image dataset (e.g. CelebA).
Reads the source label file, alternates
Confounderbetween samples (even index = confounded) and writes modified images plus the original attributes,ConfounderandConfounderStrengthtodata_config.dataset_path. Supportedconfoundingmodes:"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_inversetwin dataset and a difference mask).- Parameters:
dataset_origin_path (
str) – Source dataset root containingimgs/and the label file.dataset_name (
str, optional) – Unused; the output path comes fromdata_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 (
strorNone) – Mode as above;Nonetakesdata_config.confounding_factors[-1].num_samples (
int, optional) – Number of source samples to process (all whenNone).attribute (
str, optional) – Stored but unused.data_config (
DataConfig) – Suppliesdataset_pathand, optionally,inverse(a previously generated dataset whoseConfounderStrengthis negated and reused).
Methods
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
inversedataset’sConfounderStrengthcolumn ifdata_config.inverseis 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.csvis rewritten every 100 samples so a partial run is usable. Existing output folders are moved aside with a timestamp suffix.