Explaining Image Classifiers by Counterfactual Generation

Chun-Hao Chang, Elliot Creager, Anna Goldenberg, David Duvenaud

To understand why a deep learning model makes a specific prediction (e.g., classifying an image as a "duck"), researchers often rely on saliency maps to highlight the most influential pixels. A common way to generate these maps is by masking parts of the image and observing if the classification score drops. However, traditional masking techniques introduce a critical flaw: they create unnatural images that confuse the model.

This paper introduces FIDO (Fill-In the DropOut), a framework that uses conditional generative models to fill masked regions with plausible "counterfactual" pixels. By keeping the modified images within the natural data distribution, FIDO produces more compact, relevant, and human-interpretable saliency maps.

The Problem with Traditional Saliency Maps

The fundamental gap in traditional saliency mapping lies in how pixels are "removed." Previous methods rely on heuristics like replacing regions with solid gray blocks, Gaussian noise, or blurred versions of the original image.

Because the classifier was never trained on "gray-blocked" or "blurry-holed" images, these unnatural inputs are out-of-distribution (OOD). Consequently, the classifier's response might be driven by the weirdness of the mask itself rather than the absence of the underlying feature. This OOD problem leads to "artifacts"—saliency maps that are excessively noisy or highlight irrelevant background pixels simply because the mask disrupted the image manifold.

The FIDO Framework: Generative In-filling

To solve this, the authors propose FIDO, a model-agnostic framework that treats the masked region as an unobserved variable and marginalizes it out using a conditional generative model.

Comparison of graphical models for classification, heuristic in-filling, and generative in-filling.

Instead of using a fixed heuristic, FIDO operates through the following mechanisms:

  1. Generative In-filling: When a region is masked, a generative model (such as a Contextual Attention GAN or a VAE) "hallucinates" what could plausibly be in that spot based on the surrounding context. The in-filling function creates a convex mixture of the original image and a sample from the generative model, ensuring the resulting "counterfactual" image looks like a real photo.
  2. Variational Bernoulli Dropout: Rather than optimizing a single continuous mask, FIDO optimizes the parameters of a Bernoulli distribution for each pixel. This essentially learns a "dropout rate" for every pixel to find the Smallest Supporting Region (SSR) (the minimum pixels needed to maintain a classification) or the Smallest Deletion Region (SDR) (the minimum pixels needed to destroy a classification).
  3. Optimization: The framework uses the Concrete distribution (a continuous relaxation) to backpropagate through the discrete random masks, optimizing for a mask that is both sparse and highly influential on the classifier's log-odds score.

Key Insights and Results

The primary evaluation was performed on the ImageNet dataset across standard classifier architectures like AlexNet, VGG, and ResNet. The results highlight the importance of respecting the manifold: explanations are significantly more reliable when the "interrogated" images stay close to the natural image distribution.

Visual comparison of saliency maps generated by heuristic methods versus generative methods.
  • Qualitative Superiority: Visualizations demonstrate that FIDO (particularly using Contextual Attention GANs, or FIDO-CA) produces much cleaner saliency maps. These maps tightly "hug" the object of interest compared to heuristic baselines, which often highlight large, diffuse, and irrelevant areas.
  • Context Matters: Heuristic masks ignore spatial relationships. FIDO’s use of generative models allows the mask to be filled with textures and structures that actually fit the scene, preventing the classifier from being distracted by sharp edges or unnatural colors at the mask boundaries.
  • Quantitative Performance: On a Saliency Metric (SM) measuring information concentration (where lower is better), FIDO-CA achieved a score of -0.021, significantly outperforming heuristic methods like Blur (0.766).
  • SSR vs. SDR: The authors found that the Smallest Supporting Region (SSR) objective is generally more robust and less prone to artifacts than the Smallest Deletion Region (SDR) objective.

Limitations and Future Directions

While FIDO represents a significant step forward in model interpretability, it has limitations. First, it is computationally expensive. Because it requires an optimization loop for each image, it takes about one minute per image on a single GPU, making it slower than single-pass saliency methods.

Second, FIDO is dependent on the generative model. If the underlying GAN or VAE cannot produce a high-quality, diverse set of in-fills for a specific domain, the resulting saliency map may be inaccurate. However, this limitation is also an opportunity: as generative models (like modern Diffusion models) continue to improve, the quality of these counterfactual explanations will naturally scale with them, potentially expanding this approach to non-image domains.

Summary updated

BibTeX
@inproceedings{chang2019explaining,
  author = {Chun-Hao Chang and Elliot Creager and Anna Goldenberg and David Duvenaud},
  title = {{Explaining Image Classifiers by Counterfactual Generation}},
  booktitle = {International Conference on Learning Representations},
  year = {2019},
  url = {https://openreview.net/forum?id=0iLUm3iAFO},
}
Figure