peal.teachers.segmentation_mask_teacher.SegmentationMaskTeacher¶
- class peal.teachers.segmentation_mask_teacher.SegmentationMaskTeacher[source]¶
Bases:
TeacherInterfaceTeacher that scores attribution maps against segmentation hints.
For every counterfactual the (mean-centred) hint mask is multiplied with the attribution heatmap; if the mean of that product exceeds
attribution_thresholdthe change lies inside the annotated region and the feedback is"true", otherwise"false".- Parameters:
attribution_threshold (
float) – Decision threshold on the mean ofheatmap * (hint - hint.mean()).dataset (
peal dataset) – Dataset providinggenerate_contrastive_collagefor tracking.counterfactual_type (
{"1sided", "2sided"}) – With"1sided"a counterfactual whose original prediction was wrong gets the feedback"student originally wrong!".tracking_level (
int) – Verbosity level;>= 5writes collage images tobase_dir.
Methods
Produce one feedback string per counterfactual.
- get_feedback(x_attribution_list, hint_list, base_dir, x_counterfactual_list, y_source_list, y_target_list, x_list, y_list, y_target_end_confidence_list, student=None, **kwargs)[source]¶
Produce one feedback string per counterfactual.
- Parameters:
x_attribution_list (
listoftorch.Tensor) – Attribution heatmap of each counterfactual (same spatial shape as the hint mask).hint_list (
listoftorch.Tensor) – Binary segmentation mask of the legitimate region per sample.base_dir (
str) – Directory the collage is written to whentracking_level >= 5.x_counterfactual_list (
listoftorch.Tensor) – Counterfactual images.y_source_list (
list) – Class the student predicted for each original sample.y_target_list (
list) – Target class of each counterfactual.x_list (
listoftorch.Tensor) – Original images.y_list (
list) – Ground-truth labels of the originals.y_target_end_confidence_list (
listoffloat) – Student confidence for the target class on the counterfactual.student (
torch.nn.Module) – The classifier being explained; only used to determine the device.**kwargs – Forwarded to
dataset.generate_contrastive_collage.
- Returns:
One of
"true","false","student originally wrong!"or"student not swapped!"per counterfactual.- Return type: