Explainable Image Classification

Machine Learning
Introduced by
Selvaraju et al. (Grad-CAM); Ribeiro et al. (LIME)
Year
2016-2017
Type
Post-hoc explainability applied to image classifiers
Family
Deep learning / NLP / CV

What does it do?

Explainable image classification combines a deep learning image classifier — typically a CNN or Vision Transformer — with a post-hoc or intrinsic interpretability method such as Grad-CAM, LIME, or SHAP to produce visual or quantitative explanations of why the model assigned a particular label to an image.

The goal is to make the classifier's decision process transparent, auditable, and trustworthy.

The intuition behind the method

When a medical imaging classifier marks a scan as malignant, clinicians need to know which pixels drove that judgment. Explainability methods answer this by highlighting the image regions the model weighted most heavily. Grad-CAM uses gradients flowing into the final convolutional layer to weight that layer's feature maps, producing a heatmap overlaid on the original image. LIME perturbs superpixels and fits a local linear model to approximate the classifier's behaviour near the input. SHAP assigns each pixel (or superpixel) a contribution score rooted in cooperative game theory. The result is a human-readable visual explanation alongside the classification output.

History

Ribeiro et al. introduced LIME in 2016 as a way to explain the predictions of any classifier, and Selvaraju et al. introduced Grad-CAM at ICCV in 2017 as a gradient-based localisation method for CNNs that requires no architectural changes or retraining. Explainability has since become a substantial subfield, and regulatory frameworks increasingly call for transparency in automated decisions.

When to use it

Use explainable image classification when the reasons for a prediction must be inspected: medical imaging diagnostics where clinicians or regulators need to see the evidence, industrial defect inspection that requires auditable decisions, scientific image analysis where attribution to image regions is part of the question, or any deployment where stakeholders must be able to challenge model outputs. It is also useful for debugging classifiers, since explanation maps can reveal shortcut learning, for example a skin-lesion classifier that keys on image ruler artefacts rather than tissue texture. Do not use explanations as a substitute for rigorous model validation, and do not add an explanation layer when only a label is needed and no one will inspect the reasoning. When the base classifier is weak, explanations will be unreliable whatever XAI method is chosen.

Limitations and considerations

  • Post-hoc explanations approximate the model's reasoning rather than revealing its true internal computation, so faithfulness is never guaranteed.
  • Grad-CAM produces a coarse localisation map, so it may not localise fine-grained decision boundaries accurately.
  • LIME and SHAP require many model evaluations on perturbed inputs, which can make them expensive for high-resolution images and limit real-time use.
  • Explanation quality is bounded by classifier quality; explanations of a poorly performing model are themselves unreliable.
  • Different XAI methods can produce conflicting attributions for the same input, so choosing a method is itself a substantive decision.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Makes black-box image classifiers inspectable without architectural changes, which supports transparency requirements.
  • Grad-CAM produces class-specific spatial heatmaps from gradients already computed in the backward pass, and applies to a wide range of CNN architectures without architectural changes or retraining.
  • SHAP provides additive attribution values for each prediction, computed relative to a chosen baseline; comparing values across images requires a common baseline and normalisation, so such comparisons should be made with care.
  • Can reveal failure modes and dataset bias, for example by showing whether the model attends to semantically meaningful regions rather than contextual cues.
  • Model-agnostic methods such as LIME and SHAP can explain pretrained backbones, including ResNet, EfficientNet and ViT models, without re-training the classifier, while Grad-CAM works with CNN backbones such as ResNet-based architectures without re-training.
  • Quantitative faithfulness metrics allow competing explanation methods to be compared systematically on the same model.

Applications

  • Medical imaging: highlighting tumour regions in radiology or dermatology classifiers for clinician review.
  • Remote sensing: explaining land-use classification decisions in satellite imagery for environmental monitoring.
  • Industrial quality control: auditing defect detection models to identify which surface features trigger rejection.
  • Scientific image analysis: attributing classification decisions to biologically or physically meaningful image structures.
  • AI fairness auditing: detecting whether classifiers rely on spurious or demographically sensitive image features.
  • Model debugging: identifying shortcut learning by inspecting whether heatmaps highlight contextually irrelevant regions.

How it works

How it works

1

A standard image classifier, typically a pretrained CNN (such as ResNet or EfficientNet) or a Vision Transformer fine-tuned on the target dataset, is trained or loaded. Its performance is validated on held-out data using accuracy, F1, and AUC before any explanation is generated, because explanations of a weak classifier are unreliable.

2

An explainability strategy is chosen based on the requirements. Grad-CAM and similar gradient-based methods produce coarse spatial heatmaps from gradients in convolutional layers and need access to model internals. LIME treats the model as a black box and fits a local surrogate to its behaviour near the input. SHAP, in its deep or kernel form, gives attribution values with a game-theoretic basis. Attention visualisation is specific to transformer architectures and should not be treated as a general attribution method.

3

The chosen method computes pixel- or region-level attribution scores. For Grad-CAM, gradients of the target class score with respect to the final convolutional feature map are global-average-pooled to give one weight per feature channel; the weighted combination of those channels forms a class activation map. For LIME, the image is segmented into superpixels, subsets of superpixels are masked, and the classifier's predictions on the perturbed images train an interpretable local model whose coefficients serve as the attribution.

4

Attribution scores are upsampled and overlaid onto the original image as a heatmap (for gradient-based methods) or displayed as highlighted superpixels (for LIME). The explanation is presented alongside the predicted class label and confidence score so stakeholders can check whether the highlighted regions are relevant to the domain.

5

Explanation quality is assessed quantitatively with insertion and deletion curves, which track the model's score for the predicted class as the image is progressively altered. In a deletion curve, the most highly attributed pixels are masked first; a faithful explanation makes the score fall quickly. In an insertion curve, pixels are revealed in order of attribution on a blank baseline; a faithful explanation makes the score rise quickly. To read the curves, compare each method against a random pixel ordering on the same model and with the same masking protocol, since a curve is informative only relative to that baseline. Qualitative review by domain experts is also standard, particularly in high-stakes applications such as medical imaging or satellite analysis.

Common pitfalls

  • Treating explanation maps as proof of correct model behaviour without checking them with insertion/deletion curves or expert review.
  • Applying Grad-CAM to a network without a convolutional feature map that keeps spatial layout. Grad-CAM applies to CNNs with fully-connected layers such as VGG, so the restriction concerns the loss of spatial feature maps, not the presence of fully connected layers.
  • Reporting qualitative heatmaps without quantitative faithfulness evaluation, which can mislead reviewers about how reliable the explanations are.
  • Ignoring the fragility of explanations under adversarial or imperceptible input perturbations: small changes can drastically alter a heatmap while the predicted label stays the same.
  • Conflating attention weights in transformers with causal explanation; attention and attribution are not equivalent.

Frequently asked questions

Which explainability method should I choose for my image classifier?

For CNN-based models where you need a quick spatial heatmap, Grad-CAM is a common starting point. For black-box models, LIME or kernel SHAP are options, though both can be costly on high-resolution images. For Vision Transformers, attention-based visualisation is the architecture-native option, but attention weights are not a substitute for attribution. Complement any qualitative heatmap with quantitative faithfulness evaluation.

Is Grad-CAM applicable to Vision Transformers?

Standard Grad-CAM is described for CNN feature maps and does not directly apply to pure ViT architectures without adaptation. Transformer-specific variants or attention-based methods are better suited to pure ViTs. For hybrid architectures with convolutional stems, standard Grad-CAM can target the convolutional layers.

How do I know if my explanation is trustworthy?

Apply quantitative faithfulness tests: deletion curves, which track the predicted-class score as the most salient pixels are progressively masked, and insertion curves, which track it as pixels are revealed in order of salience. A faithful explanation makes the score fall quickly under deletion and rise quickly under insertion, compared with a random pixel ordering. Use the same model and masking protocol when comparing methods. Complement these metrics with review by domain experts, since a heatmap that looks plausible can still be unfaithful.

Can I use explainability methods during training, or only after?

Most methods discussed here (Grad-CAM, LIME, SHAP) are post-hoc and applied after training. Intrinsic approaches build interpretability into the model or its training objective, at the possible cost of some classification accuracy and greater architectural complexity.

Does explainability improve model performance?

Not directly. Explainability methods are diagnostic tools, not training-time optimisers. However, insights from explanation maps can guide data curation (removing spurious correlations), architecture choice, and fine-tuning decisions that indirectly lead to better and more robust classifiers.

Related methods

Sources

  1. Selvaraju, R. R., Cogswell, M., Das, A., Vedantam, R., Parikh, D., & Batra, D. (2017). Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization. Proceedings of the IEEE International Conference on Computer Vision (ICCV), 618-626.

    Open DOI reference
  2. Ribeiro, M. T., Singh, S., & Guestrin, C. (2016). Why Should I Trust You?: Explaining the Predictions of Any Classifier. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, 1135-1144.

    Open DOI reference