peal.data.interfaces.PealDataset¶
- class peal.data.interfaces.PealDataset[source]¶
Bases:
DatasetBase class of every dataset in PEAL.
Subclasses (see
peal.data.datasetsandcustom_datasets) hold aconfig(DataConfig) and usually anormalizationtransform. The methods defined here are defaults/hooks: most return placeholders and are meant to be overridden when a dataset supports the corresponding feature.project_to_pytorch_default/project_from_pytorch_defaultare the bridge between the classifier’s input format and the generator’s image format and are used by every counterfactual explainer.Methods
Hook: distance of
x_listto the data distribution (returns None).Hook: fraction of counterfactuals whose label differs (returns None).
Render original/counterfactual pairs for teachers and tracking (hook).
Hook: distance between two samples in dataset units (returns None).
This function maps pytorch default image to the processed format
This function maps processed data sample back to pytorch default format
This function serializes the dataset to a given directory
This function tracks the performance of the generator
Hook: diversity/variance of a list of samples (returns None).
- generate_contrastive_collage(x_list, x_counterfactual_list, y_target_list, y_source_list, y_list, y_target_start_confidence_list, y_target_end_confidence_list, base_path, start_idx, y_counterfactual_teacher_list=None, y_original_teacher_list=None, feedback_list=None, **kwargs)[source]¶
Render original/counterfactual pairs for teachers and tracking (hook).
Subclasses write one collage image per pair under
base_pathand return the paths plus per-sample attribution maps; teachers such asBaselineTeacherorModel2ModelTeachercall this to show or log the counterfactuals they judge.- Parameters:
x_list (
listoftorch.Tensor) – Originals and their counterfactuals, in dataset format.x_counterfactual_list (
listoftorch.Tensor) – Originals and their counterfactuals, in dataset format.y_target_list (
list) – Target class of the edit, class predicted for the original, and ground-truth label.y_source_list (
list) – Target class of the edit, class predicted for the original, and ground-truth label.y_list (
list) – Target class of the edit, class predicted for the original, and ground-truth label.y_target_start_confidence_list (
list) – Student confidence in the target class before and after the edit.y_target_end_confidence_list (
list) – Student confidence in the target class before and after the edit.base_path (
str) – Directory to write the collages to.start_idx (
int) – Offset used to number the written files.y_counterfactual_teacher_list (
list, optional) – Teacher-model predictions, if available.y_original_teacher_list (
list, optional) – Teacher-model predictions, if available.feedback_list (
list, optional) – Feedback strings to print onto the collage.kwargs (dict)
- Returns:
This base implementation only returns a
(3, 64, 64)zero tensor. Overrides return(collage_paths, attribution_list).- Return type:
- serialize_dataset(output_dir, x_list, y_list, sample_names=None)[source]¶
This function serializes the dataset to a given directory
- project_to_pytorch_default(x)[source]¶
This function maps processed data sample back to pytorch default format
- Parameters:
x (
torch.tensor) – The data sample in the processed format- Returns:
The data sample in the pytorch default format
- Return type:
torch.tensor
- project_from_pytorch_default(x)[source]¶
This function maps pytorch default image to the processed format
- Parameters:
x (
torch.tensor) – The data sample in the pytorch default format- Returns:
The data sample in the processed format
- Return type:
torch.tensor
- track_generator_performance(generator, batch_size=1)[source]¶
This function tracks the performance of the generator
- Parameters:
generator (
Generator) – The generator
- distribution_distance(x_list)[source]¶
Hook: distance of
x_listto the data distribution (returns None).