Neuron SegmentationΒΆ
This tutorial provides step-by-step guidance for neuron segmentation with SENMI3D benchmark datasets. Dense neuron segmentation in electronic microscopy (EM) images belongs to the category of instance segmentation. The methodology is to first predict the affinity map of pixels with an encoder-decoder ConvNets and then generate the segmentation map using a segmentation algorithm (e.g., watershed).
The evaluation of segmentation results is based on the Rand Index and Variation of Information.
Note
Before running neuron segmentation, please take a look at the demo to get familiar with the datasets and have a sense of how the affinity graphs look like.
All the scripts needed for this tutorial can be found at pytorch_connectomics/scripts/
. The pytorch target affinity generation is connectomics.data.utils.data_segmentation
.
Get the dataset:
wget http://hp06.mindhackers.org/rhoana_product/dataset/snemi.zip
For description of the data please check this page.
Run the training script:
$ source activate py3_torch $ python scripts/train.py -i /{path-to-snemi}/ -o outputs/unetv3 -din train-input.tif -dln train-labels.tif \ -lr 1e-03 --iteration-total 100000 --iteration-save 10000 \ -mi 18,160,160 -ma unet_residual_3d -moc 3 \ -to 2 -lo 1 -wo 1 -g 4 -c 4 -b 8
data:
i/o/din/dln
(input folder/output folder/train volume/train label)optimization:
lr/iteration-total/iteration-save
(learning rate/total #iterations/#iterations to save)model:
mi/ma/moc
(input size/architecture/#output channel)loss:
to/lo/wo
(target option/loss option/weight option)system:
g/c/b
(#GPU/#CPU/batch size)
Visualize the training progress:
$ tensorboard --logdir runs
Run inference on image volumes (min over 4-aug):
$ python scripts/test.py -i /{path-to-snemi}/ \ -din train-input.tif -mi 116,256,256 -g 4 -c 4 -b 4 \ -ma unet_residual_3d -mpt outputs/unetv3/{log-folder}/volume_100000.pth -mpi 99999 -dp 8,64,64 -tam min -tan 4
Gnerate segmentation and run evaluation:
Download the
waterz
package:$ git clone git@github.com:zudi-lin/waterz.git $ cd waterz $ pip install --editable .
Download the
zwatershed
package:$ git clone git@github.com:zudi-lin/zwatershed.git $ cd zwatershed $ pip install --editable .
Generate 3D segmentation and report Rand and VI score using
waterz
:$ python evaluation.py -pd /path/to/snemi/aff_pred.h5 -gt /path/to/snemi/seg_gt.h5 --mode 1
You can also run the jupyter notebook segmentation.ipynb in the demo, which provides more options and visualization.