Aug 7, 2026
MUHAMMAD GHIFARY, VANYA VALINDRIA
Many image generation tasks sound causal before they are formalized. What would a chest radiograph look like if an abnormality were absent? What would this face look like under different lighting? What would this handwritten digit look like if it were thinner, while still preserving the writer’s style?
An ordinary conditional generator can create a plausible image with a requested attribute. That’s useful, but it doesn’t answer the individual-level question behind explanation, simulation, and intervention: what would have happened to this observed sample if one cause had been different? Suppose an image has thickness 3.6 and intensity 245. Drawing a digit with thickness 2.1 is not the same as asking:
What would this same handwritten digit have looked like if its thickness had been 2.1?
This “same” carries most of the difficulty. A useful answer should preserve the observation-specific factors that the intervention does not cause, e.g., writing style, pose, fine image detail, and other latent variation, while changing the target variable and only its causal descendants. A model that changes everything is an editor or a model that preserves the wrong things is not a causal explanation either.
Consider a clinical decision-support system reviewing a chest radiograph for pneumonia. Asking for an image that merely looks less like pneumonia may also alter the patient’s anatomy, image positioning, or acquisition conditions, making it impossible to tell what visual evidence drove the prediction. A meaningful counterfactual instead asks: “What would this same patient’s radiograph look like if the pneumonia-related finding were absent?” That question requires a causal intervention on the finding while preserving the patient-specific anatomy and unrelated imaging factors.
This is why causal and counterfactual modeling is relevant. It makes the assumptions behind a “what if” image explicit: which factors are causes, which variation belongs to the observed individual, and which change is being contemplated. That does not guarantee a correct answer — the causal graph and mechanisms must still be justified — but it gives the questions a meaning that ordinary conditional generation lacks.
In this article, we take a close look at an image counterfactual method of (Ribeiro et al. 2023) — they also share the code implementation here: https://github.com/biomedia-mira/causal-gen
We port the code to be a pure JAX/Flax implementation with not merely a translation of APIs, but also creating a cleaner path to efficient execution on TPU hardware: https://github.com/ghif/causal-genx/
To appreciate causal inference, one should understand the difference between observation (”seeing”) and intervention (”doing”). Observation means watching the world naturally unfold and collecting data without changing anything. When we observe, we might ask:
Given that I just noticed event $A$ happening, how likely is it that event $B$ is also happening?
This type of question is typically answered formally through probabilistic models, through a conditional distribution $P(B | A)$.
Let us use the rooster (A) and sunrise (B) analogy. Imagine a rooster that crows every morning right before the sun rises. For every single day for 10 years, we write down two things:
We can statistically conclude 100% correlation: $P(B = \texttt{Sunrise} | A =\texttt{Rooster crow}) = 1.0$. If we stay purely in the world of observation, the data tells us that the rooster crowing and the sunrise are tightly linked. But, does the rooster cause the sun to rise?
Intervention means stepping into the world, breaking the natural routine, and forcing a variable to take a specific value regardless of what normally happens. When we intervene, we are asking
If I actively step in and force $A$ to happen, what will happen to $B$?