nv-segment-ct-finetune
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNV-Segment-CT Finetune
NV-Segment-CT 微调
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
- 用于在CT NIfTI标签上对NV-Segment-CT VISTA3D进行冒烟测试或数据集微调。不用于临床验证。
- 封装上游MONAI bundle入口点;请勿用手写训练或推理代码替代它。
- 清单输入项包括、
dataset_dir、datalist、target_anatomy、label_mapping、smoke、sanity和auto_seg。skip_formal_eval - 清单输出项包括和经过 schema 校验的
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
- 运行;正常使用该技能期间,请勿修改
scripts/run_finetune.py下的文件或上游检出内容。bundle/ - 对于独立Bash环境,在执行包装器前需包含新鲜环境设置命令;基准虚拟环境初始为空。
- 从仓库根目录原地运行已提交的脚本。请勿将此技能复制到运行时目录,且在生成的调用命令中请勿使用或清理命令。
rm - 如果主机提供函数,请使用
run_script;否则从仓库根目录运行。run_script("scripts/run_finetune.py", args=[...]) - 如需最短流程检查,请使用参数;如需复现MSD Task06肺部肿瘤任务,请使用
--smoke参数。--sanity - 仅当需要Task06参考细节、输出字段定义或手动bundle设置说明时,才阅读。
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
- 支持CUDA的Torch环境下的Python 3.10+,用于GPU运行。
- 中指定的运行时包,尤其是
skill_manifest.yaml、monai==1.4.0、numpy<2、nibabel、scipy、typer、PyYAML、fire、pytorch-ignite和einops。huggingface_hub - 可选环境变量:用于限制可见GPU;
CUDA_VISIBLE_DEVICES用于覆盖GPU数量,当值NPROC_PER_NODE时,非sanity运行将启用多GPU模式。>=2 - 副作用:会在下生成bundle配置文件,包括
skills/nv-segment-ct-finetune/bundle/configs/、skills/nv-segment-ct-finetune/bundle/configs/auto_override.json和skills/nv-segment-ct-finetune/bundle/configs/train_continual_task06_lung.json;会在skills/nv-segment-ct-finetune/bundle/configs/dfw_no_logging.json下写入检查点/证据文件,可能在--output-dir下缓存模型资产,且可能连接~/.cache/huggingface/或https://huggingface.co。https://raw.githubusercontent.com
新鲜环境设置命令:
bash
python -m pip install "monai==1.4.0" "numpy<2" pytorch-ignite einops nibabel scipy typer PyYAML fire huggingface_hub已知上游兼容性约束:
- DFW Task06参考环境:Python 、MONAI
3.10.16、Torch1.4.0。2.7.0+cu126 - 冒烟测试、sanity测试和证据运行请使用精确的;MONAI 1.5.x可能会导致上游微调损失在布尔标签上崩溃。
monai==1.4.0 - 在生成的命令中请勿将依赖项设置为。
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]]'冒烟规模流程检查:
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_smoke使用已准备好的数据集作为。如需微型测试数据,请使用。冒烟模式用于验证连接、配置生成、检查点加载和运行时兼容性;不代表质量标准。
PATH_TO_DATASETskills/nv-segment-ct-finetune/fixtures/spleen_microMSD Task06肺部肿瘤sanity复现:
bash
python skills/nv-segment-ct-finetune/scripts/run_finetune.py \
/path/to/Task06 \
--sanity \
--output-dir runs/nvseg_task06_sanitySanity预设遵循单GPU DFW方案:fold-0验证、针对的标签映射、自动类别提示分割、补丁、5个epoch,以及训练前后使用原始间距评分。预期参考范围为预训练Dice约、训练最佳Dice约、微调后正式Dice约。
lung tumor[[1, 23]][128,128,128]configs/evaluate.json0.66970.69050.6836用户数据微调:
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_finetune当本地标签值自定义或解剖结构名称不明确时,请使用。
--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_sanity在已准备好的小型数据集上运行冒烟测试:
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_smoke在本地MSD缓存上运行Task06 sanity测试:
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
- 推荐布局:和
dataset/imagesTr/*.nii.gz。dataset/labelsTr/*.nii.gz - 标签必须与图像按文件名一一对应。
- 目标标签值必须存在于训练标签中。
- 当需要按患者级别拆分时,请使用数据列表。Bundle默认为
fold,因此0的条目为验证集,其他所有fold为训练集。fold: 0 - 每个训练的前景标签必须映射到中已有的VISTA3D全局类别ID;此技能无法创建新类别。
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: false请首先查看运行目录中的:
output.json- 和
formal_pretrained_val_dice:启用正式评估时,原始间距下的训练前后评分。formal_finetuned_val_dice - 、
training_start_val_dice和val_dice_per_epoch:训练期间的验证跟踪数据。training_best_val_dice - :当
finetuned_ckpt_matches_pretrained_weights时,检测epoch-0检查点陷阱。val_at_start=true - :建议保留的检查点。请勿盲目使用最后一个epoch的检查点或
recommended_ckpt。model_finetune.pt - 、
runtime.oom和阶段日志:用于区分内存不足(OOM)、验证缓慢和进程失败。runtime.peak_gpu_mb
决策规则:优先使用已有的正式原始间距训练前后评分;如果sanity恢复时得到与预训练权重完全相同的“微调”检查点,则判定为失败;将视为有效证据,而非包装器故障。
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.
- 轻量包装器。训练、验证、变换和检查点功能均委托给中的上游bundle。
bundle/ - 自动生成的方案为启发式;调用者提供的、
--patch-size、--cache-rate和--epochs优先级更高。--learning-rate - Task06 sanity方案强制使用单GPU执行,以匹配DFW参考结果。其他数据集的多GPU模式需要主机支持。
torchrun - 配对验证器仅支持CPU,用于审计证据包;不会重新运行GPU分割。
- 不适用于临床部署、临床解读、自主诊断或监管提交。
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. |
| 错误 | 原因 | 修复方案 |
|---|---|---|
| 依赖缺失或导入错误 | 运行环境与 | 安装上述指定包或使用文档中说明的环境。 |
| Task06预训练Dice值偏低 | 配置错误、检查点错误、数据拆分偏差或依赖版本偏差。 | 在修改训练逻辑前,先对比环境字段和已准备好的配置。 |
| | 使用 |
| 缺少正式Dice字段 | 正式评估失败或被跳过。 | 检查 |
| GPU内存不足 | 补丁/缓存设置过大。 | 减小 |
| 无验证案例 | 数据列表中缺少 | 至少提供一个验证条目。 |
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当需要质量把关时,运行已实现的验证器:
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