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
Xwith 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 ofcreate_checkbox_dict(or the caller-provided one).explainer (
LRPExplainerorCounterfactualExplainer) – Decides which branch is taken.explainer.predictormust already be set to the model in question.batch_size (
int) – Batch size for the counterfactual branch.
- Returns:
images (
listoftorch.Tensor) – Two image stacks of shape(N, 3, H, W):[heatmap, overlay]for LRP or[counterfactual, attribution]for counterfactuals.labels (
listofstr) – One caption per row (target and score for LRP,before -> afterconfidence for counterfactuals).