Official code for An interpretable deep learning model for predicting endometrial cancer molecular subtypes from H&E-stained slides. npj precision oncology
Journal link | Download citation
This repository contains the official implementation of a deep learning framework designed to predict molecular subtypes of endometrial cancer directly from H&E-stained whole slide images. By leveraging an interpretable, end-to-end prediction network, this tool bridges the gap between traditional histology and modern molecular profiling, offering a cost-effective and scalable approach to personalized oncology.
Install the dependencies
pip install -r requirements.txt-
We have uploaded another repo for data preprocessing: WSI_Segmenter. It can also be found in the ./preprocess directory. The detailed patch extraction and segmentation steps can be found in the ./preprocess/readme.md.
-
Extract raw patches to 1024x1024 resolution, use tiatoolbox or DeepZoom for patch extraction. The tumor segmentation network can be easily added to these pipelines.
-
Prepare the data in the following structure, png or jpeg format is supported. Note that extracting patches only from the tumor region is recommended.
├── data │ ├── slide_1 │ │ ├── patch_1.png │ │ ├── patch_2.png │ │ ├── ... │ ├── slide_2 │ │ ├── patch_1.png │ │ ├── patch_2.png │ │ ├── ... │ ├── ... │ └── slide_n │ ├── ... │ └── patch_n.png
-
[Optional] Run stain normalization for whole slide image tiles wsi_normalizer. This step is recommended for external validation when you have multiple cohorts.
-
Organize your data like
example.csv. Create k-fold split for the data.python utils/gen_kfold_split.py --csv <CSV_PATH> --dir <STEP_2_OUTPUT_DIR> --k 5 --on slide
--on slidesplit the data on slide level--on patientsplit the data on patient level (use name column)A directory named
kfwill be created in the current directory. -
Modify the config.yaml file to set hyperparameters.
-
Hyperparameters: batch_size, lr, epochs, iters_to_val, save_best
-
Task-specific config: class_names
-
-
Train & evaluate a single fold (e.g., fold 1) and evaluate on the validation set
python train.py --fold 1
-
Train & evaluate all folds (for Windows)
python ./scripts/train_kf.py
Train & evaluate all folds (for Linux)
sh ./scripts/train_kf.sh
-
The results will be saved in the
runs/directory.In the format of:
├── runs │ ├── {cmbs} # configuration │ │ ├── 1 # fold name │ │ │ ├── {fold}_best.pth # best model │ │ │ ├── slide_{iter}.png # slide-level ROC │ │ │ ├── ... │ │ ├── ... │ ... -
im4MEC pipeline Here, we follow the im4MEC pipeline to pretrain, train and evaluate the model (we simplify the original code for single-gpu-support). The code is provided in the
im4MEC-pipeline/directory.- Pretrain the model:
python train_moco_v2.py
- Extract features:
python extract_features.py
Then, you can use the CLAM pipeline for model training and evaluation.
The code for interpretable feature analysis is provided in the another repository: PyPathomics.
We are grateful to the authors for sharing their code. We use CLAM for data preprocessing and feature extraction in comparison experiments.
| Model | Authors | GitHub link |
|---|---|---|
| CLAM | Lu et al. | https://github.com/mahmoodlab/CLAM |
| im4MEC | Fremond et al. | https://github.com/AIRMEC/im4MEC |
| TransMIL | Shao et al. | https://github.com/zhangzj5/TransMIL |
© This code is released under the GPLv3 License for non-commercial academic use.
If you find our work useful in your research, please consider citing our paper:
Guo, Q., Cui, H., Zhang, Y. et al. An interpretable deep learning model for predicting endometrial cancer molecular subtypes from H&E-stained slides. npj Precis. Onc. (2026). https://doi.org/10.1038/s41698-026-01280-w

