peal.data.custom_datasets.FunnyNodulesDataset

class peal.data.custom_datasets.FunnyNodulesDataset[source]

Bases: Image2MixedDataset

Synthetic nodules whose internal structure is confounded by roundness.

FunnyNodulesDatasetGenerator writes the dataset on first use and only supports config.confounder_probability == 0.5: the unpoisoned pool has to exist before a poisoned variant can be derived from it. An oracle over the six nodule attributes is loaded from the first existing of $PEAL_RUNS/funnynodules_roundness_confounding_size/torchvision/ foundation_poisoned098/model.cpl and the same path under funnynodules/; it backs sample_to_2d_latent.

Parameters:
  • config (DataConfig) – Uses dataset_path, confounder_probability and confounding_factors.

  • **kwargs – Forwarded to Image2MixedDataset.

Variables:

oracle (torch.nn.Module or None) – Attribute predictor in eval mode, or None if no checkpoint exists.

Raises:

NotImplementedError – If the dataset has to be generated but confounder_probability is not 0.5.

Methods

sample_to_2d_latent

Oracle attribute readout, reduced to the confounding factors.

Attributes

__init__(config, **kwargs)[source]

Generate the dataset if missing and load the first available oracle.

Parameters:

config (DataConfig)

sample_to_2d_latent(sample, mask=None)[source]

Oracle attribute readout, reduced to the confounding factors.

Parameters:
  • sample (torch.Tensor) – Image [C, H, W] or batch [N, C, H, W]; a single image is unsqueezed for the oracle and squeezed again afterwards.

  • mask (torch.Tensor, optional) – Ignored; kept for interface compatibility.

Returns:

Oracle outputs for the attributes named in config.confounding_factors, or all outputs if that is unset.

Return type:

torch.Tensor

Raises:

RuntimeError – If no oracle checkpoint was found at construction time.