arXiv:2610.22437cs.LGOct 2026

Manuscript Offprint

arXiv:2610.22437

CF-NODE: Counterfactual Spatial Node Intervention for Test-Time Adaptation Under Domain Shift, Evaluated Across Five Diabetic Retinopathy Datasets

Sabarish G, Deepak Parashar

Sabarish G and Deepak Parashar, Senior Member, IEEE

Abstract—Automated fundus-based diabetic retinopathy (DR) grading can substantially expand screening capacity, but source-trained models degrade sharply across different cameras, clinics, and patient populations. Existing test-time adaptation methods depend on entropy minimization or target information accumulated from image batches and streams. These mechanisms can reinforce confidently incorrect predictions and break down when clinical images arrive independently. We introduce CF-NODE, a novel counterfactual test-time adaptation framework for cross-domain DR grading. Instead of trusting prediction confidence or estimating a target distribution, CF-NODE asks how each prediction responds under a controlled intervention on the evidence supporting it. CF-NODE ranks internal spatial nodes using model-derived attention, feature magnitude, and node-set similarity, progressively attenuates the highest-ranked nodes, and uses the stability of the resulting expected-grade response to apply a bounded calibration of the predicted grade distribution. The framework is fully frozen and adapts every image independently using only geometric views and a fixed source-derived prior, requiring no target-derived information or model updates. We evaluate CF-NODE on five external DR datasets under repeated-seed evaluation against TENT, EATA, SAR, and T3A. CF-NODE outperforms all four methods with statistically significant improvements over the second-best method, improves AUC on every target domain, and attains the highest average AUC and macro-F1, delivering stronger grade discrimination together with more balanced recognition across DR severity levels. These results demonstrate that counterfactual intervention sensitivity provides consistent and deployment-ready domain robustness for single-image clinical inference. Code is available at https://github.com/sabarishknight/CF-Node.

Index Terms— Diabetic Retinopathy Grading, Test-time Adaptation, Domain Generalization, Counterfactual Intervention, Retinal Fundus Imaging.

I. INTRODUCTION

DIABETIC Retinopathy (DR) is one of the major causes of preventable vision loss, and accurate grading of retinal fundus images is important for timely referral and treatment [1], [2]. Deep neural networks have achieved strong performance in automated DR screening and severity grading [3], [4], [5]. However, their reliability often deteriorates when they are applied outside the training domain. Differences in retinal cameras, illumination, field of view, acquisition protocols, image quality, and patient populations can alter the appearance of fundus images and lead to confident but incorrect grades [6], [7]. This limits the safe use of a model across clinics and screening programs, even when it performs well on its original test set.

Clinical deployment also creates a difficult inference setting. Fundus images may arrive individually, on demand, and from different cameras or clinical sites. A model may not have access to a homogeneous batch of target images, and it may be unrealistic to assume that consecutive patients belong to the same target distribution. Entropy-based TTA methods [8], [9], [10] can also be risky in this setting. Low entropy indicates confidence rather than correctness, so entropy minimization may reinforce a confident but incorrect grade under domain shift. We therefore consider the following problem: how can a source-trained DR grader improve its prediction for one unlabeled image from an unseen domain without entropy minimization, parameter updates, target labels, target-domain statistics, a target batch, or an adaptation stream?

Test-time adaptation (TTA) attempts to improve model performance using unlabeled images observed during inference. A common approach is entropy minimization. TENT adapts batch-normalization parameters by reducing prediction entropy [8], while EATA combines reliable-sample filtering with anti-forgetting regularization, whereas SAR uses reliable-sample filtering and sharpness-aware updates [9], [10]. These methods can be effective, but entropy is not a direct measure of prediction correctness. A shifted model may assign high confidence to an incorrect grade and therefore produce low entropy. In this case, entropy provides little warning that correction is needed and minimizing it can make the incorrect prediction even more confident [11]. Online parameter updates may also allow an unreliable image or an unstable target batch to influence predictions for later patients.

Another group of TTA methods uses target features, class supports, prototypes, memory banks, or estimated target statistics. T3A updates class supports using incoming target features [12], while FunOTTA maintains a target-feature memory bank and uses prototype-based adaptation for fundus images [11]. Such methods can benefit from repeated observations from a stable target domain. However, their behavior can depend on pseudo-label quality, batch composition, stream order, and previously observed images [11], [12]. These assumptions may not hold when clinical images arrive independently or originate from different devices and sites. Estimating a target-class distribution or target feature structure from a single image is also unreliable. These constraints motivate a single-image method that does not rely on target-derived statistics or adaptation state carried across patients.

We introduce Counterfactual Spatial Node Intervention (CF-NODE), a frozen-model approach that obtains an adaptation signal directly from the current image. Instead of updating model parameters from entropy or estimating a target distribution, CF-NODE asks a different question: how does the predicted DR grade change when the spatial representation selected by the model is deliberately weakened? The final convolutional feature map is represented as a set of spatial nodes. CF-NODE ranks these nodes using learned attention, feature magnitude, and similarity to the complete node set, then progressively attenuates the highest-ranked nodes across four intervention levels. The magnitude and consistency of the expected-grade decrease across intervention levels define a per-image counterfactual sensitivity score. This score measures dependence within the trained model.

CF-NODE uses intervention sensitivity to control bounded, image-specific probability calibration. A small intervention response keeps the calibrated distribution close to the source prediction, while a stronger and more stable response produces a larger but bounded change in its concentration. Geometric views of the same image are then aggregated, and a fixed source-derived class prior is applied without estimating statistics from the target dataset. The complete model remains frozen, and each image is processed independently without target labels, target batches, gradients, optimization, or information from previous patients. This avoids cross-patient state and prevents an unreliable test image from changing the model used for subsequent cases.

The key distinction from existing TTA methods is the source of the adaptation signal. Entropy-based methods adapt from prediction confidence, while prototype and memory methods adapt from accumulated target features. CF-NODE instead creates a controlled intervention inside the spatial representation and uses the measured response to control the strength of bounded probability calibration. The main contributions are:

  • We introduce CF-NODE, a novel counterfactual test-time adaptation method for cross-domain DR grading. It refines each image-specific prediction through interventions on ranked internal spatial nodes.

  • We develop a model-guided framework that first ranks internal spatial nodes using attention, feature magnitude, and global node-set similarity, then applies graded counterfactual interventions to the highest-ranked nodes and converts the stability-normalized expected-grade response into a bounded probability correction.

  • CF-NODE enables fully frozen, independent-image deployment. Each prediction uses only the frozen source model, geometric views of the current image, and a fixed source-derived prior, requiring no target labels, cross-image target batches or statistics, memory banks, pseudo-labels, gradients, model updates, or persistent adaptation state.

  • Across five external DR datasets, CF-NODE improves AUC on every target and achieves the highest mean AUC and macro-F1 among the evaluated methods. Relative to source-only inference, it gains 2.1 and 6.2 percentage points on average, demonstrating stronger grade discrimination and class-balanced recognition under domain shift.

References (33)