Segmentation and measurements for retinal layers in OCT data using neural networks, e.g. OCT-SAM and nnU-Net.
OCT-SAM can be installed via conda (or micromamba). To install it:
Download the github repository:
git clone https://github.com/computational-cell-analytics/oct-samGo to the directory:
cd oct-samCreate an environment with the required dependencies:
conda env create -f environment.yamlActivate the environment:
conda activate oct-samInstall the oct_tools package:
pip install -e .Heidelberg Heyex tomograms in VOL format are read by oct_tools.heyex_vol, which is part of the package. No additional dependency is required to process the external data from the public datasets.
Follow the instructions specified in doc/nnunet.md.
The relevant functions are:
oct_tools.interactive: For automatic and interactive segmentation.- Automatic segmentation is based on deriving prompts from the SAM predictions and then segmenting the layers with the fine-tuned SAM model based on these prompts.
oct_tools.metrics: Calculate metrics for a segmentation.oct_tools.measure: Interactive measurement tool for segmentation analysis with napari.oct_tools.apply_sam: Apply an OCT-SAM model on multiple images without interactions.oct_tools.apply_nnunet: Apply the pre-trained nnU-Net model on multiple images without interactions.oct_tools.eval_segmentation: Evaluate segmentation by comparing it to labels to measure network performance.oct_tools.open_labels: Open one or more segmentations in napari with the retinal layer color map.
The following scripts are relevant:
scripts/training/pretrain_oct_sam_on_public_datasets.py: For pre-training a SAM model on the public datasets.scripts/training/train_oct_sam.py: For fine-tuning a SAM model on the public datasets and the UMG-RP data.scripts/training/finetune_pretrained_model_iteratively.py: For fine-tuning a pre-trained checkpoint on a data subset.scripts/training/train_oct_sam_semantic.py: For training a SAM model for semantic segmentation.
The data is located at /mnt/vast-nhr/projects/nim00007/data/mace/oct-data. Currently (2026-04-29), it is not clear if the data will be published.
The models are located at /mnt/vast-nhr/projects/nim00007/data/mace/oct-data/models.
Models available for download online:
oct-sam-V1.pt: The fine-tuned SAM model, which was trained on public datasets (HCMS and Duke DME) and the UMG-RP data. Download from ownCloud
Two public datasets, HCMS and Duke DME, and a private dataset UMG-RP were used for network training.
UMG-RP consists of a retrospective cohort of 37 retinitis pigmentosa (RP) patients who presented at the Department of Ophthalmology, University Medical Center of Göttingen, between 2019 and 2025.
Detailed information about the data can be found here: doc/training_data.md
The segmentation data was limited to the 7 layers:
- RNFL: Retina nerve fiber layer
- GCL+IPL: Ganglion cell layer and inner plexiform layer
- INL: Inner nuclear layer
- OPL: Outer plexiform layer
- ONL: Outer nuclear layer
- EZ: Ellipsoid zone (Inner photoreceptor segments and Outer photoreceptor segments)
- RPE: Retinal pigment epithelium
Two segmentation models were used:
- OCT-SAM:
- model for interactive segmentation
- based on µSAM (Segment Anything Model for microscopy)
- nnU-Net:
- open source network for 2D and 3D semantic segmentation in medical imaging
- paper
The pre-trained models can be downloaded here:
Additional information about network training and application can be found here: doc/oct-sam.md and doc/nnunet.md.