Release for synthetic-data training and 3D axon segmentation.
- Primary: three-class MONAI 3D U-Net predicting background, axon shell, and axon interior. Shell and interior probabilities are collapsed for binary foreground evaluation.
- Ablation: the supported original binary MONAI 3D U-Net.
- Baselines: a domain-calibrated normalized-intensity threshold and a calibrated bright-only Frangi filter (
black_ridges=false).
Thresholds, Frangi parameters, patch splits, and portable path templates are fixed in paper_analysis/config/lsm_12patch.json.
- Generate geometry:
datagen/run/128/gen_labels_array.sbatchcreates the deterministic dense label/probability corpus. - Train and validate:
run/production/train_three_class_v2.sbatchlaunches the primary recipe.train.pyperforms validation, best-checkpoint selection, periodic checkpointing, and resume handling. - Prepare and infer:
inference/prepare_lsm_full.pyconverts anisotropic source NIfTIs to model space, andinference/infer_lsm.pyorrun/production/infer_lsm.sbatchruns a checkpoint. - Evaluate:
paper_analysis/metrics.pyprovides reusable binary-mask metrics.run/paper/applies them in the fixed 12-patch paper workflow.
Training does not require pre-generated intensity images. It reads stored dense
label/probability pairs and synthesizes images and targets into RAM caches;
training caches are refreshed periodically while the validation cache remains
fixed. The original binary ablation is in run/ablations/, and lightweight
checks are in run/smoke/ and tests/.
Create the CUDA training and inference environment with:
conda env create -f environment.yml
conda activate axonsynthThe smaller CPU analysis environment is defined in paper_analysis/environment.yml. Set site paths with DATA_ROOT and OUTPUT_ROOT; config/site.example.env documents the local variables.
Training uses only synthetic data. Activate the axonsynth environment, set
your paths, and submit jobs from the repository root. Add -p <partition> or
other site options to sbatch as needed.
cp config/site.example.env config/site.env # edit the paths
source config/site.env1. Generate labels (once). Each array task writes one 128³ label and
probability volume at 0.8 µm, seeded with 42000 + id:
sbatch --array=0-499%50 datagen/run/128/gen_labels_array.sbatchVolumes are written to ${DENSE_LABEL_ROOT}/train. Training uses
vol0000–vol0099 for validation and vol0100–vol0499 for training.
2. Smoke test. One epoch on two volumes, in both modes:
OUTPUT_DIR=/path/to/smoke sbatch run/smoke/train_modes_smoke.sbatch3. Train the three-class model:
OUTPUT_DIR=/path/to/run sbatch run/production/train_three_class_v2.sbatchThe script contains the full recipe: 200 epochs, batch size 2, learning rate 1e-4, 800 synthetic training samples per cache, and a new cache every 3 epochs. It requests one GPU, 50 CPUs, 256 GB RAM, and 48 h. The released model took about 100 GPU-hours on one NVIDIA L40S. Most of that time is image synthesis: each cache takes about 78 min to build, while an epoch of gradient updates takes under a minute.
A full run needs about three submissions. Resubmit the same command with the
same OUTPUT_DIR; training resumes from the last completed epoch and stops if
the arguments have changed. Use a new OUTPUT_DIR for a new run. Logs are
written to local/logs/.
Outputs in OUTPUT_DIR:
checkpoints/best_model.pt: best score on the fixed synthetic validation set (mean of foreground, shell, and interior Dice). Use this checkpoint for inference. The released model is epoch 136.checkpoints/last_state.ptandcheckpoints/epoch_XXXX.pt(every 10 epochs): resume points.tensorboard/: losses, validation scores, and preview images.
No real images are used for training or checkpoint selection. The binary
ablation follows the same steps with run/ablations/train_binary_baseline.sbatch;
its released checkpoint is checkpoints/best_model_ep200.pt.
The model expects isotropic model-order input. Prepare anisotropic NIfTI data
before inference; --assume-source-units-micron is required when a source
header does not declare micron units:
python inference/prepare_lsm_full.py \
--input source.nii.gz \
--output prepared_0p8um.nii.gz \
--target-spacing 0.8 \
--axis-order 2 0 1 \
--assume-source-units-micronFor fields that exceed GPU stitching memory, keep the normalized volume and stitched logits on CPU while running model windows on CUDA:
python inference/infer_lsm.py \
--input prepared_0p8um.nii.gz \
--checkpoint best_model.pt \
--output-dir predictions \
--segmentation-mode three_class_shell_interior \
--stitch-device cpu \
--output-profile binary_focused \
--no-save-input \
--threshold 0.5 \
--additional-threshold 0p94=0.94 \
--require-cudaUse --no-save-input when the normalized input volume does not need to be
retained. Normalization and Gaussian logit blending remain global over the
prepared field. Do not infer independent outer tiles and merge their
probabilities.
paper_analysis/metrics.py is independent of the paper cohort and accepts any
matching 3D binary prediction and target arrays:
from paper_analysis.metrics import evaluate_binary_mask
results = evaluate_binary_mask(prediction, target)It reports voxel, topology, and connected-component metrics. See
tests/test_metrics.py for small examples. In contrast,
paper_analysis/evaluate_lsm.py is the reproducibility runner for the 12
patches and four methods defined in paper_analysis/config/lsm_12patch.json;
it expects predictions to have already been generated. New labeled datasets
can use inference/infer_lsm.py and import evaluate_binary_mask directly.
Use local/sbatch/ for temporary Slurm scripts and local/logs/ for scheduler
output. Their contents are ignored by Git. Submit the tracked Slurm scripts
from the repository root so their configured log paths resolve correctly.
The pretrained three-class checkpoint is available on Hugging Face at lincbrain/axonsynth:
hf download lincbrain/axonsynth best_model.pt --local-dir weightsIf you use AxonSynth, please cite:
Gaibor E, Bintsi KM, Mauri C, Leiva Ureta CL, Bellatif Z, Maffei C, Li W, Hillman E, Balbastre Y, Yendiki A. AxonSynth: Domain-Randomized Synthetic Data for Zero-Shot 3D Axon Segmentation in Light-Sheet Microscopy. arXiv:2609.31431, 2026. https://arxiv.org/abs/2609.31431