---
title: 'Mirror-CFE: Counterfactual Image Explanations'
url: https://www.emergentmind.com/topics/mirror-cfe
type: topic
---

# Mirror-CFE: Counterfactual Image Explanations

Searching arXiv for Mirror-CFE and closely related counterfactual-explanation work.
Mirror-CFE is a counterfactual explanation method for deep image classification models that generates explanations by operating directly in the classifier’s own feature space rather than in an external latent space. Its central construction treats the pairwise decision boundary between a source class and a target class as a geometric “mirror,” reflects the source feature across that hyperplane, and then learns an inverse mapping back to image space while preserving distance relationships. In this formulation, counterfactual validity, input resemblance, and faithfulness to the trained classifier are addressed jointly, and the method also yields step-wise transitions that visualize how features evolve as classification confidence changes [2509.16822].

## 1. Problem setting and conceptual basis

Mirror-CFE is designed for the standard counterfactual question for deep image classifiers: what minimal change to an input image would flip the model’s decision from its original class \(s\) to a target class \(t\) [2509.16822]. In the formulation used by the method, a good counterfactual explanation should be valid, plausible, proximal, sparse, diverse, and faithful. The last of these is treated as the defining requirement: the explanation should reflect exactly what the classifier has learned, including both its feature representation and its decision boundaries.

The method is motivated by limitations attributed to earlier counterfactual pipelines. Earlier methods are described as typically following one of three patterns: exhaustive search in pixel or latent spaces, reliance on external generative models such as VAEs, GANs, or diffusion models, or region editing by example retrieval. In the Mirror-CFE formulation, such approaches usually ignore the actual decision boundaries and feature embeddings of the trained classifier, which can produce unfaithful explanations, including adversarial noise or unrealistic edits, and provide no direct access to the classifier’s own latent geometry.

The distinctive claim of Mirror-CFE is therefore not merely that it produces realistic edited images, but that it explains the intrinsic feature space and decision boundaries learned by the classifier. This suggests that the method should be understood primarily as a classifier-faithful explanation framework rather than as a generic image-editing pipeline.

## 2. Geometric formulation in classifier feature space

Mirror-CFE formalizes the classifier as a pretrained feature extractor \(F:\mathcal{X}\to\mathcal{Z}\), with \(\mathcal{X}\subset\mathbb{R}^{C\times H\times W}\) the image space and \(\mathcal{Z}=\mathbb{R}^N\) the feature space, together with a final linear layer \(\mathbf{W}\in\mathbb{R}^{N\times|\mathcal{C}|}\) and bias \(\mathbf{b}\in\mathbb{R}^{|\mathcal{C}|}\). The classifier probabilities are written as

\[
\mathbf{p}(\mathbf{z}) \;=\;\sigma\bigl(\mathbf{W}^\top \mathbf{z} + \mathbf{b}\bigr)\;\in\Delta^{|\mathcal{C}|-1}.
\]

For a source class \(s\) and target class \(t\), Mirror-CFE defines the pairwise boundary parameters

\[
\mathbf{w}\;=\;\mathbf{W}_t \;-\;\mathbf{W}_s\;\in\mathbb{R}^N, \quad b\;=\;b_t \;-\;b_s,
\]

so that the hyperplane \(\mathbf{w}^\top\mathbf{z}+b=0\) is the pairwise decision boundary between \(s\) and \(t\) [2509.16822].

Given a source feature \(\mathbf{z}_s=F(\mathbf{x}_s)\), the full reflection across this hyperplane is

\[
\mathbf{z}_r \;=\; \mathbf{z}_s \;-\; 2\;\frac{\mathbf{w}^\top\mathbf{z}_s\;+\;b}{\|\mathbf{w}\|^2}\;\mathbf{w}.
\]

Mirror-CFE further introduces a step factor \(k\in[0,1]\), producing intermediate feature points

\[
\mathbf{z}_k \;=\; \mathbf{z}_s \;-\; 2\,k\; \frac{\mathbf{w}^\top\mathbf{z}_s + b}{\|\mathbf{w}\|^2}\;\mathbf{w}.
\]

This parameterization has an immediate decision-theoretic interpretation. When \(k=0.5\), \(\mathbf{z}_k\) is the orthogonal projection of the source feature onto the mirror; when \(k=1\), it is the full reflection. Any \(k>0.5\) yields a valid counterfactual feature that flips classification to \(t\), whereas \(k<0.5\) yields a semi-factual that remains in class \(s\). The method thereby converts counterfactual generation into a controlled traversal of the classifier’s own decision geometry.

## 3. Inverse mapping and training objective

The feature-space construction alone does not produce images. Mirror-CFE therefore learns an inverse map \(G:\mathcal{Z}\to\mathcal{X}\), together with a small adversarial discriminator \(D\), so that \(G(\mathbf{z}_k)\) is a realistic image whose classifier feature is \(\mathbf{z}_k\) [2509.16822]. The training objective combines five losses.

The classification loss enforces validity in feature space:

\[
\mathcal{L}_{\rm cls} =\; \mathbb{E}_{\mathbf{z}\in\{F(\mathbf{x}),\,\mathbf{z}_k\}}
\Bigl[\mathrm{KL}\bigl(\sigma(F(G(\mathbf{z})))\;\Big\|\;\sigma(\mathbf{z})\bigr)\Bigr].
\]

The adversarial term promotes realism:

\[
\mathcal{L}_{\rm adv} =\; -\;\mathbb{E}_{\mathbf{x}\sim\mathcal{X}}\bigl[\log D(\mathbf{x})\bigr] \;-\;\mathbb{E}_{\mathbf{z}_k}\bigl[\log(1-D(G(\mathbf{z}_k)))\bigr].
\]

The reconstruction loss imposes cycle consistency for real images:

\[
\mathcal{L}_{\rm rec} =\; \mathbb{E}_{\mathbf{x}\sim\mathcal{X}} \bigl[\|\mathbf{x}\;-\;G(F(\mathbf{x}))\|_1\bigr].
\]

The feature-reconstruction loss imposes cycle consistency for counterfactual features:

\[
\mathcal{L}_{\rm fea} =\; \mathbb{E}_{\mathbf{z}_k}\bigl[\|\mathbf{z}_k - F(G(\mathbf{z}_k))\|_2\bigr].
\]

The triangulation loss encodes proximity and plausibility. For a source image \(\mathbf{x}_s\), a target image \(\mathbf{x}_t\), and a generated image \(\mathbf{x}_k=G(\mathbf{z}_k)\), the ratio

\[
\beta = \frac{\|\mathbf{z}_k-\mathbf{z}_t\|}{\|\mathbf{z}_s-\mathbf{z}_k\|}
\]

is used to constrain relative image-space distances through

\[
(1-\alpha)\,\frac{\|\mathbf{x}_k-\mathbf{x}_t\|_1}{\beta} \;\le\; \|\mathbf{x}_s-\mathbf{x}_k\|_1 \;\le\; (1+\alpha)\,\frac{\|\mathbf{x}_k-\mathbf{x}_t\|_1}{\beta}.
\]

This is implemented as the one-sided hinge loss

\[
\mathcal{L}_{\rm cfe} = \max\bigl(\tfrac{1-\alpha}{\beta}\|\mathbf{x}_k-\mathbf{x}_t\|_1-\|\mathbf{x}_s-\mathbf{x}_k\|_1,\,0\bigr) \;+\; \max\bigl(\|\mathbf{x}_s-\mathbf{x}_k\|_1-\tfrac{1+\alpha}{\beta}\|\mathbf{x}_k-\mathbf{x}_t\|_1,\,0\bigr).
\]

For semi-factuals with \(k<0.5\), Mirror-CFE defines \(\gamma=\tfrac{\|\mathbf{z}_k-\mathbf{z}_{ss}\|}{\|\mathbf{z}_s-\mathbf{z}_k\|}\) relative to a random same-class sample \(\mathbf{z}_{ss}\), giving \(\mathcal{L}_{\rm sfe}\). The complete triangulation term is

\[
\mathcal{L}_{\rm tri} =\; \mathbb{1}_{k<0.5}\,\mathcal{L}_{\rm sfe} \;+\; \mathbb{1}_{k\ge0.5}\,\mathcal{L}_{\rm cfe}.
\]

The generator objective is then

\[
\mathcal{L}_G =\; \lambda_{\rm cls}\,\mathcal{L}_{\rm cls} \;+\; \lambda_{\rm adv}\,\mathcal{L}_{\rm adv} \;+\; \lambda_{\rm rec}\,\mathcal{L}_{\rm rec} \;+\; \lambda_{\rm fea}\,\mathcal{L}_{\rm fea} \;+\; \lambda_{\rm tri}\,\mathcal{L}_{\rm tri},
\]

with typical settings \(\alpha=0.2\), \(\lambda_{\rm cls}=\lambda_{\rm adv}=\lambda_{\rm rec}=\lambda_{\rm fea}=1\), and \(\lambda_{\rm tri}=1\) or \(2\) on some datasets. The overall design couples classifier consistency, visual realism, and geometric faithfulness in a single objective.

## 4. Architecture and optimization procedure

Mirror-CFE fixes the pretrained classifier \(F\) and does not fine-tune it during explanation generation, explicitly to guarantee faithfulness [2509.16822]. The decoder \(G\) is implemented as a U-Net with skip-connection controllers (SCC) that modulate the flow of high-frequency features from \(F\) to \(G\) through a small bottleneck, while a discriminator \(D\) evaluates realism.

Training alternates between generator and discriminator updates. The procedure samples real images and latent counterfactual points \(\{\mathbf{z}_k\mid k\in[0,1]\}\), computes \(\mathcal{L}_{\rm cls}, \mathcal{L}_{\rm adv}, \mathcal{L}_{\rm rec}, \mathcal{L}_{\rm fea}\), and \(\mathcal{L}_{\rm tri}\), updates \(G\) with Adam at learning rate \(2\times10^{-4}\), and then updates \(D\) to maximize \(\mathcal{L}_{\rm adv}\). Reported training schedules are approximately \(50\)–\(100\) epochs on MNIST, Fashion-MNIST, and Blood-MNIST, and approximately \(30\) epochs on CelebA-HQ.

A notable architectural constraint is that the method requires a GAP-based architecture to compute CAM masks in the SCC module. Vision Transformers, which are described as lacking GAP or meaningful CAMs in this setting, would therefore require approximate attentional priors. This limitation is not incidental: it follows from the specific way Mirror-CFE reuses the classifier’s own internal structure to preserve faithfulness.

## 5. Evaluation protocol and empirical results

Mirror-CFE is evaluated against PGD, REVISE, CEM, ExpGAN, and C3LT on four datasets: MNIST, Fashion-MNIST, Blood-MNIST, and CelebA-HQ [2509.16822]. The reported metrics are Validity, Denoised Validity, Proximity measured by mean \(L_1\) distance, Sparsity measured by LPIPS, Realism measured by FID, and \(\%\)Fail, the fraction of test cases for which no counterfactual is found.

The paper reports results for two operating points: the first valid counterfactual at \(k=0.5+\epsilon\), and the full reflection at \(k=1\).

| Dataset | First valid CFE (\(k=0.5+\epsilon\)) | Full reflection (\(k=1\)) |
|---|---|---|
| MNIST | \(L_1=0.16\), LPIPS \(=0.17\), FID \(=3.25\), D.Val. \(=0.99\), Val. \(=1.00\), Fail \(=0.0\) | \(L_1=0.26\), LPIPS \(=0.33\), FID \(=3.20\), D.Val. \(=0.99\), Val. \(=1.00\), Fail \(=0.0\) |
| F-MNIST | \(L_1=0.12\), LPIPS \(=0.10\), FID \(=2.80\), D.Val. \(=0.99\), Val. \(=0.99\), Fail \(=0.0\) | \(L_1=0.25\), LPIPS \(=0.21\), FID \(=4.40\), D.Val. \(=0.96\), Val. \(=0.99\), Fail \(=0.0\) |
| Blood-MNIST | \(L_1=0.05\), LPIPS \(=11.81\), FID \(=86.02\), D.Val. \(=0.99\), Val. \(=0.99\), Fail \(=0.0\) | \(L_1=0.14\), LPIPS \(=28.69\), FID \(=132.93\), D.Val. \(=0.98\), Val. \(=0.99\), Fail \(=0.0\) |
| CelebA-HQ | \(L_1=0.08\), LPIPS \(=0.051\), FID \(=8.78\), D.Val. \(=0.87\), Val. \(=0.94\), Fail \(=\text{–}\) | \(L_1=0.08\), LPIPS \(=0.053\), FID \(=8.97\), D.Val. \(=0.89\), Val. \(=0.94\), Fail \(=\text{–}\) |

Across these experiments, Mirror-CFE is reported to achieve the highest validity and denoised validity among the compared methods while maintaining competitive proximity and perceptual similarity, without producing adversarial noise. The distinction between the first valid crossing and the full reflection is also significant: the former isolates the minimal class-flipping perturbation along the mirror direction, whereas the latter shows the endpoint of the geometric reflection procedure.

## 6. Interpretability, scope, and limitations

Mirror-CFE provides interpretability through step-wise transitions \(\{G(\mathbf{z}_k)\}\) generated by varying \(k\) from \(0\) to \(1\) [2509.16822]. These sequences begin at the original image, pass through the decision boundary, and end at the reflected feature, thereby revealing which features evolve as the target-class confidence changes. Reported examples include changes in strokes for MNIST, cell shape for Blood-MNIST, and mouth openness for CelebA-HQ.

The method also supports latent-trajectory analysis by plotting the confidence \(\mathbf{p}_t(F(G(\mathbf{z}_k)))\) and the average pixel difference \(\|\mathbf{x}_k-\mathbf{x}_s\|\) as functions of \(k\). This allows the transition point where the target confidence crosses \(0.5\) to be identified explicitly. For multi-class models, the reflection point can be refined with L-BFGS to ensure a true confidence swap between \(s\) and \(t\), and the resulting \(\mathbf{z}_r\) can be visualized with t-SNE to verify that it lies in the target cluster.

The method’s reported advantages are true faithfulness through reuse of the same \(F\), \(\mathbf{W}\), and \(\mathbf{b}\); animated explanations rather than a single static counterfactual; robustness to adversarial shortcuts, reflected in high denoised validity; and a unified treatment of counterfactual, semi-factual, and factual explanations. Its stated limitations are the dependence on GAP-based architectures for CAM masks and the observation that high-resolution fidelity is governed by skip connections through \(F\), so very high resolution may require richer style priors. Proposed future directions are adaptation to Transformer-based classifiers via learned attention masks, extension of the mirror-based reflection concept to structured-data classifiers, and incorporation of nonlinear “mirrors” through local second-order approximations.

A common misunderstanding would be to treat Mirror-CFE as merely a generator-assisted image-editing method. Its defining property is narrower and more technical: it constructs explanations by reflecting representations in the classifier’s own feature space and by decoding those reflected points back to images under explicit constraints designed to preserve classifier consistency, visual realism, and distance structure. This suggests that its contribution lies as much in explanation geometry as in image synthesis.

Source: https://www.emergentmind.com/topics/mirror-cfe