Dynamic Residual Encoding with Slide-Level Contrastive Learning for End-to-End Whole Slide Image Representation

Jing Jin, Xu Liu, Te Gao, Zhihong Shi, Yixiong Liang, Ruiqing Zheng, Hulin Kuang, Min Zeng, Shichao KanarXiv 2025 · DOI

TL;DR

This paper introduces DRE-SLCL, a novel end-to-end framework for Whole Slide Image (WSI) representation that overcomes GPU memory bottlenecks by combining dynamic tile sampling with a persistent feature memory bank. By aggregating features via residual encoding (VLAD) and aligning them with pathology reports using slide-level contrastive learning, the model achieves state-of-the-art performance in computational pathology tasks with a fraction of the parameters of massive foundation models.

What Problem Does This Paper Address?

In computational pathology, Whole Slide Images (WSIs) are gigapixel-sized digital slides containing tens of thousands of individual image tiles. Because of current GPU memory limitations, it is impossible to load an entire WSI into memory to compute gradients and train a deep learning model end-to-end.

To circumvent this, standard practices rely on a two-stage approach: first, a frozen, self-supervised tile encoder extracts features from all patches; second, an aggregator combines these features to make a slide-level prediction.

Figure 1: WSI representation learning. (a) The pipeline of the two-stage learning methods and (b) the proposed end-to-end learning method.

The major drawback here is that the tile encoder never learns from the final slide-level labels (like cancer subtype or genetic mutations), leading to suboptimal feature representations. The authors tackle this gap by engineering a way to train the entire pipeline end-to-end without blowing up the GPU.

Methods

The proposed framework, Dynamic Residual Encoding with Slide-Level Contrastive Learning (DRE-SLCL), introduces three key components to enable end-to-end training:

  1. Dynamic Tile Sampling & Memory Bank: The authors maintain a two-level nested dictionary (stored in CPU memory) that holds the features of all tiles across the dataset. During a training iteration, the model randomly samples a tiny subset of tiles (e.g., just 10 tiles) from a WSI to pass through the active image encoder (a ViT-256 pretrained on HIPT), computing fresh gradients. The remaining thousands of tile features for that slide are quickly retrieved from the memory bank.
  2. Dynamic Residual Encoding (VLAD): Instead of simple attention pooling, the model aggregates the mixed features (newly computed + memory bank retrieved) using Vector of Locally Aggregated Descriptors (VLAD). Tile features are mapped to their nearest cluster centers (codewords) from a pre-computed codebook, and their accumulated residuals (deviations from the cluster centers) form the global slide representation.
  3. Slide-Level Contrastive Learning: To improve generalization, the visual slide representation is aligned with the semantic representation of its corresponding text pathology report. The text reports are encoded using a frozen LLaMA2-7B model, and a CLIP-style cross-entropy loss forces matching slide-report pairs closer together in the latent space.
Figure 2: The end-to-end whole slide image representation framework with the proposed dynamic residual encoding with slide-level contrastive learning (DRE-SLCL).

To stabilize training, the authors use a two-stage unfreezing strategy: they first freeze the image encoder to train the classifier, and then gradually unfreeze the encoder parameters for joint fine-tuning.

Datasets

The model was evaluated on two prominent, publicly available cancer datasets:

  • The Cancer Genome Atlas (TCGA): Specifically the LUAD (Lung Adenocarcinoma) and LUSC (Lung Squamous Cell Carcinoma) cohorts.
  • Clinical Proteomic Tumor Analysis Consortium (CPTAC): Including LUAD, LSCC (Lung Squamous Cell Carcinoma), CCRCC (Clear Cell Renal Cell Carcinoma), and PDA (Pancreatic Ductal Adenocarcinoma).

Tasks included binary cancer recognition, cancer subtyping, and the prediction of four major gene mutations (TP53, FAT1, LPRB1, EGFR).

Key Insights and Ideas

  • The Power of Synergy: Ablation studies revealed that the performance leap doesn't just come from adding contrastive text loss, but from the combination of end-to-end dynamic residual encoding and cross-modal alignment.
  • Extreme Parameter Efficiency: While recent pathology foundation models like Prov-GigaPath scale up to 1.1 billion parameters, DRE-SLCL achieves superior or competitive results with under 27 million parameters. This makes it highly viable for resource-constrained clinical environments.
  • Sampling as Augmentation: Randomly sampling a small subset of tiles in each epoch acts as an effective data augmentation strategy, forcing the model to learn robust global representations from diverse tile combinations.

Key Results

DRE-SLCL consistently outperformed mainstream weakly supervised and multiple instance learning (MIL) methods (such as CLAM and TransMIL) across all tasks:

  • Cancer Subtyping: On the CPTAC_lung dataset, the model achieved an F1-score of 76.43%, outperforming the best competing baseline by roughly 4.83%.
  • Cancer Recognition: Achieved near-perfect AUCs on TCGA datasets (99.26% for LUAD, 99.58% for LUSC) and significantly boosted the challenging CPTAC_PDA dataset to 92.34% AUC.
  • Gene Mutation Prediction: For the difficult task of predicting TP53 mutations, DRE-SLCL achieved an AUC of 71.33% and an F1-score of 82.76%, showing strong robustness against data imbalance.
Figure 3: Ablation results for TP53 gene mutation prediction.

Limitations and Future Work

A primary limitation is that the slide-level contrastive learning component relies heavily on the availability of high-quality pathology reports; the contrastive loss can only be applied to slides that have them. Additionally, while the model is highly efficient, the authors note that future work needs to focus on improving the interpretability of the model—a critical requirement for clinical deployment so pathologists can verify which visual features triggered a specific model prediction.

Summary updated

BibTeX
@misc{jin2025dynamic,
  author = {Jing Jin and Xu Liu and Te Gao and Zhihong Shi and Yixiong Liang and Ruiqing Zheng and Hulin Kuang and Min Zeng and Shichao Kan},
  title = {{Dynamic Residual Encoding with Slide-Level Contrastive Learning for End-to-End Whole Slide Image Representation}},
  year = {2025},
  eprint = {2511.05034},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.05034},
}
Figure