peal.teachers.spray_teacher.Spray¶
- class peal.teachers.spray_teacher.Spray[source]¶
Bases:
TeacherInterfaceTeacher that derives confounder group labels from a SpRAy analysis.
The constructor loads the classifier (unwrapping a
.modelattribute if present), loads the train/val/test datasets with URLs and groups enabled, and preparesbase_dir.get_feedback()then runs the attribution, clustering and ViReLay steps and returns a filename -> group-label map.- Parameters:
config (
dictorSprayConfig) – SeeSprayConfig.device (
str, optional) – Torch device; CUDA when available by default.
- Variables:
analysis_dir (
str) –<base_dir>/attrbs-layer-<n>_analysis, set byget_feedback.analysis_db_path (attribution_db_path, heatmaps_db_path, concept_importance_db_path, input_db_path,) – HDF5 files produced by the analysis.
Methods
Run the full SpRAy pipeline and return per-sample confounder labels.
- __init__(config, device=None)[source]¶
Load the classifier and the datasets and create
base_dir.Scalar
tsne_perplexity/umap_neighborsentries are wrapped in a list, the model is unwrapped (model.model) and put in eval mode, and the train/val/test datasets are loaded with URLs and groups enabled and class restrictions disabled, so that every sample can be attributed and matched back to its file. The HDF5 paths are only set later, byget_feedback().- Parameters:
config (
dictorSprayConfig) – SeeSprayConfig; a dict is validated into one.device (
str, optional) – Torch device; CUDA when available by default.
- get_feedback(**args)[source]¶
Run the full SpRAy pipeline and return per-sample confounder labels.
Steps: compute attributions into HDF5 databases, spectrally cluster them per class, write a label map and ViReLay project, run the GUI until the user has exported
<cls>-confounders.json/<cls>-nonconfounders.jsonintogroup-labels/(the process exits and must be re-run after that), then read the selections. Side effects:config.yaml,data_spray_labels.csv(the dataset’sdata.csvplus aSprayLabelcolumn, -1 for unlabelled) andresult_summary.txt(label accuracy againsthas_confounder) underanalysis_dir.- Parameters:
**args – Ignored; present for the
TeacherInterfacesignature.- Returns:
Sample filename -> 1 (confounder selected) or 0 (non-confounder).
- Return type:
- Raises:
ImportError – If the optional
h5pydependency is not installed.