|
| 1 | + |
| 2 | +# Multiple Instance Learning (MIL) Examples |
| 3 | + |
| 4 | +This tutorial contains a baseline method of Multiple Instance Learning (MIL) classification from Whole Slide Images (WSI). |
| 5 | +The dataset is from [Prostate cANcer graDe Assessment (PANDA) Challenge - 2020](https://www.kaggle.com/c/prostate-cancer-grade-assessment/) for cancer grade classification from prostate histology WSIs. |
| 6 | +The implementation is based on: |
| 7 | + |
| 8 | +Andriy Myronenko, Ziyue Xu, Dong Yang, Holger Roth, Daguang Xu: "Accounting for Dependencies in Deep Learning Based Multiple Instance Learning for Whole Slide Imaging". In MICCAI (2021). [arXiv](https://arxiv.org/abs/2111.01556) |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +The script is tested with: |
| 16 | + |
| 17 | +- `Ubuntu 18.04` | `Python 3.6` | `CUDA 11.0` | `Pytorch 1.10` |
| 18 | + |
| 19 | +- the default pipeline requires about 16GB memory per gpu |
| 20 | + |
| 21 | +- it is tested on 4x16gb multi-gpu machine |
| 22 | + |
| 23 | +## Dependencies and installation |
| 24 | + |
| 25 | +### MONAI |
| 26 | + |
| 27 | +Please install the required dependencies |
| 28 | + |
| 29 | +```bash |
| 30 | +pip install tifffile |
| 31 | +pip install imagecodecs |
| 32 | +``` |
| 33 | + |
| 34 | +For more information please check out [the installation guide](https://docs.monai.io/en/latest/installation.html). |
| 35 | + |
| 36 | +### Data |
| 37 | + |
| 38 | +Prostate biopsy WSI dataset can be downloaded from Prostate cANcer graDe Assessment (PANDA) Challenge on [Kaggle](https://www.kaggle.com/c/prostate-cancer-grade-assessment/data). |
| 39 | +In this tutorial, we assume it is downloaded in the `/PandaChallenge2020` folder |
| 40 | + |
| 41 | +## Examples |
| 42 | + |
| 43 | +Check all possible options |
| 44 | + |
| 45 | +```bash |
| 46 | +python ./panda_mil_train_evaluate_pytorch_gpu.py -h |
| 47 | +``` |
| 48 | + |
| 49 | +### Train |
| 50 | + |
| 51 | +Train in multi-gpu mode with AMP using all available gpus, |
| 52 | +assuming the training images in /PandaChallenge2020/train_images folder, |
| 53 | +it will use the pre-defined 80/20 data split in [datalist_panda_0.json](https://drive.google.com/drive/u/0/folders/1CAHXDZqiIn5QUfg5A7XsK1BncRu6Ftbh) |
| 54 | + |
| 55 | +```bash |
| 56 | +python -u panda_mil_train_evaluate_pytorch_gpu.py |
| 57 | + --data_root=/PandaChallenge2020/train_images \ |
| 58 | + --amp \ |
| 59 | + --distributed \ |
| 60 | + --mil_mode=att_trans \ |
| 61 | + --batch_size=4 \ |
| 62 | + --epochs=50 \ |
| 63 | + --logdir=./logs |
| 64 | +``` |
| 65 | + |
| 66 | +If you need to use only specific gpus, simply add the prefix `CUDA_VISIBLE_DEVICES=...` |
| 67 | + |
| 68 | +```bash |
| 69 | +CUDA_VISIBLE_DEVICES=0,1,2,3 python -u panda_mil_train_evaluate_pytorch_gpu.py |
| 70 | + --data_root=/PandaChallenge2020/train_images \ |
| 71 | + --amp \ |
| 72 | + --distributed \ |
| 73 | + --mil_mode=att_trans \ |
| 74 | + --batch_size=4 \ |
| 75 | + --epochs=50 \ |
| 76 | + --logdir=./logs |
| 77 | +``` |
| 78 | + |
| 79 | +### Validation |
| 80 | + |
| 81 | +Run inference of the best checkpoint over the validation set |
| 82 | + |
| 83 | +```bash |
| 84 | +# Validate checkpoint on a single gpu |
| 85 | +python -u panda_mil_train_evaluate_pytorch_gpu.py |
| 86 | + --data_root=/PandaChallenge2020/train_images \ |
| 87 | + --amp \ |
| 88 | + --mil_mode=att_trans \ |
| 89 | + --checkpoint=./logs/model.pt \ |
| 90 | + --validate |
| 91 | +``` |
| 92 | + |
| 93 | +### Inference |
| 94 | + |
| 95 | +Run inference on a different dataset. It's the same script as for validation, |
| 96 | +we just specify a different data_root and json list files |
| 97 | + |
| 98 | +```bash |
| 99 | +python -u panda_mil_train_evaluate_pytorch_gpu.py |
| 100 | + --data_root=/PandaChallenge2020/some_other_files \ |
| 101 | + --dataset_json=some_other_files.json |
| 102 | + --amp \ |
| 103 | + --mil_mode=att_trans \ |
| 104 | + --checkpoint=./logs/model.pt \ |
| 105 | + --validate |
| 106 | +``` |
| 107 | + |
| 108 | +### Stats |
| 109 | + |
| 110 | +Expected train and validation loss curves |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | +Expected validation QWK metric |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | +## Questions and bugs |
| 120 | + |
| 121 | +- For questions relating to the use of MONAI, please us our [Discussions tab](https://github.com/Project-MONAI/MONAI/discussions) on the main repository of MONAI. |
| 122 | +- For bugs relating to MONAI functionality, please create an issue on the [main repository](https://github.com/Project-MONAI/MONAI/issues). |
| 123 | +- For bugs relating to the running of a tutorial, please create an issue in [this repository](https://github.com/Project-MONAI/Tutorials/issues). |
0 commit comments