StainNFT: Curriculum-Gated Multi-Reward Post-Training for Pathology-Faithful Virtual Staining

Shurong Yang, Dong Wei, Qiong Peng, Xian Wu, Yefeng Zheng, Liansheng WangNeurIPS 2026

TL;DR

Digitally translating standard biopsy slides into specialized diagnostic stains could save hospitals immense time and money, yet today's generative AI models often look plausible while getting the underlying biology dangerously wrong. StainNFT uses reinforcement learning (RL) to teach a flow-matching model where to place disease-indicating proteins before teaching it how much to place. By mimicking a real pathologist's workflow, it prevents classic RL "reward hacking" and sets a new bar for diagnostic accuracy in virtual staining.

What Problem Does This Paper Address?

In pathology, standard H&E stains reveal basic tissue structure in pinks and purples, while costly, slow IHC stains use antibodies—often marked by a brown dye called DAB—to light up specific proteins (like HER2 in breast cancer). Virtual staining uses AI to digitally translate H&E images directly into IHC images.

While diffusion and flow-matching models generate sharper images than older GANs, training them via standard supervised fine-tuning (SFT) hits a wall. Because SFT averages error across the whole image at single noisy timesteps, sparse brown DAB-positive cancer cells get drowned out by the massive background. Run the same SFT model four times with different random seeds, and the cancer signal flickers wildly in and out of existence.

Figure 1: Inter-rollout instability of the SFT model across four independent inference runs (SFT R1–R4) with different random initial noise. Repeated rollouts of the same SFT model yield unstable DAB channels, exhibiting incorrect pathological signals. Top: a case from RegH2I [63]. bottom: a case from MIST-HER2 [42]; This inter-rollout variance is precisely the signal that reinforcement learning can exploit to impose pathological constraints at the outcome level.

Reinforcement learning can fix this by judging completed images at the outcome level. However, naively rewarding a model for matching total brown dye concentration (optical density, or OD) triggers severe reward hacking: the AI arbitrarily scatters brown pixels like confetti just to hit the target sum, ruining image realism.

Reward hacking when optimizing stain quantity without spatial localization, compared to StainNFT and ground truth IHC.

Methods

StainNFT is a two-stage framework built on a SANA-0.6B flow-matching backbone. First, an SFT stage trains the base model on paired $1024 \times 1024$ patches, injecting fine-grained visual features alongside high-level tissue semantics from UNI2 (a pathology foundation model). Next, an RL post-training stage uses DiffusionNFT (an online RL method operating directly on the forward diffusion process via LoRA) to evaluate $K=8$ rollouts per input using three novel reward designs:

Overview of the StainNFT architecture and RL post-training loop.
  • Curriculum-Gated Reward: Pathologists locate positive regions before quantifying intensity; StainNFT does too. It optimizes a spatial mask overlap reward (IoU) and uses a dynamic sigmoid gate to keep quantitative optical density (OD) rewards turned off until a sample's mean IoU crosses the training median.
  • Expression-Aware Multi-Scale OD Reward: Once unlocked, stain intensity is checked across $4\times4$, $8\times8$, and $16\times16$ spatial grids—capturing global layout down to cell clusters—while reweighting blocks by ground-truth intensity so sparse positive regions aren't diluted by background.
  • Closed-Loop UNI2 Semantic Reward: Because DAB rewards only measure brown dye and ignore cellular morphology, a cosine-similarity reward in UNI2's feature space ensures overall histological structure stays coherent.

Datasets

No new datasets are introduced; the authors evaluate on seven existing paired H&E–IHC benchmarks at $1024 \times 1024$ resolution:

  • RegH2I (HER2 biomarker, 4B5 antibody) and RegH2I-Ext (an external out-of-distribution test set stained with different HER2 antibodies, SP3 and CB11, to test zero-shot generalization).
  • MIST (four subsets covering HER2, ER, and two additional biomarkers), BCI, and HER2Match.

Key Insights and Ideas

  • Generation instability is fuel for RL: The frustrating seed-to-seed variance of SFT models isn't just a bug—it provides the exact exploration variance RL needs to rank good diagnostic outcomes over bad ones.
  • Order of operations defeats reward hacking: Even heavy KL-divergence penalties cannot stop an RL model from scattering fake brown pixels if you ask for quantity too early. Gating quantity behind spatial location (IoU) naturally blocks the scatter-and-match shortcut, because stray pixels actively hurt the IoU score.
  • Closing the foundation model loop: Conditioning an SFT generator on foundation model features isn't enough; explicitly rewarding output similarity in that same feature space during RL preserves delicate tissue architecture.

Key Results

StainNFT outperforms 11 GAN, diffusion, and flow-matching baselines across nearly every metric on all seven benchmarks:

  • Image & Pathological Fidelity: On RegH2I, StainNFT drops FID to 30.76 (vs. 33.92 for the next best baseline) and slashes integrated optical density error ($\text{|IOD|}_{\times 10^6}$) to 0.1057—more than $3.7\times$ lower than the runner-up Pix2pixHD (0.3971) and $2.5\times$ better than its own SFT baseline (0.2645).
  • Clinical Downstream Utility: When training a ResNet-50 classifier on virtually stained images to grade real breast cancer slides (4-level HER2 scoring), StainNFT reaches 81.76% accuracy and 0.8154 F1, nearly matching a classifier trained on real chemical IHC slides (84.56% accuracy, 0.8160 F1).
  • Zero-Overhead Deployment: Because RL updates a mergeable LoRA adapter, inference takes just 1.26 seconds per $1024 \times 1024$ patch (20 steps)—faster than all multi-step diffusion baselines.

Limitations and Future Work

  • Paired Data Dependency: Both SFT and RL require pixel-aligned H&E–IHC pairs, which are expensive and tricky to prepare at scale. Extending this paradigm to unpaired or weakly paired slides is a key next step.
  • Multi-Step Sampling Latency: Though fast for a diffusion/flow model (1.26s), 20-step ODE integration still trails single-step models like pix2pix-Turbo. The authors plan to explore consistency distillation and few-step scheduling to speed up clinical deployment.

Summary updated

Abstract

Immunohistochemical (IHC) staining encodes molecular protein expression critical for clinical diagnosis, yet its chemical procedures are costly and time-consuming. Virtual staining offers a compelling alternative by digitally synthesizing IHC images from hematoxylin-eosin (H\&E) stained slides. Despite remarkable progress in diffusion- and flow-matching-based virtual staining, supervised fine-tuning (SFT) remains fundamentally limited in pathological fidelity due to its coarse, spatially averaged supervision signal that starves sparse DAB-positive regions of effective gradients. Reinforcement learning (RL) can exploit inter-rollout variance for outcome-level pathological supervision, but naively applying DAB-based rewards triggers severe reward hacking that collapses the image distribution and degrades perceptual quality. This paper presents StainNFT, a flow matching RL post-training framework built on a curriculum reward strategy that gates fine-grained optical density supervision on per-sample DAB mask IoU. To enhance fine-grained pathological fidelity, we introduce expression-aware reweighting, multi-scale block supervision, and a closed-loop implicit pathological semantic reward derived from pathology foundation model priors. Extensive experiments on seven benchmarks demonstrate that StainNFT consistently outperforms existing methods in both perceptual quality and pathological fidelity for H\&E-to-IHC virtual staining. Ablation studies confirm the effectiveness of each proposed component. Our code and trained models will be released.
BibTeX
@inproceedings{yang2026stainnft,
  author = {Shurong Yang and Dong Wei and Qiong Peng and Xian Wu and Yefeng Zheng and Liansheng Wang},
  title = {{StainNFT: Curriculum-Gated Multi-Reward Post-Training for Pathology-Faithful Virtual Staining}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=8Ci5Hrd4ph},
}
Figure