peal.teachers.segmentation_mask_teacher.SegmentationMaskTeacher

class peal.teachers.segmentation_mask_teacher.SegmentationMaskTeacher[source]

Bases: TeacherInterface

Teacher 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_threshold the change lies inside the annotated region and the feedback is "true", otherwise "false".

Parameters:
  • attribution_threshold (float) – Decision threshold on the mean of heatmap * (hint - hint.mean()).

  • dataset (peal dataset) – Dataset providing generate_contrastive_collage for 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; >= 5 writes collage images to base_dir.

Methods

get_feedback

Produce one feedback string per counterfactual.

__init__(attribution_threshold, dataset, counterfactual_type='1sided', tracking_level=0)[source]
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 (list of torch.Tensor) – Attribution heatmap of each counterfactual (same spatial shape as the hint mask).

  • hint_list (list of torch.Tensor) – Binary segmentation mask of the legitimate region per sample.

  • base_dir (str) – Directory the collage is written to when tracking_level >= 5.

  • x_counterfactual_list (list of torch.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 (list of torch.Tensor) – Original images.

  • y_list (list) – Ground-truth labels of the originals.

  • y_target_end_confidence_list (list of float) – 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:

list of str