From Visual Explanations to Counterfactual Explanations with Latent Diffusion

Tung M. Luu, Nam Le, Duc Le, Bac Le · DOI

TL;DR

The ECED (Explanations to Counterfactual Explanations with Diffusion) framework transforms traditional "where is the model looking?" heatmaps into realistic "what if?" images. By combining visual explanation masks with Latent Diffusion Models and pruned adversarial gradients, it generates subtle, semantically meaningful image edits that flip a classifier's decision without requiring specialized robust models.

What Problem Does This Paper Address?

Deep learning classifiers are often "black boxes." To peek inside, researchers use visual explanations (like heatmaps) to show which pixels influenced a decision. However, heatmaps have a major flaw: for two similar classes (e.g., an Egyptian cat vs. a Persian cat), the heatmaps often overlap on the face, failing to show the distinguishing features.

Counterfactual Explanations (CEs) offer a solution by generating a hypothetical image: "If this cat had fluffier fur, it would be a Persian cat." The challenge is generating these images so they are:

  1. Realistic: They shouldn't look like noisy adversarial examples.
  2. Minimal: Only the necessary features should change (the "foreground"), while the rest (the "background") remains untouched.
  3. Model-Specific: They should explain the actual classifier in use, not a separate, "adversarially robust" version of it.

Methods

The authors propose ECED, a three-step pipeline that bridges the gap between static heatmaps and generative counterfactuals:

  1. Identifying Key Regions: The system uses ScoreCAM to generate an attention map for the original image. It then applies a threshold to create a binary mask, separating the "foreground" (features the model cares about) from the "background."
  2. Background Preservation: To ensure the background doesn't shift during the generative process, ECED fine-tunes the Variational Autoencoder (VAE) decoder and optimizes a "background latent" representation. This ensures that when the image is reconstructed, the non-essential parts are pixel-perfect matches to the original.
  3. Counterfactual Generation via Latent Diffusion: The core of the method uses Blended Latent Diffusion. It takes adversarial gradients from the target classifier to push the image toward a new label. Crucially, it prunes these gradients, zeroing out any changes suggested for the background. The Latent Diffusion Model then "fills in" the foreground changes, ensuring the new features (like adding stripes to a cougar to make it a cheetah) look natural and align with the target concept.

Datasets

The authors evaluated ECED on two primary benchmarks:

  • ImageNet: Specifically focusing on challenging subsets where classes are visually similar (e.g., Zebra $\leftrightarrow$ Sorrel, Cheetah $\leftrightarrow$ Cougar, Egyptian Cat $\leftrightarrow$ Persian Cat).
  • CelebA-HQ: Explaining facial attribute classifiers for traits like "Smiling" and "Age."

Key Insights and Ideas

  • The Affiliation Principle: The paper argues that visual explanations and counterfactuals are two sides of the same coin. By using the heatmap to define the "edit zone," the counterfactual becomes much more efficient and localized.
  • Gradient Pruning as a Catalyst: By zeroing out gradients in the background, the optimization process doesn't "waste" energy trying to perturb irrelevant pixels. This forces the adversarial attack to find semantically meaningful changes within the foreground mask.
  • Diffusion as a Naturalizer: Standard adversarial attacks produce "noise" that flips a label but looks like static to humans. By performing the attack within the latent space of a Diffusion Model, the model's internal "knowledge" of what real objects look like acts as a constraint, forcing the attack to manifest as realistic textures or shapes.

Key Results

ECED outperformed existing state-of-the-art methods (like ACE and DVCE) across several metrics:

  • Validity: It achieved a Flip Ratio (FR) of nearly 100% on most tasks, meaning it successfully convinced the classifier to change its mind.
  • Sparsity: Using the COUT metric (which measures how efficiently a change flips a label), ECED showed it could achieve the target class with fewer, more targeted changes than its predecessors.
  • Realism: Qualitative results show remarkably subtle changes—such as adding a slight "smile" or thinning hair for "age"—that look like real photos rather than digital edits. On ImageNet, it successfully added complex textures (like zebra stripes) while keeping the surrounding environment (grass, riders) identical.

Limitations and Future Work

  • Computational Cost: Generating a single counterfactual takes roughly 150 seconds. While faster than some diffusion-based competitors, it is still too slow for real-time interactive explanation tools.
  • Manual Tuning: The threshold for the foreground mask ($\xi$) currently requires manual adjustment to balance the trade-off between how much of the image changes and how easily the classifier's label flips.
  • Future Directions: The authors suggest exploring ways to automate the thresholding process and optimizing the diffusion sampling steps to bring the generation time down to a few seconds.

Summary updated

Abstract

Visual counterfactual explanations are ideal hypothetical images that change the decision-making of the classifier with high confidence toward the desired class while remaining visually plausible and close to the initial image. In this paper, we propose a new approach to tackle two key challenges in recent prominent works: i) determining which specific counterfactual features are crucial for distinguishing the “concept” of the target class from the original class, and ii) supplying valuable explanations for the non-robust classifier without relying on the support of an adversarially robust model. Our method identifies the essential region for modification through algorithms that provide visual explanations, and then our framework generates realistic counterfactual explanations by combining adversarial attacks based on pruning the adversarial gradient of the target classifier and the latent diffusion model. The proposed method outperforms previous state-of-the-art results on various evaluation criteria on ImageNet and CelebA-HQ datasets. In general, our method can be applied to arbitrary classifiers, highlight the strong association between visual and counterfactual explanations, make semantically meaningful changes from the target classifier, and provide observers with subtle counterfactual images.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
CelebA · HQ (Smile attributeACE ℓ1FS (Face Similarity)0.8941Counterfactual Explanation · backbone=DenseNet121 · attribute=Smile
Source quote
L151: ACE \ell_1 │ 3.21 │ 20.2 │ 100.0 │ 0.8941 │ 1.56 │ 2.61 │ 0.5496 │ 5.31 │ 21.7 │ 99.6 │ 0.8085 │ 1.53 │ 5.4 │ 0.3984
CelebA · HQ (Age attributeACE ℓ1FS (Face Similarity)0.8085Counterfactual Explanation · backbone=DenseNet121 · attribute=Age
Source quote
L151: ACE \ell_1 │ 3.21 │ 20.2 │ 100.0 │ 0.8941 │ 1.56 │ 2.61 │ 0.5496 │ 5.31 │ 21.7 │ 99.6 │ 0.8085 │ 1.53 │ 5.4 │ 0.3984
CelebA · HQ (Age attributeACE ℓ1MNAC (Mean Number of Attribute Changes)1.53Counterfactual Explanation · backbone=DenseNet121 · attribute=Age
Source quote
L151: ACE \ell_1 │ 3.21 │ 20.2 │ 100.0 │ 0.8941 │ 1.56 │ 2.61 │ 0.5496 │ 5.31 │ 21.7 │ 99.6 │ 0.8085 │ 1.53 │ 5.4 │ 0.3984
BibTeX
@misc{luu2025from,
  author = {Tung M. Luu and Nam Le and Duc Le and Bac Le},
  title = {{From Visual Explanations to Counterfactual Explanations with Latent Diffusion}},
  year = {2025},
  eprint = {2504.09202},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2504.09202},
}
Figure