Segmentation example¶
The segmentation example is the smallest, most conservative training workflow shipped with KonfAI. It is meant to be easy to read, easy to adapt, and easy to use as a first project template.
What is in the folder¶
examples/Segmentation/
├── Config.yml
├── Prediction.yml
├── Evaluation.yml
└── Segmentation_demo.ipynb
Config.ymldefines the training workflow.Prediction.ymldefines inference and export.Evaluation.ymlcomputes Dice on the saved predictions.Segmentation_demo.ipynbbootstraps the example in a fresh environment.
Expected dataset layout¶
Dataset/
├── CASE_000/
│ ├── CT.mha
│ └── SEG.mha
└── ...
CTis the input image.SEGis the segmentation label map.
The shipped demo assumes:
a multiclass task
label
0for backgroundlabels
1..40for foreground classes41classes total
Default baseline¶
The baseline uses:
the built-in
segmentation.UNet.UNet2D patch-based training
CrossEntropyLossduring trainingDice during evaluation
Training uses CrossEntropyLoss on purpose. It keeps the live training loop
simple and stable while final quality is still measured with Dice during
evaluation.
Minimal workflow¶
Run all commands from examples/Segmentation.
Train:
konfai TRAIN -y --gpu 0 --config Config.yml
Predict:
konfai PREDICTION -y --gpu 0 --config Prediction.yml \
--models Checkpoints/SEG_BASELINE/<checkpoint>.pt
Evaluate:
konfai EVALUATION -y --config Evaluation.yml
Outputs are written to:
Checkpoints/SEG_BASELINE/Statistics/SEG_BASELINE/Predictions/SEG_BASELINE/Evaluations/SEG_BASELINE/
What to adapt first¶
Most real projects will need changes in:
dataset_filenamestrain_namepatch size
batch size
nb_classpreprocessing transforms
the list of Dice labels in
Evaluation.yml
If your dataset is not a 0..40 label map, update both nb_class and the Dice
labels together.