Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5e53bcb
MIL example
Nov 1, 2021
87346f1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2021
4e91b28
mil tutorial update
myron Nov 14, 2021
b82afc3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2021
7ba5a3c
mil tutorial update
myron Nov 15, 2021
861dd72
Merge branch 'master' of github.com:myron/tutorials
myron Nov 15, 2021
8c50765
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2021
c2d3f9f
Merge branch 'master' into master
bhashemian Nov 15, 2021
f344b99
small updates
myron Nov 17, 2021
247dc0b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2021
a9961e2
updated images
myron Nov 17, 2021
2c19bae
Merge branch 'master' of github.com:myron/tutorials
myron Nov 17, 2021
c668915
gdown for json
myron Nov 18, 2021
abd71ce
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 18, 2021
b6e2e0f
Merge branch 'master' into master
bhashemian Nov 19, 2021
3fb11b9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2021
6df772a
Update README
bhashemian Nov 19, 2021
1294b86
Fix formatting and typos
bhashemian Nov 19, 2021
dfa9557
small fixes
myron Nov 19, 2021
5978b16
Merge branch 'master' into master
Nic-Ma Nov 22, 2021
0c1192e
stats
myron Nov 23, 2021
e3f7cc0
pip install
myron Nov 23, 2021
95157ed
README fixes
myron Nov 24, 2021
0bbe9e9
Merge branch 'master' into master
bhashemian Nov 24, 2021
18cbb35
Merge branch 'master' into master
Nic-Ma Nov 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions pathology/multiple_instance_learning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@

# Multiple Instance Learning (MIL) Examples

This tutorial contains a baseline method of Multiple Instance Learning (MIL) classification from Whole Slide Images (WSI).
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.
The implementation is based on:

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)

![mil_patches](./mil_patches.jpg)
![mil_network](./mil_network.jpg)

## Requirements

The script is tested with:

- `Ubuntu 18.04` | `Python 3.6` | `CUDA 11.0` | `Pytorch 1.10`

- the default pipeline requires about 16GB memory per gpu

- it is tested on 4x16gb multi-gpu machine

## Dependencies and installation

### MONAI

Please install the required dependencies

```bash
pip install tifffile
pip install imagecodecs
```

For more information please check out [the installation guide](https://docs.monai.io/en/latest/installation.html).

### Data

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).
In this tutorial, we assume it is downloaded in the `/PandaChallenge2020` folder

## Examples

Check all possible options

```bash
python ./panda_mil_train_evaluate_pytorch_gpu.py -h
```

### Train

Train in multi-gpu mode with AMP using all available gpus,
assuming the training images in /PandaChallenge2020/train_images folder,
it will use the pre-defined 80/20 data split in [datalist_panda_0.json](https://drive.google.com/drive/u/0/folders/1CAHXDZqiIn5QUfg5A7XsK1BncRu6Ftbh)

```bash
python -u panda_mil_train_evaluate_pytorch_gpu.py
--data_root=/PandaChallenge2020/train_images \
--amp \
--distributed \
--mil_mode=att_trans \
--batch_size=4 \
--epochs=50 \
--logdir=./logs
```

If you need to use only specific gpus, simply add the prefix `CUDA_VISIBLE_DEVICES=...`

```bash
CUDA_VISIBLE_DEVICES=0,1,2,3 python -u panda_mil_train_evaluate_pytorch_gpu.py
--data_root=/PandaChallenge2020/train_images \
--amp \
--distributed \
--mil_mode=att_trans \
--batch_size=4 \
--epochs=50 \
--logdir=./logs
```

### Validation

Run inference of the best checkpoint over the validation set

```bash
# Validate checkpoint on a single gpu
python -u panda_mil_train_evaluate_pytorch_gpu.py
--data_root=/PandaChallenge2020/train_images \
--amp \
--mil_mode=att_trans \
--checkpoint=./logs/model.pt \
--validate
```

### Inference

Run inference on a different dataset. It's the same script as for validation,
we just specify a different data_root and json list files

```bash
python -u panda_mil_train_evaluate_pytorch_gpu.py
--data_root=/PandaChallenge2020/some_other_files \
--dataset_json=some_other_files.json
--amp \
--mil_mode=att_trans \
--checkpoint=./logs/model.pt \
--validate
```

### Stats

Expected train and validation loss curves

![mil_train_loss](./mil_train_loss.png)
![mil_val_loss](./mil_val_loss.png)

Expected validation QWK metric

![mil_val_qwk](./mil_val_qwk.png)

## Questions and bugs

- 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.
- For bugs relating to MONAI functionality, please create an issue on the [main repository](https://github.com/Project-MONAI/MONAI/issues).
- For bugs relating to the running of a tutorial, please create an issue in [this repository](https://github.com/Project-MONAI/Tutorials/issues).
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading