Agent Skill · NVIDIA NIM

nv-segment-ct-finetune

Used for smoke or dataset finetuning of NV-Segment-CT VISTA3D on CT NIfTI labels. Not for clinical validation.

Provider: NVIDIA NIM Path in repo: skills/nv-segment-ct-finetune/SKILL.md

Skill body

NV-Segment-CT Finetune

Purpose

Instructions

Available Scripts

Script Purpose Arguments
scripts/run_finetune.py Primary entrypoint declared by skill_manifest.yaml; stages configs, runs MONAI, and writes output.json. [FIXTURE_OR_DATASET] --output-dir OUT_DIR [--smoke] [--sanity] [--auto-seg] [--dataset-dir DIR] [--datalist JSON] [--target-anatomy TEXT] [--label-mapping JSON] [--patch-size JSON]

Prerequisites

Fresh environment setup:

python -m pip install "monai==1.4.0" "numpy<2" pytorch-ignite einops nibabel scipy typer PyYAML fire huggingface_hub

Known upstream compatibility constraints:

Usage

Smoke-scale workflow check:

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_smoke

Use the staged dataset as PATH_TO_DATASET. For the micro fixture, use skills/nv-segment-ct-finetune/fixtures/spleen_micro. Smoke mode proves wiring, config generation, checkpoint loading, and runtime compatibility; it is not a quality bar.

MSD Task06 Lung Tumor sanity reproduction:

python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
  /path/to/Task06 \
  --sanity \
  --output-dir runs/nvseg_task06_sanity

The sanity preset follows the single-GPU DFW recipe: fold-0 validation, label mapping [[1, 23]] for lung tumor, automatic class-prompt segmentation, patch [128,128,128], 5 epochs, and original-spacing configs/evaluate.json scoring before and after training. Expected reference range is pretrained Dice about 0.6697, training-best Dice about 0.6905, and fine-tuned formal Dice about 0.6836.

User-data finetune:

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_finetune

Use --label-mapping '[[1, 23]]' when local label values are custom or the anatomy name is ambiguous.

Examples

Smoke run on a staged tiny dataset:

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_smoke

Task06 sanity run on a local MSD cache:

python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
  .workbench_data/datasets/Task06_Lung \
  --sanity \
  --output-dir runs/nvseg_task06_sanity

Data Contract

Results

Check output.json in the run directory first:

Decision rule: prefer formal original-spacing pre/post scores when present; reject tensor-identical “fine-tuned” checkpoints for sanity recovery; treat improved: false as valid evidence rather than a wrapper failure.

Limitations

Troubleshooting

Error Cause Fix
Missing dependency or import error Runtime drift from skill_manifest.yaml. 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.
model_finetune.pt matches pretrained val_at_start=true selected epoch 0 as best. Use recommended_ckpt; treat sanity recovery as failed unless a changed checkpoint improves formal Dice.
Missing formal Dice fields Formal eval failed or was skipped. Inspect eval_pretrained.log, eval_finetuned.log, and metrics.csv.
GPU out of memory Patch/cache settings too large. Reduce --patch-size, lower --cache-rate, or reduce workers.
No validation cases Datalist lacks fold: 0. Provide at least one validation entry.

Verification

Run the implemented verifier when quality gates matter:

python -m eval_engine.run_trusted skills/nv-segment-ct-finetune \
  --fixture skills/nv-segment-ct-finetune/fixtures/spleen_micro \
  --out runs/nvseg_trusted

Skill frontmatter

license: Apache-2.0 allowed-tools: Bash metadata: {"author" => "NVIDIA MedTech Team", "tags" => ["MedTech", "CT", "finetuning", "segmentation"]}