peal.visualization.model_comparison.get_explanation

peal.visualization.model_comparison.get_explanation(X, description, scores, checkbox_dict, explainer, batch_size=1)[source]

Explain every row of X with one model and return grid columns.

Parameters:
  • X (torch.Tensor) – Images of shape (N, C, H, W), one per criterion combination.

  • description (tuple) – (explanation_type, model, target_key, base_path): the model to explain, the criterion whose checkbox column gives the source label per row, and the directory counterfactual artifacts are written to.

  • scores (torch.Tensor) – Shape (N,): the model’s softmax score for the reference class per row, used to label the images.

  • checkbox_dict (dict) – Output of create_checkbox_dict (or the caller-provided one).

  • explainer (LRPExplainer or CounterfactualExplainer) – Decides which branch is taken. explainer.predictor must already be set to the model in question.

  • batch_size (int) – Batch size for the counterfactual branch.

Returns:

  • images (list of torch.Tensor) – Two image stacks of shape (N, 3, H, W): [heatmap, overlay] for LRP or [counterfactual, attribution] for counterfactuals.

  • labels (list of str) – One caption per row (target and score for LRP, before -> after confidence for counterfactuals).