Source-linked AI summary
CounterFlow: Target-Conditioned Flow Matching for Visual Counterfactuals
Paul Sevellec, Elisa Fromont, Romaric Gaudel, Laurence Roze, Paul Viallard, Laetitia Houeix
TL;DR
Counterfactual explanations seek plausible, close-to-input examples that change a classifier’s prediction. CounterFlow directly learns a target-conditioned transport from a source image in pixel space; on MNIST and CIFAR-10, it achieves state-of-the-art counterfactual validity while remaining competitive in realism and reducing computational requirements.
Problem
Counterfactual explanations seek examples close to an input that change the classifier’s prediction while remaining plausible under the target-class distribution.
Source: §2 · p. 3Method
CounterFlow learns a target-conditioned transport field between image classes in pixel space and generates counterfactuals through a single ODE integration at inference.
Source: §1 · p. 3Results
On MNIST and CIFAR-10, CounterFlow achieves state-of-the-art counterfactual validity while remaining competitive in image realism and substantially reducing computational requirements.
Source: §7 · p. 11Takeaways & Limitations
The authors conclude that a single target-conditioned transport field can provide competitive or superior counterfactual quality with substantially reduced computational complexity compared with prior generative approaches.
Source: §6 · p. 10Experiments are restricted to relatively low-resolution image datasets, leaving scalability on larger-scale and high-resolution benchmarks for further evaluation.
Source: §6 · p. 10
Abstract
from arXiv · showhide
In eXplainable AI, counterfactual explanations have gained significant traction by offering users direct, intuitive, and actionable insights into model decisions. We introduce CounterFlow, a novel framework based on Conditional Flow Matching that generates visual counterfactual explanations by directly steering a source image toward a user-specified target class. By leveraging target-conditioned vector fields, CounterFlow identifies highly realistic semantic modifications while requiring substantially lower computational overhead than traditional GAN- or diffusion-based architectures. Empirical evaluations on standard benchmarks demonstrate that CounterFlow achieves state-of-the-art performance in both visual realism and target class switching. By working directly in the raw pixel space, CounterFlow offers a more practical solution for real-world deployment.
1 Introduction
Counterfactual explanations seek plausible, input-proximate examples that change a model’s prediction, while generative approaches offer a way to make meaningful edits. CounterFlow uses Conditional Flow Matching to transport an input directly toward a user-selected class, avoiding several costs of prior approaches.
1 Introduction
- Counterfactual explanations aim to produce plausible examples close to an input that change the model’s prediction, unlike adversarial examples based on imperceptible noise.The paper frames such explanations as supporting user trust and developer debugging.Source: §1 · p. 1
- Instance-based methods retrieve training examples, while generative approaches use GAN, diffusion, or flow-matching backbones to produce counterfactuals.Instance-based methods require training-set access at inference and cannot tailor a minimal, plausible edit to a specific input.Source: §1 · pp. 1–2
- Diffusion-guidance methods repeatedly apply guidance during denoising, while LeapFactual requires dataset-dependent latent-space leaps, VAE decoding, and classifier queries.FastDiME reduces diffusion’s inner-loop cost but remains slower than a single forward pass; CounterFlow instead directly learns transport from input to counterfactual, avoiding repeated leaps and VAE encoding and decoding.Source: §1 · pp. 2–3
- CounterFlow conditions one CFM vector field on source and target classes to transport examples in pixel space, using one learned ODE integration at inference.Its training also uses latent-space nearest-neighbor pairing and an auxiliary classification loss; the paper reports competitive or improved generation quality at a fraction of GAN- or diffusion-based alternatives’ computational cost.Source: §1 · p. 3
2 Background on Counterfactual Explanations
A counterfactual should be close to the source, receive a specified different class prediction, and remain plausible under the target-class data distribution. The paper treats this as a difficult optimization problem and approximates it with conditional flow matching and CounterFlow.
2 Background on Counterfactual Explanations
- The adopted definition additionally requires the candidate’s target-class density to exceed a threshold ε.This is intended to favor examples that are plausible according to the target-class distribution.Source: §2 · p. 3
- The counterfactual objective seeks an example close to the source that the classifier assigns to a specified different class.The paper notes that closeness and a changed prediction alone can yield an implausible example under the target-class distribution.Source: §2 · p. 3
- The paper approximates this generally non-convex problem with conditional flow matching and introduces CounterFlow to indirectly minimize distance while enforcing the target prediction.The formulation defines X as the input space, Y as the label space, and f as the classifier whose predictions are explained.Source: §2 · pp. 3–4
3 Background on Conditional Flow Matching
Continuous Normalizing Flows transport samples along paths generated by a time-dependent velocity field, while Flow Matching trains that field by supervised regression. Conditional Flow Matching makes the field evaluable under a chosen context, a mechanism CounterFlow uses to control source and target classes.
3 Background on Conditional Flow Matching
- A Continuous Normalizing Flow transports samples from a base distribution toward a target distribution by integrating a time-dependent velocity field.The resulting distributions form a probability path between source and target distributions.Source: §3 · p. 4
- Flow Matching trains the velocity field by regression along predefined trajectories instead of learning transport indirectly through maximum likelihood.The paper notes that maximum-likelihood training can be computationally expensive because it requires ODE solutions, and that the unknown true distribution makes the original FM loss intractable.Source: §3 · p. 4
- In Conditional Flow Matching, a conditioning variable selects the path and target velocity used for each sample.The paper describes the classical conditioning variable as a pair of examples drawn from a coupling distribution.Source: §3 · p. 4
- A context variable is also fed to the learned velocity field, allowing it to be evaluated for a desired context at inference.CounterFlow uses this mechanism to control the source and target classes.Source: §3 · p. 5
4 CounterFlow
CounterFlow learns a velocity field that transports an image from its source class toward a counterfactual target. It uses semantically matched examples and a classification loss during training, then generates counterfactuals by integrating the learned ODE from the input to the target.
4 CounterFlow
- CounterFlow learns a velocity field to generate a counterfactual by approximating the desired transport from source image to target image.Its training loss combines a Conditional Flow Matching loss with a weighted classification loss that encourages the change of class.Source: §4 · p. 5, §4.1 · pp. 5–6
4.1 Defining the loss
- The training context is a source-target label pair, and latent-space nearest-neighbor matching pairs examples from the corresponding classes.The distance uses embeddings from a frozen, pretrained VAE; the combined loss adds a classification objective to the flow-matching objective.Source: §4.1 · pp. 5–6
4.2 Training procedure (Algorithm 2)
- Training samples matched pairs and an interpolation time, computes flow-matching and classification losses, then updates the velocity field.The matched pairs are established using nearest-neighbor matching in the pretrained VAE encoder’s latent space.Source: §4.2 · pp. 6–7
4.3 Inference
- At inference, the user supplies a target class or one is sampled, and a single ODE integration from the input returns the counterfactual.Inference no longer requires pairing, VAE encoding, or minibatch construction.Source: §4.3 · p. 7
5 Experiments
CounterFlow is evaluated on MNIST and CIFAR-10 against recent counterfactual-generation methods using measures of validity, proximity, realism, and computational efficiency. It achieves strong quantitative results, while visualizations show class-relevant edits that preserve source characteristics and reach the target class early along the trajectory.
5.1 Setting
- The evaluation uses MNIST and CIFAR-10, with quantitative inference run using the Euler solver for 40 steps.The datasets comprise 28×28 grayscale digits and 32×32 color images, respectively.Source: §5.1 · p. 7
5.2 Quantitative Results
- On MNIST, CounterFlow reaches 99.6% conditional validity and the lowest target FID, while LeapFactual stays closer to the source but has the highest target FID.C3LT performs worst overall and requires the largest model.Source: §5.2 · p. 9
- On CIFAR-10, CounterFlow is best on all five metrics, with 100% conditional validity and roughly half the inference FLOPs and an order of magnitude fewer parameters.It nearly halves C3LT’s target FID and lowers its source FID by a quarter.Source: §5.2 · p. 9
- CounterFlow achieves state-of-the-art validity and the best realism/proximity trade-off on CIFAR-10 while substantially reducing inference complexity versus prior flow- and diffusion-based approaches.Table 1 reports quantitative results and an ablation comparing latent-space nearest-neighbor pairing with random pairing.Source: Table 1 · p. 9, §5.2 · p. 10
- Replacing latent-space pairing with random pairing lowers conditional validity and raises both target and source FID on both datasets.The passage attributes this to visually unrelated pairs producing harder-to-learn trajectories.Source: §5.2 · p. 10
5.3 Qualitative Results
- Visual examples show MNIST writer style and CIFAR-10 scene backgrounds preserved while class-relevant digit or foreground-object structure changes.Trajectory visualizations show the classifier prediction flipping early in most examples, with remaining steps refining the sample within the target class.Source: Figure 2 · p. 9, §5.3 · p. 10
6 Discussion
CounterFlow targets the computational cost of image counterfactual generation with a single target-conditioned transport field and one ODE integration at inference. The authors report strong quality with reduced complexity, but note that evaluation is limited to low-resolution datasets and inference remains more expensive than a single feed-forward network.
6 Discussion
- A single target-conditioned transport field and one ODE integration provide a simpler alternative to heavy generative backbones for counterfactual generation.The authors frame this as a step toward practical interactive decision-support systems requiring quick, consistent explanations.Source: §6 · p. 10
- Evaluation is restricted to relatively low-resolution datasets, and nearest-neighbor pairing requires pretrained-encoder preprocessing while ODE solving costs more than one feed-forward pass.The authors identify larger-scale benchmarks as needed to provide further evidence of scalability.Source: §6 · p. 10
7 Conclusion
CounterFlow achieves state-of-the-art counterfactual validity on MNIST and CIFAR-10 while remaining competitive in image realism and reducing computational requirements. The conclusion points to larger datasets and other transformation tasks as future directions.
7 Conclusion
- CounterFlow achieves state-of-the-art counterfactual validity on MNIST and CIFAR-10 while remaining competitive in image realism and substantially reducing computational requirements.Source: §7 · p. 11
- Future work will investigate larger-scale datasets and applications including domain adaptation, semantic image editing, and robust model analysis.Source: §7 · p. 11
AI use statement
- The authors used LLM-based coding assistants to implement and debug parts of the experimental code and polish prose, but not to generate ideas, design the method, or interpret results.Source: AI use statement · p. 11
Ethics statement
- Experiments use standard MNIST and CIFAR-10 benchmarks without personal or sensitive data; the authors acknowledge potential misuse to create misleading real-person edits.Source: Ethics statement · p. 11
Reproducibility statement
- The authors report using publicly available datasets and pretrained classifiers, and plan to release code needed to reproduce the experiments upon publication.Source: Reproducibility statement · p. 11
A.1 Implementation Details
The appendix identifies the training configuration for MNIST and CIFAR-10 and reports shared optimizer, weight-averaging, and warmup choices.
A.1 Implementation Details
- Both models use the Adam optimizer and an exponential moving average of the weights.Source: §A.1 · p. 13
- Both models use linear warmup schedules for the learning rate and classifier-guidance loss weight λ.Source: §A.1 · p. 13
- Table 2 lists training hyperparameters for MNIST and CIFAR-10.Source: Table 2 · p. 13
A.2 Radar plots
Figure 3 compares five metrics across methods separately for each dataset, with normalized axes that make the outer edge the best value.
A.2 Radar plots
- Each dataset’s five metric axes are min-max normalized so the outer edge marks the best value, whether the original metric is higher- or lower-is-better.Source: Figure 3 · p. 14
- CounterFlow reaches the outer edge on every metric axis for CIFAR-10.Source: Figure 3 · p. 14
- On MNIST, CounterFlow is competitive or best on most axes, while baselines tend to excel on one axis at others’ expense.Source: Figure 3 · p. 14
A.3 Ablation studies on CIFAR-10
The CIFAR-10 ablations examine the classification-loss weight, target-pair conditioning, and explained classifier, while the dataset discussion explains why comparisons are limited to MNIST and CIFAR-10 and why scaling CounterFlow to ImageNet remains future work. Additional figures show CounterFlow trajectories on MNIST and CIFAR-10.
A.3 Ablation studies on CIFAR-10
- For λ values from 0.1 to 0.5, conditional validity reaches 100%, while FIDt rises from 62.38 to 74.01 and FIDs from 118.23 to 121.82.Removing classification loss yields 68.9% validity; using classification loss alone collapses, with FID scores above 400 and 48.9% validity. The authors select λ = 0.1; daggered runs can mix successful and failed counterfactuals, so their FIDs are not quality signals.Source: §A.3 · p. 14, Table 3 · p. 15
- Removing source-target context reduces conditional validity from 100% to 8.6%, as the velocity field fits an average displacement rather than the requested transition.The authors interpret the lower source FID of 83.24 as reflecting images that barely leave their source class.Source: Table 4 · p. 15, §A.3 · p. 15
- With the robust PreActResNet-18, validity falls to 83.5% and FIDt reaches 55.72; the mis-specified classifier retains 100% validity with FIDs within two points of default.The mis-specified classifier is the RepVGG-A2 evaluated without input normalization; its accuracy falls to 86.3%.Source: Table 5 · p. 15, §A.3 · p. 15
A.4 Choice of datasets
- Comparisons use MNIST and CIFAR-10 because these are the largest settings where all methods run with official implementations, the same classifier, and the same evaluation protocol.ImageNet comparisons face baseline and evaluation constraints: C3LT uses five qualitative class pairs with GAN-sampled latent codes, LeapFactual’s large-scale experiment is binary on GAN-generated images, and classwise FID estimates are unreliable with 50 validation images per class.Source: §A.4 · p. 16
- CounterFlow’s ImageNet-scale study is deferred because training its pixel-space model from scratch exceeds the computational budget and source-target contexts grow quadratically with class count.The authors note that each context would consequently be seen less often during training.Source: §A.4 · p. 16
A.5 Additional Results
- The additional MNIST and CIFAR-10 figures show source-to-target trajectories, with border colors marking source-class, target-class, or other classifier predictions.Red marks source, green target, and orange any other predicted class.Source: Figure 4 · p. 17, Figure 5 · p. 18