Explaining Image Classifiers Using Contrastive Counterfactuals in Generative Latent Spaces

Kamran Alipour, Aditya Lahiri, Ehsan Adeli, Babak Salimi, Michael J. PazzaniarXiv 2022 · DOI

Introduction

Modern deep learning image classifiers achieve remarkable accuracy but remain notoriously opaque. While existing eXplainable AI (XAI) techniques like saliency maps highlight pixels correlated with a class, they often fail to provide a causal explanation. This paper addresses this gap by introducing a framework for generating "contrastive counterfactuals"—realistic image modifications that answer the question: "If attribute $X$ had been different, would the model's decision have changed?"

Methodology: The Counterfactual Pipeline

The proposed approach leverages the structured latent space of pretrained generative models, specifically StyleGAN2, to perform interventions that remain on the manifold of realistic images. The pipeline consists of three primary components:

  1. Pretrained Generative Model ($G$): A high-fidelity generator (e.g., StyleGAN2) produces images from latent codes. Notably, $G$ does not need to be trained on the same data as the classifier it explains.
  2. Counterfactual Shift Predictor ($M$): An MLP trained to find the optimal shift in the latent space. Given an image's latent code $z$ and a target attribute change, $M$ predicts a new code $\hat{z}$ that modifies specific features while preserving the identity and context of the original image.
  3. Causal Metrics: To quantify the explanation, the authors formalize two probabilistic scores: Probability of Necessity (NEC), which measures if an existing attribute is required for the current classification, and Probability of Sufficiency (SUF), which measures if adding an attribute is enough to flip the model's decision.
The proposed counterfactual generation pipeline.

The Shift Predictor is trained using a dual-objective loss function that balances the classifier's detection of the intended attribute change with a "faithfulness" factor $\gamma$ to ensure visual similarity to the original image.

Experimental Evaluation

The framework was evaluated using the CelebA dataset, focusing on explaining a classifier trained to predict "Attractiveness." Six explanatory attributes were tested: blonde hair, heavy makeup, baldness, mustache, youngness, and maleness.

Key Results and Insights

The method demonstrates several advantages over traditional XAI:

  • Causality over Correlation: By intervening in the latent space, the framework proves that specific features cause changes in output, rather than just being present.
  • Model Agnosticism: The Shift Predictor can explain any black-box model without requiring access to internal weights or gradients.
  • Visual Evidence: The system generates a grid of counterfactual images, allowing users to visually inspect the decision boundary of the black-box model as attributes are progressively altered.
Visualizing counterfactual shifts across multiple attributes.

In testing a VGG-based attractiveness classifier, the system revealed significant biases. For instance, decreasing baldness or mustaches showed high Necessity scores for maintaining an "attractive" label. Conversely, increasing "heavy makeup" and "youngness" were identified as the most Sufficient attributes to flip a negative classification to a positive one.

Limitations and Future Directions

A primary challenge identified is attribute entanglement within the GAN's latent space, where changing one feature (e.g., age) might inadvertently affect another (e.g., hair color). Future work aims to integrate Structural Causal Models (SCMs) to explicitly model these dependencies, enabling the calculation of direct versus indirect effects and providing a more robust tool for detecting hidden biases in AI systems.

Summary updated

BibTeX
@misc{alipour2022explaining,
  author = {Kamran Alipour and Aditya Lahiri and Ehsan Adeli and Babak Salimi and Michael J. Pazzani},
  title = {{Explaining Image Classifiers Using Contrastive Counterfactuals in Generative Latent Spaces}},
  year = {2022},
  eprint = {2206.05257},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2206.05257},
}
Figure