SeqSeg, From New Dataset to Training to Inference

A tutorial on setting up SeqSeg for medical image segmentation

1. Data Preparation and Structure

The first step in using SeqSeg is to preprocess your data.

We require the following data:

A few things to note:

2. Data Preprocessing (for Training)

The next step is to preprocess the data for training. SeqSeg requires a model trained on local patches, so we need to extract patches from the images and masks based on centerlines.

The repository for this is vascular-segment-sampler. Use main_with_nnunet.py to extract patches and convert them to nnU-Net format in one step. First, edit the configuration YAML in config/ (e.g. config/global.yaml) so it matches your dataset, then run:

python3 main_with_nnunet.py \
    --config_name global \
    --data_dir /path/to/data \
    --outdir ./extracted_data/ \
    --num_cores 4 \
    --modality CT \
    --nnunet_name AORTAS \
    --nnunet_dataset_number 1

Key arguments:

For a quick test on a subset of cases:

python3 main_with_nnunet.py \
    --config_name global \
    --data_dir /path/to/data \
    --outdir ./extracted_data/ \
    --modality CT \
    --nnunet_name AORTAS \
    --nnunet_dataset_number 1 \
    --max_samples 100 \
    --testing

The new data can be output anywhere, but we recommend writing directly into the nnU-Net Raw directory (or copying the resulting DatasetXXX_* folder there).

3. Training

The next step is to train the model with nnU-Net (see the documentation for more details). Make sure nnUNet_raw, nnUNet_preprocessed, and nnUNet_results are set, and that the dataset from step 2 is in nnUNet_raw.

Preprocessing

Run fingerprint extraction, experiment planning, and preprocessing:

nnUNetv2_plan_and_preprocess -d 1 --verify_dataset_integrity

Replace 1 with the --nnunet_dataset_number you used above. Use --verify_dataset_integrity the first time you run this. To preprocess only a specific configuration:

nnUNetv2_plan_and_preprocess -d 1 -c 3d_fullres

Training

Train a fold with:

nnUNetv2_train DATASET_NAME_OR_ID CONFIGURATION FOLD

For example, with dataset 1 (Dataset001_AORTAS), train fold 0 of a 3D full-resolution model:

nnUNetv2_train 1 3d_fullres 0

Repeat for folds 04 (or train fold all for a single model on all training cases). Other common configurations:

nnUNetv2_train 1 2d 0
nnUNetv2_train 1 3d_lowres 0
nnUNetv2_train 1 3d_fullres 0

Add --npz if you plan to use nnUNetv2_find_best_configuration later. Resume an interrupted run with --c.

4. Inference

The final step is to run SeqSeg inference on new data. This is done with the SeqSeg/seqseg.py script. You need direct access to the directory containing the images and seed points, and another containing the trained model weights.

Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • One Model, Heart and Vessels: How MeshGrow Builds Simulation-Ready Cardiovascular Anatomy
  • How Do You Turn a Blurry CT Scan into a Simulation-Ready Artery?