Manuscript Offprint

arXiv:2610.33340

Compression of Vision Foundation Models for Retinal OCT via Growing-Neural-Gas Codebooks and Graph-Guided Masked Image Modeling

Ali Yavari, Tilman Schmoll, Rainer A. Leitgeb, Wolfgang Drexler, Thomas Schlegl

Abstract

Vision foundation models for retinal imaging are large and computationally demanding, limiting point-of-care deployment. We ask how much of such a model's downstream utility survives compression into a smaller network. We propose a topology-aware discretization framework that distills a continuous foundation model into a discrete codebook, then uses it as the reconstruction target for masked image modeling (MIM). It combines gradient-free codebook learning via Growing Neural Gas, which yields an adjacency graph over the codes, with a graph-distance soft cross-entropy loss that replaces one-hot MIM targets with topologically graded supervision. With student pretraining on 383 public Duke iAMD optical coherence tomography (OCT) volumes, the pipeline distills an 86M-parameter teacher into a 22M-parameter student with ≥3.6×\geq3.6\times fewer FLOPs. The student performs close to, and in some settings above, its teacher across three classification and two segmentation benchmarks, with the magnitude and direction of the difference depending on the teacher, task, metric, and student capacity. On the external OLIVES benchmark, it surpasses its MIRAGE teacher on every metric (98.06% vs. 95.22% balanced accuracy). It works with two Vision Transformer (ViT-Base) teachers, retinal (MIRAGE) and natural-image (DINOv3); with the out-of-domain teacher, the student outperforms it on retinal-layer segmentation, indicating that the added value of retina-specific pretraining is task-dependent: largest for segmentation, while a general-domain teacher is competitive for classification. These results yield compact retinal models potentially suitable for deployment, transferring across OCT datasets, devices, and clinical tasks, including three datasets not used in the student's pretraining.

Keywords: Optical coherence tomography, Masked image modeling, Knowledge distillation, Topological codebook learning

*Corresponding author.

Email address: ali.yavari@meduniwien.ac.at (Ali Yavari)

1. Introduction

Retinal diseases including age-related macular degeneration (AMD), diabetic macular edema (DME), and choroidal neovascularization (CNV) impose a major and growing clinical burden worldwide, driven by population aging and the diabetes epidemic, and represent leading causes of vision impairment and blindness (Wong et al., 2014). Optical coherence tomography (OCT) has become the indispensable workhorse imaging modality for screening, diagnosis, and longitudinal monitoring of these conditions, delivering high-resolution, non-invasive cross-sectional visualization of retinal microstructure that directly informs anti-VEGF treatment decisions and disease activity assessment (Flaxel et al., 2020). Deep learning has become integral to automated OCT interpretation, yet conventional supervised approaches remain constrained by the scarcity of large, expert-annotated retinal datasets, motivating a shift toward self-supervised pretraining that learns directly from unlabeled scans (Morano et al., 2025). Within this paradigm, Vision Transformer-based foundation models—including the general-domain DINOv3 (Siméoni et al., 2025) and retina-specific models such as RETFound (Zhou et al., 2023), VisionFM (Qiu et al., 2024), EyeCLIP (Shi et al., 2025), and MIRAGE (Morano et al., 2025)—have demonstrated that large-scale self-supervised pretraining yields transferable representations that consistently outperform models trained from scratch or pretrained on ImageNet across diagnostic and prognostic retinal tasks. A single such backbone can deliver strong performance across both classification and segmentation of OCT images, making vision foundation models an increasingly attractive basis for retinal image analysis.

Despite this promise, the foundation models driving these gains are typically large, GPU-intensive architectures, and their substantial computational and infrastructure requirements remain a major obstacle to real-time deployment on portable devices or in resource-constrained clinical settings (Jin et al., 2026; Chia et al., 2024). Compounding this barrier, building a foundation model with broad generalizability typically demands pretraining on large, heterogeneous datasets pooled across institutions and imaging devices, a scale of data acquisition and curation that is logistically and financially prohibitive for most individual research groups or clinical centers (Chia et al., 2024; Zhou et al., 2026). A natural avenue to sidestep the data constraint is masked image modeling (MIM), a self-supervised paradigm that eliminates the need for labeled data and, in principle, allows pretraining on more modest unlabeled datasets. Pixel-level MIM approaches reconstruct raw image patches from masked inputs, an objective that is easy to optimize but biases the encoder toward low-level texture statistics rather than high-level semantic features (He et al., 2022). Lifting the reconstruction target to the semantic level — by predicting discrete visual tokens produced by a vector-quantized tokenizer rather than raw pixels — was proposed as a remedy (Bao et al., 2022; Ramesh et al., 2021; Peng et al., 2023); yet standard vector quantization imposes no relational structure among learned tokens, and the one-hot MIM target treats every incorrect code as equally wrong. Crucially, both MIM generations were developed for large, GPU-intensive encoders, and neither was designed to transfer the semantic knowledge embedded in those models into a lightweight backbone suitable for point-of-care inference. Distillation into compact Vision Transformers has been studied on natural images, for example by DeiT, which transfers a teacher's class predictions through a dedicated distillation token during supervised ImageNet training (Touvron et al., 2021), and by TinyMIM, which transfers token relations from larger MIM-pretrained ViTs to smaller ones on ImageNet (Ren et al., 2023). Both were developed on large natural-image corpora with labels or continuous targets; they do not consider distillation from a foundation model through graph-structured discrete targets on a small, unlabeled in-domain medical cohort.

To address this gap, we propose a topology-aware discrete distillation framework that compresses the knowledge of a continuous vision foundation model into a compact discrete codebook, which then serves as the reconstruction target for masked image modeling. Rather than relearning representations from scratch, a student encoder is pretrained to predict the codes of a frozen teacher, transferring the teacher's semantic knowledge into a more compact backbone, as in knowledge distillation (Phuong and Lampert, 2019; Tian et al., 2020); at its smallest, this yields a model with a reduced parameter footprint potentially suitable for deployment. The framework rests on three components. First, we learn the codebook with Growing Neural Gas (GNG), a gradient-free vector quantization method: the codebook grows adaptively through topology-driven insertion and pruning. Second, GNG yields not only the codes but also an adjacency graph linking them, endowing the discrete vocabulary with relational structure that standard tokenizers lack. Third, we exploit this structure through a graph-distance soft cross-entropy loss that replaces the flat one-hot MIM target with topologically graded supervision, so that predicting a code near the correct one on the graph is penalized less than predicting a distant one—turning masked prediction into structured prediction over the learned codebook. We instantiate the framework with two teachers from different domains—a retina-specific foundation model (MIRAGE; Morano et al., 2025) and a general-domain natural-image model (DINOv3; Siméoni et al., 2025)—and pretrain the student using only a single small public OCT dataset, Duke iAMD (Farsiu et al., 2014). Both teachers evaluated here are ViT-Base with D=768, and the same pipeline applies unchanged to each.

We first evaluate the framework along two axes: how much it compresses, and how much of the teacher's downstream utility the compressed student preserves. Using this pipeline, an 86M-parameter teacher is distilled into a 22M-parameter student—roughly a fourfold reduction in size—which we assess across three OCT classification benchmarks and two segmentation benchmarks, spanning multiple datasets, imaging devices, and clinical tasks. Across these benchmarks the compact student achieved performance close to, and on individual tasks above, the teacher's, although the magnitude and direction of the difference depended on the teacher, task, metric, and student capacity. The same result holds for both the retina-specific and the natural-image teacher, which is consistent with the gains arising from the distillation framework rather than from any single backbone. Because the same pipeline runs unchanged with both teachers, it also lets us ask a second question: for which tasks a retina-specific foundation model still adds value relative to a general-domain backbone passed through the same pipeline. Taken together, these findings offer a route to compact retinal image models potentially suitable for deployment and, more broadly, a recipe for compressing medical vision foundation models into efficient backbones without re-collecting the large, multi-source corpora their original pretraining required.

References (41)