Synthesis example¶
The synthesis example is the most complete low-level workflow in the repository. It demonstrates how KonfAI combines YAML configuration, local Python modules, preprocessing, prediction, and evaluation for a paired image-to-image task.
The shipped task is MR to CT synthesis.
What is in the folder¶
examples/Synthesis/
├── Config.yml
├── Config_GAN.yml
├── Prediction.yml
├── Evaluation.yml
├── Model.py
├── UnNormalize.py
└── Synthesis_demo.ipynb
Config.ymltrains the baselineUNetpp5model.Config_GAN.ymltrains a GAN with the same generator plus a 3D discriminator.Prediction.ymlruns inference for both the baseline checkpoint and the generator stored inside a GAN checkpoint.Evaluation.ymlevaluates predicted CT volumes against the reference CT.Model.pydefines the local model classes loaded throughclasspath.UnNormalize.pycontains a local transform used during prediction.
Expected dataset layout¶
Dataset/
├── CASE_001/
│ ├── MR.mha
│ ├── CT.mha
│ └── MASK.mha
└── ...
The example uses these groups:
MR: model inputCT: target imageMASK: mask used by preprocessing and masked metrics
Baseline workflow¶
Run all commands from examples/Synthesis.
Train:
konfai TRAIN -y --gpu 0 --config Config.yml
Predict:
konfai PREDICTION -y --gpu 0 --config Prediction.yml \
--models Checkpoints/TRAIN_01/<checkpoint>.pt
Evaluate:
konfai EVALUATION -y --config Evaluation.yml
Outputs are written to:
Checkpoints/TRAIN_01/Statistics/TRAIN_01/Predictions/TRAIN_01/Evaluations/TRAIN_01/
GAN workflow¶
Config_GAN.yml shows a more advanced graph:
a 2D / 2.5D generator
a 3D discriminator
a global dataset patch for the whole GAN
a second internal patch for the generator
This is not an undocumented convention: it follows the model graph defined in
examples/Synthesis/Model.py.
Why there are two patch levels¶
The GAN example uses two distinct patch scopes:
Trainer.Dataset.Patch: extracts the global 3D chunk seen by the GANTrainer.Model.Gan.UNetpp5.Patch: extracts the internal 2D/2.5D slices seen by the generator
This lets the generator operate slice-wise with local context while the discriminator still judges a reconstructed 3D patch.
What ;accu; means in this example¶
The output key Generator_A_to_B:;accu;Head:Tanh refers to the generator output
before patch reassembly. It is used for the generator-side reconstruction
loss.
By contrast, Discriminator_pB:Head:Conv sees the reassembled 3D fake patch and
is therefore the right place for the adversarial loss.
This behavior is inferred directly from the shipped model graph and the way
KonfAI’s accumulation path is used in Config_GAN.yml.
What to adapt first¶
When adapting this example to your own project, change these sections first:
dataset_filenamesinput and target groups
preprocessing transforms
patch sizes
losses and metrics
train_namelocal model definitions in
Model.pyif the built-in modules are not enough