|
| 1 | +# Large vesicle segmentation |
| 2 | + |
| 3 | +This module contains code for training and infering on a new dataset, as well as pretrained model checkpoints and a sample for validation. For setup, install [Pytorch Connectomics](https://connectomics.readthedocs.io/en/latest/notes/installation.html), [em_util](https://github.com/PytorchConnectomics/em_util), [neuroglancer](https://pypi.org/project/neuroglancer), and [cloud-volume](https://pypi.org/project/cloud-volume). |
| 4 | + |
| 5 | +## Training |
| 6 | +Download your data. This model was built using the Pytorch Connectomics package, and thus all configuration for training is done within the yaml files within `configs`. Refer to the file `configs/00_base.yaml` as a template. Most fields can be left untouched, but to adapt to your dataset, change the following parameters at the very minimum: |
| 7 | + |
| 8 | +* `DATASET.INPUT_PATH`: points towards directory containing training data. PyTC's dataloader will automatically seperate this into training/validation partitions. |
| 9 | +* `DATASET.IMAGE_NAME`: points to a single image or a list of images. Lists can be represented using standard YAML notation or by concatenating lists of images with `@` as a delimiter |
| 10 | +* `DATASET.OUTPUT_PATH`: points to an output directory that will contain model checkpoints |
| 11 | + |
| 12 | +After editing the config file, you can execute training with: |
| 13 | + |
| 14 | +`python scripts/main.py --config-base configs/<base.yaml> --config-file configs/bcd_config.yaml` |
| 15 | + |
| 16 | +To continue retraining from a checkpoint, use: |
| 17 | + |
| 18 | +`python scripts/main.py --config-base configs/<base.yaml> --config-file configs/bcd_config.yaml --checkpoint <path-to-checkpoint> SOLVER.ITERATION_RESTART True` |
| 19 | + |
| 20 | +## Inference |
| 21 | + |
| 22 | +Inference tools are available in `tools/process.py`. To do inference, in a Python shell or file, run: |
| 23 | + |
| 24 | +`> do_inference(<im_path>, <pred_path>, [<base_config.yaml>, <bcd_config.yaml>], <checkpoint_path>)` |
| 25 | + |
| 26 | +To also get adapted rand, precison, and recall metrics, run: |
| 27 | + |
| 28 | +`> infer_and_stats([<im_path1>, ...], [<pred_path1>, ...], [<mask_path1, ...>], [<base_config.yaml>, <bcd_config.yaml>], <checkpoint_path>), |
| 29 | +` |
| 30 | + |
| 31 | +Our final model checkpoint is provided at `outputs/checkpoint_1000000.pth.tar`. |
| 32 | + |
| 33 | +## Visualiztion |
| 34 | + |
| 35 | +Visualing predictions is done with neuroglancer. To load a volume and its segmentation, modify the file `scripts/ng.py`, then run `python -i scripts/ng.py`. A link to view neuroglancer will open. If running on a remote cluster, please note that port forwarding will be necessary to view on your machine. The `screnshot()` function can be used to take high-resolution screenshots of the neuroglancer representation. |
| 36 | + |
| 37 | +Further documentation for both functions is contained in `tools/process.py` |
| 38 | + |
| 39 | +## Sample |
| 40 | + |
| 41 | +A small sample is prepared in the `sample` directory. `11-5` shows a small inter-neuron region with an assortment of large vesicles. Neuroglancer scripts that display the CLAHE-enhanced images, neuron mask, ground truth, and predictions with the final model checkpoints are prepared in `sample/11-5_ng.py`. |
0 commit comments