Skip to content

Repository files navigation

Endometrial Cancer Subtype Prediction

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.

Overview

pipeline

Installation

Install the dependencies

pip install -r requirements.txt

Preprocessing

  1. 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.

  2. Extract raw patches to 1024x1024 resolution, use tiatoolbox or DeepZoom for patch extraction. The tumor segmentation network can be easily added to these pipelines.

Data preparation

  1. 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
  2. [Optional] Run stain normalization for whole slide image tiles wsi_normalizer. This step is recommended for external validation when you have multiple cohorts.

  3. 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 slide split the data on slide level

    --on patient split the data on patient level (use name column)

    A directory named kf will be created in the current directory.

  4. Modify the config.yaml file to set hyperparameters.

    • Hyperparameters: batch_size, lr, epochs, iters_to_val, save_best

    • Task-specific config: class_names

Train and evaluate

  1. Train & evaluate a single fold (e.g., fold 1) and evaluate on the validation set

    python train.py --fold 1
  2. Train & evaluate all folds (for Windows)

    python ./scripts/train_kf.py

    Train & evaluate all folds (for Linux)

    sh ./scripts/train_kf.sh
  3. 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
     │   │   │   ├── ...
     │   │   ├── ...
     │   ...
  4. 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.

Interpretable feature analysis

The code for interpretable feature analysis is provided in the another repository: PyPathomics.

feature-set-eg

Comparison experiments

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

License

© This code is released under the GPLv3 License for non-commercial academic use.

Reference

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

About

Official code for An interpretable deep learning model for predicting endometrial cancer molecular subtypes from H&E-stained slides..

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages