arXiv:2610.35679cs.LGOct 2026

Manuscript Offprint

arXiv:2610.35679

CounterFlow: Target-Conditioned Flow Matching for Visual Counterfactuals

Paul Sevellec, Elisa Fromont, Romaric Gaudel, Laurence Roze, Paul Viallard, Laetitia Houeix

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

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

Context. On the one hand, in generative modeling, diffusion models currently dominate the landscape for high-quality image, video, and audio synthesis (Rombach et al., 2022; Ho et al., 2022; Liu et al., 2023a). However, they are also well-known for their slow training times and their stochastic sampling paths. To address these limitations, Lipman et al. (2023); Albergo and Vanden-Eijnden (2023); Liu et al. (2023b) introduced Conditional Flow Matching (CFM). CFM is a generative modeling framework based on Continuous Normalizing Flows (CNFs) that uses standard regression objectives for training. Moreover, instead of relying on diffusion processes, CFM generates examples by integrating the CNF's ODE along deterministic trajectories. On the other hand, the generative models' ability to generate complex data distributions and thus to produce realistic examples is particularly appealing for eXplainable Artificial Intelligence (XAI, Dwivedi et al., 2023), where one aims to produce counterfactual explanations (Wachter et al., 2017), i.e., examples (i) close to a given input, (ii) plausible, and (iii) that change the model's prediction. Unlike adversarial examples that rely on imperceptible noise to fool the classifier, counterfactual examples expose meaningful changes, helping users to trust the model while enabling developers to debug it. Our work leverages CFM to create counterfactual explanations: rather than generating images from random noise, our approach transports an input sample toward a counterfactual conditioned on a user-defined target class, while jointly optimizing for plausibility and proximity; see Figure 1.

Related Work. Prior work on image counterfactual explanations falls into two categories: instance-based and generative approaches. Instance-based methods (see e.g., Goyal et al., 2019; Keane and Smyth, 2020) select examples from the training set using similarity metrics to modify the input sample.

∗^{*}Corresponding Author. Email: prenom.nom@inria.fr

Figure

(a) MNIST

dog→bird

horse→truck

dog→horse

bird→deer

airplane→auto

Figure

(b) CIFAR10

Figure 1: Qualitative counterfactual explanations generated by CounterFlow on (a) MNIST and (b) CIFAR10. We show five examples per dataset as source/counterfactual pairs (source on the left of each pair, the corresponding counterfactual generated by CounterFlow on the right), and we indicate the source→target class transition above each pair. CounterFlow preserves source-specific style, such as stroke thickness and digit slant on MNIST, or object color and orientation on CIFAR10, modifying only what is needed to reach the target class.

x. However, they require access to the training set at inference and cannot tailor a minimal, plausible edit to a specific example x. We focus instead on generative approaches, a more recent line of work (Khorram and Fuxin, 2022; Jeanneret et al., 2024; Weng et al., 2024; Augustin et al., 2022; Cao et al., 2025) that produces more plausible examples, which we group by generative backbone: GANs, diffusion models, or CFM.

• GAN. C3LT (Khorram and Fuxin, 2022) encodes the input (with a VAE encoder) into a latent space, in which it learns two cycle-consistent transformations per pair of classes (y,y′)(y, y') before decoding with the generator of a GAN. It thus requires one model set per pair, impractical for many classes, and its fidelity is bounded by the VAE's reconstruction quality.

• Diffusion. DiME (Jeanneret et al., 2024) generates a counterfactual by corrupting the input and denoising it through the backward diffusion process (an inner loop of several steps); at each outer step, the classifier gradient computed on this denoised estimate refines the corrupted instance, and the process repeats until it converges to a valid counterfactual. FastDiME (Weng et al., 2024) instead computes this gradient directly from the model's one-step denoised estimate, bypassing the inner loop entirely. ACE (Jeanneret et al., 2023) takes a different route: it builds an adversarial attack against the classifier and lets the diffusion model's own denoising process project this attack back onto the manifold of realistic images, turning an imperceptible perturbation into a semantically meaningful one. DVCE (Augustin et al., 2022) starts the reverse diffusion from a partially noised version of the input, rather than pure noise, and steers the process by projecting the gradient of an adversarially robust classifier onto a cone around the target classifier's own gradient direction whenever the two disagree, avoiding non-semantic changes. More recently, MaskDiME (Guo et al., 2026) improves on DiME's efficiency and spatial precision with a training-free, adaptive dual-mask mechanism guided by classifier gradients that restricts updates to a localized region rather than the whole image. Regardless of the specific guidance scheme, diffusion-guidance methods must reapply their guidance at every one of many denoising steps, making inference slow: DiME's inner diffusion loop scales quadratically with the number of diffusion steps, and even FastDiME's one-step approximation, despite yielding a roughly 20×20\times empirical speedup, only reduces this to a linear scaling and remains markedly slower than a single forward pass. ACE and DVCE compound this same per-step cost further, respectively adding an adversarial attack and a robust-classifier gradient computation at every step.

• CFM. LeapFactual (Cao et al., 2025) builds on Conditional Flow Matching (CFM) to generate counterfactuals. It learns a class-conditional generative flow from a Gaussian prior to the latent space of a pretrained VAE, and repurposes this flow for counterfactual generation through a lift-and-land procedure. Given an input, its VAE encoding is first lifted toward the prior under the input class by solving the learned ODE backward, and then landed back into the latent space under the target class by solving the ODE forward. This “leap” must be repeated a dataset-dependent number of times, with each leap requiring a VAE decoding and a classifier query.

Our work also builds on CFM, but uses it in a fundamentally different way. We directly learn a transport from an input image to its counterfactual. This avoids (i) the need for multiple costly leaps, (ii) the intermediate traversal through a prior space, and (iii) VAE encoding and decoding, whose reconstruction fidelity can limit the quality of the generated counterfactuals.

Our contributions. To address the drawbacks of the previous methods, our contributions are as follows:

• We introduce CounterFlow, the first CFM framework that directly conditions the vector field on both the source and target class, enabling a single model to transport examples between any pair of classes in their original pixel representation. Moreover, CounterFlow generates a counterfactual by integrating a single (learned) ODE from source to target, with no additional VAE decoding or iterative optimization at inference.

• To enable the learning of the transport map, we introduce two complementary contributions: a latent-space nearest-neighbor pairing strategy and an auxiliary classification loss. The pairing algorithm leverages the embedding space of a pretrained VAE to associate each source example with a semantically similar target example, thereby reducing the transport distance that the flow must learn. The auxiliary classification loss further guides the flow toward transformations that induce the desired change in the classifier's prediction.

• We provide an empirical evaluation covering conditional validity, plausibility, and computational efficiency, a combination rarely reported together in prior work, demonstrating that CounterFlow matches or improves on state-of-the-art generation quality at a fraction of the computational cost of GAN- or diffusion-based alternatives.

References (25)