nv-segment-ct-finetune
Original:🇺🇸 English
Translated
2 scripts
Used for smoke or dataset finetuning of NV-Segment-CT VISTA3D on CT NIfTI labels. Not for clinical validation.
3installs
Sourcenvidia/skills
Added on
NPX Install
npx skill4agent add nvidia/skills nv-segment-ct-finetuneTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →NV-Segment-CT Finetune
Purpose
- Used for smoke or dataset finetuning of NV-Segment-CT VISTA3D on CT NIfTI labels. Not for clinical validation.
- Wraps the upstream MONAI bundle entrypoint; do not replace it with handwritten training or inference code.
- Manifest inputs are ,
dataset_dir,datalist,target_anatomy,label_mapping,smoke,sanity, andauto_seg.skip_formal_eval - Manifest outputs are and schema-checked
finetuned_ckpt.result_json
Instructions
- Run ; do not patch files under
scripts/run_finetune.pyor upstream checkouts during normal skill use.bundle/ - For standalone Bash, include the fresh-environment setup line before the wrapper; benchmark venvs start empty.
- Run the committed script in place from the repo root. Do not copy this skill to a runtime directory, and do not use or cleanup commands in generated invocations.
rm - If a host exposes , use
run_script; otherwise run from the repo root.run_script("scripts/run_finetune.py", args=[...]) - For the shortest workflow check, use ; for MSD Task06 Lung Tumor reproduction, use
--smoke.--sanity - Read only when you need Task06 reference details, output-field definitions, or manual bundle setup notes.
references/task06-and-results.md
Available Scripts
| Script | Purpose | Arguments |
|---|---|---|
| Primary entrypoint declared by | |
Prerequisites
- Python 3.10+ with CUDA-capable Torch for GPU runs.
- Runtime packages from , especially
skill_manifest.yaml,monai==1.4.0,numpy<2,nibabel,scipy,typer,PyYAML,fire,pytorch-ignite, andeinops.huggingface_hub - Optional environment variables: restricts visible GPUs;
CUDA_VISIBLE_DEVICESoverrides GPU count and valuesNPROC_PER_NODEselect multi-GPU mode for non-sanity runs.>=2 - Side effects: writes generated bundle configs under , including
skills/nv-segment-ct-finetune/bundle/configs/,skills/nv-segment-ct-finetune/bundle/configs/auto_override.json, andskills/nv-segment-ct-finetune/bundle/configs/train_continual_task06_lung.json; writes checkpoints/evidence underskills/nv-segment-ct-finetune/bundle/configs/dfw_no_logging.json, may cache model assets under--output-dir, and may contact~/.cache/huggingface/orhttps://huggingface.co.https://raw.githubusercontent.com
Fresh environment setup:
bash
python -m pip install "monai==1.4.0" "numpy<2" pytorch-ignite einops nibabel scipy typer PyYAML fire huggingface_hubKnown upstream compatibility constraints:
- DFW Task06 reference: Python , MONAI
3.10.16, Torch1.4.0.2.7.0+cu126 - Use exact for smoke, sanity, and evidence runs; MONAI 1.5.x can crash the upstream finetune loss on boolean labels.
monai==1.4.0 - Do not float the dependency as in generated commands.
monai>=1.4,<1.6
Usage
Smoke-scale workflow check:
bash
python -m pip install "monai==1.4.0" "numpy<2" pytorch-ignite einops nibabel scipy typer PyYAML fire huggingface_hub && \
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
PATH_TO_DATASET \
--smoke \
--patch-size '[64,64,64]' \
--output-dir runs/nvseg_smokeUse the staged dataset as . For the micro fixture, use . Smoke mode proves wiring, config generation, checkpoint loading, and runtime compatibility; it is not a quality bar.
PATH_TO_DATASETskills/nv-segment-ct-finetune/fixtures/spleen_microMSD Task06 Lung Tumor sanity reproduction:
bash
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
/path/to/Task06 \
--sanity \
--output-dir runs/nvseg_task06_sanityThe sanity preset follows the single-GPU DFW recipe: fold-0 validation, label mapping for , automatic class-prompt segmentation, patch , 5 epochs, and original-spacing scoring before and after training. Expected reference range is pretrained Dice about , training-best Dice about , and fine-tuned formal Dice about .
[[1, 23]]lung tumor[128,128,128]configs/evaluate.json0.66970.69050.6836User-data finetune:
bash
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
--dataset-dir /path/to/dataset \
--datalist /path/to/datalist.json \
--target-anatomy "lung tumor" \
--auto-seg \
--epochs 5 \
--patch-size '[128,128,128]' \
--output-dir runs/nvseg_user_finetuneUse when local label values are custom or the anatomy name is ambiguous.
--label-mapping '[[1, 23]]'Examples
Smoke run on a staged tiny dataset:
bash
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
runs/with_vs_without_nv/_inputs/nv_segment_ct_finetune/input_dataset \
--smoke \
--patch-size '[64,64,64]' \
--output-dir runs/nvseg_smokeTask06 sanity run on a local MSD cache:
bash
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
.workbench_data/datasets/Task06_Lung \
--sanity \
--output-dir runs/nvseg_task06_sanityData Contract
- Preferred layout: and
dataset/imagesTr/*.nii.gz.dataset/labelsTr/*.nii.gz - Labels must align one-to-one with images by basename.
- The target label value must be present in the training labels.
- Use a datalist when patient-level splitting matters. The bundle default is
fold, so0entries are validation and all other folds are training.fold: 0 - Every trained foreground label must map to an existing VISTA3D global class id from ; this skill cannot invent a new class.
bundle/label_dict.json
Results
Check in the run directory first:
output.json- and
formal_pretrained_val_dice: original-spacing pre/post scores when formal eval is enabled.formal_finetuned_val_dice - ,
training_start_val_dice, andval_dice_per_epoch: training-time validation trace.training_best_val_dice - : detects the epoch-0 checkpoint trap when
finetuned_ckpt_matches_pretrained_weights.val_at_start=true - : checkpoint to keep. Do not blindly use the last epoch or
recommended_ckpt.model_finetune.pt - ,
runtime.oom, and phase logs: distinguish OOM, slow validation, and process failure.runtime.peak_gpu_mb
Decision rule: prefer formal original-spacing pre/post scores when present; reject tensor-identical "fine-tuned" checkpoints for sanity recovery; treat as valid evidence rather than a wrapper failure.
improved: falseLimitations
- Thin wrapper. Training, validation, transforms, and checkpointing are delegated to the upstream bundle in .
bundle/ - The auto-derived plan is heuristic; caller-provided ,
--patch-size,--cache-rate, and--epochswin.--learning-rate - The Task06 sanity recipe intentionally forces single-GPU execution to match the DFW reference. Multi-GPU mode for other datasets requires host support.
torchrun - The paired verifier is CPU-only and audits the evidence pack; it does not re-run GPU segmentation.
- Not for clinical deployment, clinical interpretation, autonomous diagnosis, or regulatory submission.
Troubleshooting
| Error | Cause | Fix |
|---|---|---|
| Missing dependency or import error | Runtime drift from | Install the packages above or use the documented environment. |
| Low Task06 pretrained Dice | Wrong config, wrong checkpoint, data split drift, or dependency drift. | Compare environment fields and staged configs before changing training logic. |
| | Use |
| Missing formal Dice fields | Formal eval failed or was skipped. | Inspect |
| GPU out of memory | Patch/cache settings too large. | Reduce |
| No validation cases | Datalist lacks | Provide at least one validation entry. |
Verification
Run the implemented verifier when quality gates matter:
bash
python -m eval_engine.run_trusted skills/nv-segment-ct-finetune \
--fixture skills/nv-segment-ct-finetune/fixtures/spleen_micro \
--out runs/nvseg_trusted