Giter Club home page Giter Club logo

histobistro's Introduction

HistoBistro

Pipeline for weakly-supervised learning on histology images. The pipeline contains various models for multiple instance learning with different aggregation models. Based on Pytorch Lightning. All aggregation modules can be loaded as model files in the classifier lightning module. Loss, models, optimizers, and schedulers can be specified as strings according to the PyTorch name in the config file.

Repository structure

├── CancerCellCRCTransformer        # materials for the publication
├── models                          # all model files
│   ├── aggregators
│   │   ├── __init__.py  
│   │   ├── aggregator              # base class for aggregation modules 
│   │   ├── attentionmil.py         # model by Ilse et al., 2018
│   │   ├── lamil.py                # model by Reisenbüchler er al., 2022
│   │   ├── model_utils.py          # common layers and functions used in the other models
│   │   ├── perceiver.py            # model by Jaegle et al., 2021
│   │   ├── test_aggregators.py     # test new aggregators
│   │   ├── transformer.py          # CancerCellCRCTransformer model
│   │   ├── transmil.py             # model by Shao et al. 2021
├── classifier.py                   # lightning module for feature classification
├── config.yaml                     # config file for training
├── data.py                         # dataset class and helper functions
├── environment.yaml                # config file for conda environment
├── main.py                         # train and test models
├── train_k-fold.py                 # train models with k-fold cross validation
├── test_k-fold.py                  # test models with k-fold cross validation
├── test.py                         # test models (e.g., CancerCellCRCTransformer models)
├── options.py                      # argument parsing, overrides config file when arguments are given
├── Evaluations.ipynb               # visualize attention and classification score heatmaps
├── Visualizations.ipynb            # plot metric curves (ROC, PRC) and analyze clinicopathological features
├── utils.py                        # get files and other utils

Setup

Setup data_config.yaml and config.yaml with your data paths and training configurations. All entries in brackets < > should be customized.

Install the following packages needed for a minimal working environement:

  • mamba/conda: pytorch pytorch-lightning wandb einops pyparsing h5py pandas
  • pip: dgl

Alternatively, install the conda env from environment.yaml:

conda env create --file environment.yaml

Data structure

  • clini_table.xlsx: Table (Excel-file) with clinically important labels. Each patient has a unique entry, column names PATIENT and TARGET are required.
PATIENT TARGET GENDER AGE
ID_345 positive female 61
ID_459 negative male 67
ID_697 NA female 42
  • slide.csv: Table (csv-file) with patient id's matched with slide / file names (column names FILENAME and PATIENT). Patients can have multiple entries if they have multiple slides.
FILENAME PATIENT
ID_345_slide01 ID_345
ID_345_slide02 ID_345
ID_459_slide01 ID_459
  • folder with features as .h5-files. Filenames correspond to filenames in slide.csv

Training

You can train your model on a multi-centric dataset with the following k-fold cross validation (k=5) scheme where -- (train) ** (val), and ## (test).

[--|--|--|**|##]
[--|--|**|##|--]
[--|**|##|--|--]
[**|##|--|--|--]
[##|--|--|--|**]

by running

python train_k-fold.py --name <name> --data_config <path/to/data_config.yaml> --config <path/to/config.yaml>

and test it on the in-domain test set and external cohorts by running

python test_k-fold.py --name <name> --data_config <path/to/data_config.yaml> --config <path/to/config.yaml>

Testing

You can test a given model with the following command:

python test.py --model_path <path/to/model.ckpt> --name <custom-name> --config_file <path/to/config.yaml> --data_config <path/to/data_config.yaml>

You can find the models for MSI high, BRAF, and KRAS prediction from the publication "Transformer-based biomarker prediction from colorectal cancer histology: A large-scale multicentric study" trained on the multicentric cohort in the folder CancerCellCRCTransformer/trained_models in this repo.

Publications

Information to publications based on this repository are grouped in the respective folders. Find more detailed information in the README.md files in the respective folders.

If you consider this useful for your research, please cite our paper:

@article{wagner2023transformer,
  title={Transformer-based biomarker prediction from colorectal cancer histology: A large-scale multicentric study},
  author={Wagner, Sophia J and Reisenb{\"u}chler, Daniel and West, Nicholas P and Niehues, Jan Moritz and Zhu, Jiefu and Foersch, Sebastian and Veldhuizen, Gregory Patrick and Quirke, Philip and Grabsch, Heike I and van den Brandt, Piet A and others},
  journal={Cancer Cell},
  publisher={Elsevier}
}

histobistro's People

Contributors

sophiajw avatar manuel-tran avatar

Stargazers

Verena Bitto avatar Mina Jamshidi avatar hamfei avatar Jiwon avatar Zihan Zhong avatar  avatar  avatar 하린 avatar Saarthak Kapse avatar Daisy Jun avatar  avatar wilson avatar chaosheng9505 avatar  avatar  avatar  avatar  avatar armaank avatar Chinglemba avatar  avatar Okunator avatar  avatar  avatar wangyh97 avatar  avatar jacob_he avatar Nicolas Triltsch avatar Yue Yang avatar  avatar Lei Zhang avatar  avatar Tabris avatar MingxinLiu avatar Ping  avatar  avatar Gijs Smit avatar  avatar superych avatar xj avatar  avatar  avatar Márcus Vinícius  avatar Daniil Lysukhin avatar Alexander Zeilmann avatar  avatar  avatar Nikos Tsiknakis avatar  avatar True C avatar Rob Jewsbury avatar Haoyu Cui avatar Hang Qiao avatar Pieter Valkema avatar Caibin Sheng avatar  avatar Valentin avatar Daniel Reisenbüchler avatar André Pedersen avatar  avatar

Watchers

Tingying Peng avatar  avatar Ali Boushehri avatar Kostas Georgiou avatar  avatar Lei Zhang avatar

histobistro's Issues

Questions about the size of tiles used to extract features

Hi, thank you for making such a great framework!

I have a question about CTransPath, I checked the literature on this method and found that the image input size of the model provided by the author is 224*224,

In your literature, it is mentioned that 512*512, I would like to ask what method was used to modify the size of the image? I haven't figured out how it works yet, I hope to get your advice, thank you!

ctranspath running error

RuntimeError: Error(s) in loading state_dict for SwinTransformer:
Missing key(s) in state_dict: "patch_embed.proj.weight", "patch_embed.proj.bias".
Unexpected key(s) in state_dict: "patch_embed.proj.0.weight", "patch_embed.proj.1.weight", "patch_embed.proj.1.bias", "patch_embed.proj.1.running_mean", "patch_embed.proj.1.running_var", "patch_embed.proj.1.num_batches_tracked", "patch_embed.proj.3.weight", "patch_embed.proj.4.weight", "patch_embed.proj.4.bias", "patch_embed.proj.4.running_mean", "patch_embed.proj.4.running_var", "patch_embed.proj.4.num_batches_tracked", "patch_embed.proj.6.weight", "patch_embed.proj.6.bias".

Need to fix

Missing code (step1, 2) request

Very seminal work and detailed code for step 3 in your whole pipeline. However, codes for feature extraction and imaging data preprocessing are missing. For example, there is no description about how the h5 feature file was generated for each cohort. The results cannot be reproduced without these codes, even though the random seed was given. Could you please upload these codes. Looking forward to your reply!

Code for the interpretability section

Could the author provide the code for the interpretability part? I would like to learn the code details of Figure 3 in the article.If possible, thank the author for sharing.

no features found in feature_dir

Thank you very much for your research and code!
I have a question, how to use ctranspath to extract features and generate h5 files? Please forgive my stupidity, I have not yet found the code and related instructions for extracting features.

Looking forward to your reply

Inquiry of code for feature extractor and data preprocessing

I noticed that you summarized 'Our model consists of a transformer-based feature extractor that was pretrained on histopathology images and a transformer-based aggregation module' in the paper. Could you please provide the code for data pre-processing and transformer-based feature extractor? I will really appreciate your generous help.

Environmental configuration issues

Hi!
May I ask if the configuration information in the data_config.yaml and config.yaml files can be more specific, such as what is filled in for target and cohorts? I hope you can give an example

How to run the training model

Hi! As a beginner, After I readed the readme.txt, I run the sentence:
"python train_k-fold.py --name --data_config <path/to/data_config.yaml> --config <path/to/config.yaml>"(of course I wrote down my own path)
in Anaconda prompt, but it gave me a error which showed:
"Incorrect file name, directory name, or volume label syntax: 'D:\HistoBistro-main\HistoBistro-main\models\try1_<Transformer\TransMIL\AttentionMIL\...><cohort_name1>-<cohort_name2><normalizatio_used>_'"
It seemslike indicate that the error is occurring in the part, and some part is vacant.
So could you please tell me how to fix the sentence and make it run successfully? I don't have the luxury of being able to run all the code anymore, but I'd still like to be able to implement at least some of it...THX!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.