Source code for our paper Weakly Supervised Histopathology Image Segmentation with Sparse Point Annotations.
GlaS challenge is a well-known H&E stained digital pathology dataset for medical image segmentation. Download the dataset from here. Then run the following convenience script to organize the dataset:
$ python prepare_glas.py /path/to/downloaded/dataset -o data_glas
The mask-level fully-annotated dataset data_glas
looks like this:
data_glas
├── train
│ ├── images
│ │ ├── train-1.png
│ │ └── train-2.png
│ └── masks
│ ├── train-1.png
│ └── train-2.png
└── val
├── images
│ ├── val-1.png
│ └── val-2.png
└── masks
├── val-1.png
└── val-2.png
Download the dataset from this link. Then organize this dataset like GlaS mentioned above.
$ python scripts/generate_points.py /path/to/dataset -p 1e-4
The
-p
or--label-percent
argument is for controlling the percentage of labeled pixels. Larger value means stronger supervision.
Then labels
directory storing point labels will be generated alongside images
and masks
. Each csv file within labels
directory correspond to a training image, with each row (a triple) representing a point:
p1_top,p1_left,p1_class
p2_top,p2_left,p2_class
$ python scripts/visualize_points.py data_glas/train
You will see visualization outputs in data_glas/train/viz
.
$ python train.py /path/to/dataset --epochs 100
$ python train.py /path/to/dataset --epochs 100 --checkpoint /path/to/checkpoint
By default, each run will be stored within a timestamped directory within records
. The structure of a record directory is as follows:
records/20190423-1122-AM
├── checkpoints
│ ├── ckpt.0001.pth
│ ├── ckpt.0002.pth
│ └── ckpt.0003.pth
├── curves
│ ├── loss.png
│ ├── pixel_acc.png
│ └── sp_acc.png
├── history.csv
├── params
│ ├── 0.json
│ └── 1.json
└── source
checkpoints
directory stores all training checkpointscurves
stores learning curves for loss and all metricsparams
stores CLI and configuration parameterssource
stores a snapshot of all source code filehistory.csv
records the training history
We offer four types of inference utilities:
- Superpixel-wise inference (the
infer.py
script) - Superpixel-wise inference with tiling strategy (the
infer_tile.py
script) - Pixel-wise inference (the
pixel_infer.py
script) - Pixel-wise inference with tiling strategy (the
pixel_infer_tile.py
script)
Example:
$ python infer.py /path/to/test/data --checkpoint /path/to/checkpoint
$ python pixel_infer_tile.py /path/to/test/data --checkpoint /path/to/checkpoint --patch-size 400