How to Train a State-of-the-Art Pathology Foundation Model with $1.6k

Introducing OpenMidnight foundation model for pathology.
Figure 1: Overview of the OpenMidnight pathology foundation model training and evaluation pipeline.

TL;DR: We present OpenMidnight, a replication and improvement of the Midnight pathology foundation model, that achieves state-of-the-art performance across multiple benchmarks while being trained on just 12,000 whole-slide images for only $1.6K. We demonstrate that foundation models for computational pathology do not require massive scale to achieve top performance, and we release the full training pipeline, code, and model weights to accelerate research in this field.

Introduction

Examining patient tissue under a microscope by a pathologist is an essential step in diagnosing and treating cancer and other diseases. Specifically, a tissue biopsy is taken, and the sample is stained and affixed to a glass slide for the pathologist to analyze. The pathologist performs various tasks, such as detecting abnormal cells and determining the severity of disease. In order to accurately assess the tissue slide, the pathologist has to observe the shape of cells, the organization of cells in the tissue, and more.

Computational pathology (CPath), which is the application of AI to digitized whole-slide images (WSIs), has emerged to augment these workflows. AI systems have been developed for tasks like tumor detection, grading, margin assessment, and segmentation. AI can also be used to predict features that doctors otherwise cannot determine from WSIs like survival-risk prediction, drug treatment response, and even inference of certain molecular or gene expression signatures from morphology.

While many early CPath systems were "narrow" deep-learning models trained for a single task (some methods currently approved by the FDA and used in clinical practice), the field is increasingly exploring foundation models. Rather than training a new model for every task, a single pre-trained foundation model can be adapted to many downstream applications in CPath. Companies like Microsoft, Paige, PathAI, Bioptimus, and Kaiko.AI have each trained their own foundation models for pathology images. They typically rely on self-supervised learning techniques such as DINOv2 to train transformers to learn meaningful representations using unlabeled data.

The prevailing wisdom is that foundation models should improve with scale, so companies with access to the most data should develop the best performing foundation models. However, this is an assumption worth challenging. In April 2025, Kaiko.AI released a paper titled "Training state-of-the-art pathology foundation models with orders of magnitude less data" in which they presented Midnight, a foundation model trained on just 12,000 whole-slide images (WSIs) from the publicly available TCGA dataset. Surprisingly, this model performed on par with all the other foundation models, many of which were trained on over a million WSIs!

At Sophont, our initial steps towards training our own pathology foundation model began with a replication of Kaiko.AI's Midnight model, fully open-sourced, including training code and model weights. Through some additional minor pipeline improvements, we achieve state-of-the-art (SOTA) average performance across a variety of benchmarks. We estimate that our model consumed 16× fewer GPU hours and completed in one-quarter of the time it took to train Midnight (single-node 8×H100 for 3.5 days vs. Midnight's 32×H100 for 14 days), costing only $1.6K USD assuming a cost of $2.5/H100/hr (exact compute costs may vary).

In this post, we detail how our Midnight replication works and what it means for the field that this model could outperform the competition without scale.

We release this model as OpenMidnight, the first model in our series of pathology foundation models. We open-source the model weights on 🤗 Hugging Face, and the training code on 💻 GitHub. If you're interested in trying out the model, we have a 🧪 demo.

Results

We evaluate OpenMidnight on a variety of benchmarks supported by eva, an evaluation suite released by Kaiko.ai. These benchmarks cover multiple different downstream proxy tasks, from nucleus segmentation to tumor patch classification to cancer subtyping of WSIs. We also evaluate OpenMidnight on the HEST benchmark, which is a collection of multiple benchmarks for predicting cell gene expression from pathology image patches. Together, these benchmarks expose different strengths and weaknesses of the model being evaluated.

Average performance of top pathology foundation models and baselines.
Figure 2: Average performance of top pathology foundation models and baselines. Scores for prior models are taken from Karasikov et al. (2025).

These results show that OpenMidnight's performance is comparable or superior to all other models on all tasks, with our average performance being the highest among the tested models (Figure 2). OpenMidnight achieves a new state-of-the-art on both BreakHis and Cam16(small) scoring 0.946 and 0.873 balanced accuracy, respectively, beating the next best model, UNI-2’s 0.860 on BreakHis and 0.873 on Cam16(small).

Again, it is worth highlighting that OpenMidnight was trained with only 12k slides while UNI-2, the third best model, is trained with over 350k slides!

Model #WSIs PCam (10 shots) BACH BRACS BreakHis CRC-100K Gleason MHIST PCam Cam16 (small) Panda (small) CoNSeP MoNuSAC HEST Average
OpenMidnight (Ours)12K0.7900.9160.6610.8730.9610.8170.8440.9380.9460.6520.6310.6550.3900.775
Midnight92K0.9000.9060.6420.8500.9640.8090.8250.9510.8310.6330.6630.7070.3840.774
UNI-2350K0.8870.9140.6610.8600.9650.7780.8230.9490.8680.6590.6280.6440.4140.773
UNI-2/392350K0.8210.9170.6630.8290.9650.7910.8490.9270.8580.6530.6290.6590.4070.767
Virchow23.1M0.8510.8840.6240.8230.9660.7780.8610.9360.8650.6560.6390.6760.3980.766
Midnight 92k92K0.8760.8960.6160.7890.9660.8200.8110.9500.8610.6250.6290.6560.3920.761
Midnight 12k12K0.7910.9040.6440.8410.9660.8010.8070.9300.8500.6630.6260.6630.3950.760
H-Optimus-0500K0.8240.7570.6150.8080.9560.7710.8420.9420.8380.6700.6440.6850.4150.751
Kaiko-B829K0.7860.8720.6170.8250.9570.7480.8280.9170.8310.6420.6430.6860.3730.748
TCGA-100M12K0.7740.8640.6150.7790.9670.7990.7920.9270.8520.6670.6220.6560.3960.747
Prov-GigaPath171K0.8520.7660.6160.8210.9510.7200.8310.9420.7910.6600.6260.6870.3930.743
Hibou-L1.1M0.8040.8110.6370.7400.9330.7630.8390.9520.8230.6340.6450.6680.3880.740
UNI100K0.8150.7910.5930.7890.9480.7570.8400.9380.8220.6550.6270.6590.3860.740
UNI/512100K0.7370.8770.6120.7320.9500.7540.8140.8830.8140.6540.6210.6580.3640.728
Phikon12K0.8200.7350.5680.7130.9420.7290.8040.9230.8090.6440.6230.6440.3670.717
Phikon v260K0.7410.7340.6000.7160.9390.7550.7840.8930.8030.6310.6260.6450.3750.711
DINOv2-giant (pretrained)00.7190.7250.5830.8320.9350.7440.8620.8740.5070.3820.5640.6140.3420.668
DINOv2-giant (random)00.6490.4730.4110.4270.7480.4640.5690.7550.5660.3080.4610.4280.1720.495
Performance comparison of OpenMidnight to existing pathology foundation models on eva+HEST benchmarks. Scores for existing models are taken from Karasikov et al. (2025). We report balanced accuracy for the classification tasks, Dice score for semantic segmentation (CoNSeP and MoNuSAC), and the average Pearson correlation for the nine HEST regression tasks. Only performance with [CLS] token is reported. Best score per dataset is bolded.

We also qualitatively evaluated the representations learned by OpenMidnight. We took images from the BACH dataset of breast cancer images, passed them through our model, and visualized the embeddings produced by our model using t-SNE (Figure 3). We see a clear separation between different classes and also observe sensible organization of images in the t-SNE space: normal images are closer to benign images than invasive carcinoma images. We also compare these representations to those of a pretrained DINOv2 ViT-G, which lacks any clear separation between classes.

t-SNE of CLS token embeddings of images from the BACH dataset.
Figure 3: t-SNE of CLS token embeddings of images from the BACH dataset from both DINOv2 ViT-G and OpenMidnight. The embeddings from the OpenMidnight foundation model show clear separation across classes, as opposed to the embeddings from the DINOv2 ViT G model.

In addition, we perform a principal component feature analysis within single images of the MoNuSAC dataset (Figure 4). Here we see the principal components picking up on different structures within the image.

PCA analysis of MoNuSAC embeddings.
Figure 4: PCA analysis of MoNuSAC embeddings. It's possible to visualize different tissue components using PCA.

How we did it

Our training approach does not differ significantly from other SOTA pathology foundation models, which utilize Meta's DINOv2. However, we mostly follow the original Midnight paper, which makes a few changes that likely enable more data-efficient training.

We start with a pretrained 1.1B parameter ViT-G DINOv2. We suspect that initialization with the pretrained checkpoint enables faster convergence and more efficient training. We also use the KDE regularizer to help with stable training, replacing KoLeo typically used in DINOv2.

OpenMidnight also utilizes augmentations in the Hematoxylin-Eosin-DAB colorspace to increase the diversity of the training data and improve robustness of the model. We also applied these augmentations, but we qualitatively observed that the initial augmentations applied to the image patches during DINOv2 were quite strong, so we decreased the strength of these augmentations.

A majority of the prior works divide up the large whole-slide images into non-overlapping patches of size 224/256 ahead of time, and save them offline. OpenMidnight switched to an online patching approach, where the patches are sampled from the whole-slide image during training. We differ from OpenMidnight by utilizing a variation of offline patching, in which we instead precompute the image patches. However, we still select the patches randomly from within the image, allowing for overlaps. We also perform filtering of non-informative patches like in OpenMidnight.

We train OpenMidnight only on one publicly available dataset: TCGA, which contains 12K Formalin-Fixed, Paraffin-Embedded (FFPE) slides from 32 different cancer types. Note that while some pathology foundation models also train on this dataset, most utilize large-scale proprietary datasets.

We train using 8 Nvidia-H100 GPUs (80GB memory) at a batch size of 48 per GPU (384 total batch size), for 250K steps, at a learning rate of 2.0e-4 with the AdamW optimizer. This takes around 83.33 wall-clock hours (667 GPU hours), with 96M image patches seen, and 29M unique image patches.

The current state of pathology foundation models

The surprising performance of OpenMidnight motivates us to take a closer look at the state of pathology foundation models.

All the top CPath foundation models were trained nearly identically, with the biggest difference coming from the private data sources used to train the model. Everyone seems to follow the same recipe of DINOv2 from scratch on patches of whole-slide images, with a few groups identifying benefits from things like swapping out KoLeo with KDE regularization, discarding patches that contain primarily adipose tissue, and performing data augmentation steps curated better for pathology slides than natural images.

Despite almost identical model architectures, downstream performance across the foundation model landscape is messy. Among the top models, there isn't a clear winner in performance across all the benchmarks (see table above). Additionally, Figure 5 (numbers pulled from prior works) demonstrates that when training pathology foundation models, average performance is not cleanly correlated with the compute used or dataset size.

Average model performance plotted against amount of training compute. Average model performance plotted against dataset size.
Figure 5: Average model performance plotted against amount of training compute and dataset size. Compute is normalized to H100 GPU-hours. Models that do not report training compute or dataset size are omitted. Poor scaling of pathology foundation models is observed.

These observations reveal some of the limitations of the current state of the field. We come to two conclusions. First, OpenMidnight demonstrates that we can push foundation models on limited data much further than previously thought. Second, the messy performance landscape points to a broader concern: whether these benchmarks are truly reflective of real-world use-cases. Perhaps performance completely changes when applied to more sophisticated downstream use-cases beyond linear probes on basic classification tasks. Additionally, we note that datasets used for benchmarking are often low-quality or are improperly preprocessed during benchmark evaluation. For instance, we observed that vision transformers pretrained only on ImageNet (i.e., a model that has never seen a pathology slide) can actually outperform all pathology foundation models on the MHIST dataset. For these reasons, we urge the field to adopt better-curated benchmarks, rigorous preprocessing checks, and develop more practically oriented standardized evaluations; frameworks like eva were a much-needed step towards reproducible comparisons but further work is needed to align evaluations with clinical utility. Unfortunately, the most clinically relevant datasets and benchmarks are private, and we encourage the community to open-source better real-world benchmarks.

Open-sourcing the full pipeline

We believe that fully open-sourcing the code, weights, and evaluation scripts lowers the barrier to entry, and accelerates progress in CPath with improved trust and reproducibility.

We hope that OpenMidnight will serve as an accessible baseline for pathology foundation models, and our open-source training pipeline will expand participation in the development of the next generation of pathology foundation models. Students, clinicians, and researchers without access to large compute clusters or private datasets can work together with us on methods to improve the field for everyone.

We request the CPath community to experiment with OpenMidnight and test out the model in their own research, and share any interesting results with us in the MedARC community Discord server here.

We are also building in public and welcome collaborators of all forms in the MedARC Discord server as we develop our next model, one that will deviate further from prevailing recipes to hopefully deliver larger practical gains (including better whole-slide context and a DINOv3 backbone).

Additionally, we are actively hiring, so if this is a research area that interests you, check out our job posting!

Finally, if you are a life sciences company/startup, hospital, clinician, etc. interested in applying our models to your own use cases, contact us here.

Acknowledgments

We thank Mikhail Karasikov for answering questions about Midnight. We thank Nicolas Känzig for answering questions about eva. We thank the members of MedARC and the broader research community for their feedback and support. We are very grateful to FAL AI for granting compute to support this open-source research.

Citation

For attribution in academic contexts, please cite this work as

Daniel Kaplan, Ratna Sagari Grandhi, Connor Lane, Benjamin Warner, Tanishq Mathew Abraham, and Paul S. Scotti, "How to Train a State-of-the-Art Pathology Foundation Model with $1.6k", Sophont Blog, 2025.

BibTeX citation

@article{kaplan2025openmidnight,
            author = {Kaplan, Daniel and Grandhi, Ratna Sagari and Lane, Connor and Warner, Benjamin and Abraham, Tanishq Mathew and Scotti, Paul S.},
            title = {How to Train a State-of-the-Art Pathology Foundation Model with \$1.6k},
            year = {2025},
            url = {https://sophont.med/blog/openmidnight},
          }