nv-generate-ct-rflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNV-Generate-CT (rflow-ct)
NV-Generate-CT (rflow-ct)
Purpose
用途
- Used for generating synthetic CT volumes and masks with NV-Generate-CTMR rflow-ct. Not for production training data without review.
- Use the wrapper exactly as documented; do not replace the upstream entrypoint with a handwritten implementation.
- Do not write custom inference code for normal runs. The wrapper owns config staging, output paths, label mapping evidence, and validation.
- Manifest I/O: inputs are ; outputs are
config_infer_overrideandsynthetic_ct_volumes.result_json
- 用于通过NV-Generate-CTMR rflow-ct生成合成CT体和掩码。未经审核不得用于生产训练数据。
- 严格按照文档说明使用封装器;请勿用手写实现替换上游入口点。
- 正常运行时请勿编写自定义推理代码。封装器负责配置暂存、输出路径、标签映射验证和校验。
- 清单输入输出:输入为;输出为
config_infer_override和synthetic_ct_volumes。result_json
Instructions
使用说明
- Read before changing arguments, side effects, or validation gates.
skill_manifest.yaml - Run through the documented command below; keep outputs under a caller-provided run directory.
scripts/run_rflow_ct.py - If a host agent exposes , use
run_script; otherwise run the Bash/Python command shown below.run_script("scripts/run_rflow_ct.py", args=[...]) - Emit a single bash code block, and keep the step in that same command — the runtime may be a fresh environment without
python -m pip install -r "$NV_GENERATE_ROOT/requirements.txt"/MONAI, so dropping the install fails withnibabel.ModuleNotFoundError - Do not add ,
rm, or any cleanup ofmkdir; the wrapper creates it. Use a fresh--output-dirinstead of deleting one.--output-dir - Check the emitted JSON and paired verifier guidance before treating the run as evidence.
- 在修改参数、副作用或校验规则前,请先阅读。
skill_manifest.yaml - 通过下方文档记录的命令运行;将输出保存在调用方提供的运行目录下。
scripts/run_rflow_ct.py - 如果主机Agent暴露接口,请使用
run_script;否则运行下方所示的Bash/Python命令。run_script("scripts/run_rflow_ct.py", args=[...]) - 输出单个bash代码块,并保留步骤——运行环境可能是未安装
python -m pip install -r "$NV_GENERATE_ROOT/requirements.txt"/MONAI的全新环境,省略安装步骤会导致nibabel错误。ModuleNotFoundError - 请勿添加、
rm或任何清理mkdir的操作;封装器会自动创建该目录。请使用全新的--output-dir而非删除已有目录。--output-dir - 在将运行结果作为有效证据前,请检查输出的JSON文件及配套验证器指南。
Available Scripts
可用脚本
| Script | Purpose | Arguments |
|---|---|---|
| Internal helper used by the primary entrypoint. | Imported only; do not call directly. |
| Internal helper used by the primary entrypoint. | Imported only; do not call directly. |
| Helper command for catalog or anatomy lookup. | |
| Primary entrypoint declared by skill_manifest.yaml. | |
| Advanced diagnostic helper for standalone raw MAISI mask generation. | |
| Advanced helper for CT image generation from a MAISI label mask. | |
| Advanced helper for CT image-only generation without paired labels. | |
| 脚本 | 用途 | 参数 |
|---|---|---|
| 主入口点使用的内部辅助工具 | 仅用于导入;请勿直接调用。 |
| 主入口点使用的内部辅助工具 | 仅用于导入;请勿直接调用。 |
| 用于目录或解剖结构查询的辅助命令 | |
| | |
| 用于独立生成原始MAISI掩码的高级诊断辅助工具 | |
| 用于从MAISI标签掩码生成CT图像的高级辅助工具 | |
| 用于仅生成CT图像(无配对标签)的高级辅助工具 | |
Prerequisites
前置条件
- Required environment variables: .
NV_GENERATE_ROOT - Runtime requirements: GPU/CUDA when declared by the manifest; Python packages listed in .
runtime.side_effects.pip_packages - Side effects: writes generated outputs under the caller's , may cache model assets under
--output-dir, and may contact~/.cache/huggingface/orhttps://huggingface.coduring setup.https://github.com - Run commands from the repository root unless an existing section below says otherwise.
- 必填环境变量:。
NV_GENERATE_ROOT - 运行时要求:清单声明时需GPU/CUDA;需安装中列出的Python包。
runtime.side_effects.pip_packages - 副作用:在调用方指定的下写入生成的输出,可能在
--output-dir下缓存模型资产,且在设置过程中可能访问~/.cache/huggingface/或https://huggingface.co。https://github.com - 除非下方已有章节说明,否则请从仓库根目录运行命令。
Limitations
局限性
- This is a thin wrapper. Inference, sampling, and decoding are delegated entirely to NVIDIA-Medtech/NV-Generate-CTMR's . Do not modify code under $NV_GENERATE_ROOT.
scripts.inference - rflow-ct requires CUDA and ≈ 16 GB VRAM minimum for the default 256³ output_size. Larger output_size (e.g. 512×512×768) needs an A100/H100.
- Output volumes are synthetic. They are not safe to use as training data for production medtech models without an independent quality review.
- Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission.
- 这是一个轻量封装器。推理、采样和解码完全委托给NVIDIA-Medtech/NV-Generate-CTMR的。请勿修改
scripts.inference下的代码。$NV_GENERATE_ROOT - rflow-ct需要CUDA,且默认256³输出大小至少需要≈16 GB显存。更大的输出大小(如512×512×768)需要A100/H100显卡。
- 输出体是合成数据。未经独立质量审核,不得将其用作医疗科技生产模型的训练数据。
- 不得用于临床部署、临床解读、自主诊断或监管申报。
Troubleshooting
故障排查
| Error | Cause | Fix |
|---|---|---|
| Missing dependency or import error | Runtime package drift from | Install the packages declared in the manifest or use the documented setup command. |
| Empty or schema-invalid output | Wrong input path, unsupported modality, or upstream failure. | Re-run with a known fixture and inspect the wrapper JSON plus stderr. |
| Validation gate failure | Output violated a declared engineering invariant. | Keep the failed evidence pack and use the gate message to repair inputs or wrapper code. |
Wraps the upstream
rectified-flow synthesis pipeline. The wrapper does not reimplement diffusion,
sampling, or autoencoder decoding — it shells out to the upstream
entry point exactly as the project's README documents and
inspects the produced image/mask pairs.
NVIDIA-Medtech/NV-Generate-CTMRscripts.inference| 错误 | 原因 | 解决方法 |
|---|---|---|
| 依赖缺失或导入错误 | 运行时包与 | 安装清单中声明的包,或使用文档记录的设置命令。 |
| 输出为空或不符合Schema | 输入路径错误、模态不支持或上游运行失败。 | 使用已知测试用例重新运行,并检查封装器JSON文件及stderr输出。 |
| 校验规则失败 | 输出违反了已声明的工程约束。 | 保留失败的证据包,并根据规则提示修复输入或封装器代码。 |
本工具封装了上游
的整流流合成流水线。封装器未重新实现扩散、采样或自动编码器解码——它完全按照项目README文档的说明调用上游入口点,并检查生成的图像/掩码对。
NVIDIA-Medtech/NV-Generate-CTMRscripts.inferencePreconditions
前置准备
-
Clone the upstream repo and pointat it (one-time):
NV_GENERATE_ROOTbashtest -d "$HOME/nv-generate-ctmr/.git" || \ git clone https://github.com/NVIDIA-Medtech/NV-Generate-CTMR.git $HOME/nv-generate-ctmr export NV_GENERATE_ROOT=$HOME/nv-generate-ctmr pip install -r "$NV_GENERATE_ROOT/requirements.txt" -
Download theweights and the mask-candidate datasets into the clone (one-time, ≈ 5.5 GB):
rflow-ctbashcd "$NV_GENERATE_ROOT" python -m scripts.download_model_data --version rflow-ct --root_dir "./"The mask candidates () condition the diffusion sampler; omitting them viadatasets/all_masks_flexible_size_and_spacing_4000will make the inference script fail with a missing-file error at startup. The anatomy-size condition file is also part of the full CT download and is needed for controllable mask generation.--model_only -
NVIDIA GPU with ≥ 16 GB VRAM and CUDA. There is no CPU fallback.
For agent-generated user run commands, prefer the short wrapper command in
Usage. Do not prepend clone or model-download setup steps when
or the repo-local upstream cache is already present. In a fresh Python
environment, still include
before the wrapper unless the active environment has already proven those
imports are available; cached weights do not imply cached Python packages. Run
the wrapper from the medical-AI-skills repo root. If setup requires , return to the Medical AI Skills repo before invoking
.
NV_GENERATE_ROOTpip install -r "$NV_GENERATE_ROOT/requirements.txt"cd "$NV_GENERATE_ROOT"skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py-
克隆上游仓库并将指向该仓库(仅需一次):
NV_GENERATE_ROOTbashtest -d "$HOME/nv-generate-ctmr/.git" || \ git clone https://github.com/NVIDIA-Medtech/NV-Generate-CTMR.git $HOME/nv-generate-ctmr export NV_GENERATE_ROOT=$HOME/nv-generate-ctmr pip install -r "$NV_GENERATE_ROOT/requirements.txt" -
将权重以及掩码候选数据集下载到克隆的仓库中(仅需一次,约5.5 GB):
rflow-ctbashcd "$NV_GENERATE_ROOT" python -m scripts.download_model_data --version rflow-ct --root_dir "./"掩码候选数据集()用于约束扩散采样器;如果通过datasets/all_masks_flexible_size_and_spacing_4000参数省略该数据集,推理脚本会在启动时因文件缺失而失败。解剖结构大小条件文件也是完整CT下载的一部分,是可控掩码生成所必需的。--model_only -
配备≥16 GB显存和CUDA的NVIDIA GPU。无CPU fallback方案。
对于Agent生成的用户运行命令,优先使用用法说明中的简短封装器命令。当或仓库本地上游缓存已存在时,请勿添加克隆或模型下载的设置步骤。在全新Python环境中,除非当前环境已确认相关导入可用,否则仍需在封装器命令前包含;缓存的权重并不意味着缓存了Python包。请从medical-AI-skills仓库根目录运行封装器。如果设置需要,请在调用前返回Medical AI Skills仓库。
NV_GENERATE_ROOTpip install -r "$NV_GENERATE_ROOT/requirements.txt"cd "$NV_GENERATE_ROOT"skills/nv-generate-ct-rflow/scripts/run_rflow_ct.pyUsage
使用示例
bash
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/nv-generate-ctmr}" && \
python -m pip install -r "$NV_GENERATE_ROOT/requirements.txt" && \
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py \
PATH_TO_CONFIG_INFER.json \
--output-dir runs/nv_generate_ct_rflow_demo \
--random-seed 0 \
--version rflow-ctReplace with the user's actual request/config
path. Do not copy the fixture path from this document unless the user
explicitly asked to run that fixture. If the user says "the case request is at
", that exact path is the first
positional argument to .
PATH_TO_CONFIG_INFER.jsonruns/.../chest_lung_tumor_controllable.jsonscripts/run_rflow_ct.pyThe fixture argument is a override file: it can replace
, , , ,
, and . Pass to use the upstream config
verbatim. The wrapper stages the override into the upstream tree before
running.
config_infer.jsonnum_output_samplesbody_regionanatomy_listcontrollable_anatomy_sizeoutput_sizespacingdefaultbash
export NV_GENERATE_ROOT="${NV_GENERATE_ROOT:-$HOME/nv-generate-ctmr}" && \
python -m pip install -r "$NV_GENERATE_ROOT/requirements.txt" && \
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py \
PATH_TO_CONFIG_INFER.json \
--output-dir runs/nv_generate_ct_rflow_demo \
--random-seed 0 \
--version rflow-ct将替换为用户实际的请求/配置路径。除非用户明确要求运行测试用例,否则请勿复制本文档中的测试用例路径。如果用户表示"病例请求位于",则该精确路径即为的第一个位置参数。
PATH_TO_CONFIG_INFER.jsonruns/.../chest_lung_tumor_controllable.jsonscripts/run_rflow_ct.py测试用例参数是一个覆盖文件:它可以替换、、、、和。传入即可直接使用上游配置。封装器会在运行前将覆盖配置暂存到上游目录中。
config_infer.jsonnum_output_samplesbody_regionanatomy_listcontrollable_anatomy_sizeoutput_sizespacingdefaultFixture catalog
测试用例目录
fixtures/fixtures/README.mdfixtures/fixtures/README.mdHelper commands
辅助命令
bash
undefinedbash
undefinedBrowse the 132-class label_dict grouped by body region.
按身体部位浏览包含132个类别的label_dict。
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --region chest
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --controllable
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --filter tumor
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --region chest
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --controllable
python skills/nv-generate-ct-rflow/scripts/list_anatomies.py --filter tumor
Validate a fixture and preview cost without launching inference.
验证测试用例并预估成本,无需启动推理。
NV_GENERATE_ROOT=$HOME/nv-generate-ctmr
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py
skills/nv-generate-ct-rflow/fixtures/abdomen_liver_spleen.json
--output-dir runs/preview --preflight-only
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py
skills/nv-generate-ct-rflow/fixtures/abdomen_liver_spleen.json
--output-dir runs/preview --preflight-only
Advanced helpers stay inside this skill for debugging and less-common CT
generation modes. Use them only when the user explicitly asks for that mode:
```bashNV_GENERATE_ROOT=$HOME/nv-generate-ctmr
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py
skills/nv-generate-ct-rflow/fixtures/abdomen_liver_spleen.json
--output-dir runs/preview --preflight-only
python skills/nv-generate-ct-rflow/scripts/run_rflow_ct.py
skills/nv-generate-ct-rflow/fixtures/abdomen_liver_spleen.json
--output-dir runs/preview --preflight-only
高级辅助工具用于调试和较不常见的CT生成模式,仅当用户明确要求该模式时才使用:
```bashRaw MAISI mask diagnostic, useful for checking lung tumor -> label 23.
原始MAISI掩码诊断,用于检查肺肿瘤->标签23。
python skills/nv-generate-ct-rflow/scripts/run_ct_mask.py
skills/nv-generate-ct-rflow/fixtures/ct_mask_lung_tumor.json
--output-dir runs/ct_mask_debug --preflight-only
skills/nv-generate-ct-rflow/fixtures/ct_mask_lung_tumor.json
--output-dir runs/ct_mask_debug --preflight-only
python skills/nv-generate-ct-rflow/scripts/run_ct_mask.py
skills/nv-generate-ct-rflow/fixtures/ct_mask_lung_tumor.json
--output-dir runs/ct_mask_debug --preflight-only
skills/nv-generate-ct-rflow/fixtures/ct_mask_lung_tumor.json
--output-dir runs/ct_mask_debug --preflight-only
CT image from an existing MAISI label mask with body label 200.
从现有MAISI标签掩码(身体标签200)生成CT图像。
python skills/nv-generate-ct-rflow/scripts/run_ct_from_mask.py
skills/nv-generate-ct-rflow/fixtures/ct_from_mask_request_example.json
--output-dir runs/ct_from_mask_demo
skills/nv-generate-ct-rflow/fixtures/ct_from_mask_request_example.json
--output-dir runs/ct_from_mask_demo
python skills/nv-generate-ct-rflow/scripts/run_ct_from_mask.py
skills/nv-generate-ct-rflow/fixtures/ct_from_mask_request_example.json
--output-dir runs/ct_from_mask_demo
skills/nv-generate-ct-rflow/fixtures/ct_from_mask_request_example.json
--output-dir runs/ct_from_mask_demo
CT image-only generation without paired labels.
仅生成CT图像(无配对标签)。
python skills/nv-generate-ct-rflow/scripts/run_ct_image.py
skills/nv-generate-ct-rflow/fixtures/ct_image_only_default.json
--output-dir runs/ct_image_only_demo --version rflow-ct
skills/nv-generate-ct-rflow/fixtures/ct_image_only_default.json
--output-dir runs/ct_image_only_demo --version rflow-ct
The wrapper runs preflight on every invocation (regardless of
`--preflight-only`): config-schema bounds, anatomy names matched
against the upstream label_dict, body_region in the supported set,
controllable_anatomy_size constraints, upstream CT output-size/spacing
contracts, body-region-aware x/y FOV minimums, dataset presence under
`$NV_GENERATE_ROOT/datasets/`, CUDA available, and an estimated peak VRAM /
wall-time. Runs estimated to exceed 5 min wall-time or 30 GB VRAM peak require
`--yes` to proceed.
Each invocation runs `python -m scripts.inference -t configs/config_network_rflow.json
-i configs/config_infer.json -e configs/environment_rflow-ct.json --random-seed <s>
--version rflow-ct`. Output evidence records the upstream git commit, model
checkpoint hashes, the rendered config, per-sample image/mask geometry, mask
label set, image HU range summary, and per-class voxel volumes.
When `controllable_anatomy_size` is non-empty, upstream ignores the broader
`anatomy_list` for the saved paired label map and filters labels to the
controllable anatomy names. The saved paired label values are local `1..N`
ordinals, not raw MAISI label IDs. Read `output.output_label_mapping` in
`result_json` to map saved output labels back to source labels; for example,
output label `1` can represent MAISI label `23` (`lung tumor`).
For curated lung-tumor examples, prefer a controllable size around `0.5` or
larger; smaller requests such as `0.2` can produce absent or extremely small
label-23 components for some seeds.
For FOV and setup details, see `references/fov-and-downloads.md`. For
advanced helper label-space details, see
`references/ct-mask-label-space.md` and `references/ct-from-mask-format.md`.python skills/nv-generate-ct-rflow/scripts/run_ct_image.py
skills/nv-generate-ct-rflow/fixtures/ct_image_only_default.json
--output-dir runs/ct_image_only_demo --version rflow-ct
skills/nv-generate-ct-rflow/fixtures/ct_image_only_default.json
--output-dir runs/ct_image_only_demo --version rflow-ct
封装器每次调用都会运行预检(无论是否指定`--preflight-only`):包括配置Schema边界、解剖结构名称与上游label_dict匹配、身体部位在支持范围内、可控解剖结构大小约束、上游CT输出大小/间距约定、身体部位相关的x/y视野最小值、`$NV_GENERATE_ROOT/datasets/`下的数据集存在性、CUDA可用性,以及预估的峰值显存/运行时间。预估运行时间超过5分钟或峰值显存超过30 GB的任务需要添加`--yes`参数才能继续。
每次调用都会运行`python -m scripts.inference -t configs/config_network_rflow.json
-i configs/config_infer.json -e configs/environment_rflow-ct.json --random-seed <s>
--version rflow-ct`。输出证据会记录上游git提交记录、模型检查点哈希、渲染后的配置、每个样本的图像/掩码几何信息、掩码标签集、图像HU范围汇总以及每个类别的体素体积。
当`controllable_anatomy_size`非空时,上游会忽略保存的配对标签映射中更宽泛的`anatomy_list`,并将标签过滤为可控解剖结构名称。保存的配对标签值是本地的`1..N`序数,而非原始MAISI标签ID。请查看`result_json`中的`output.output_label_mapping`,将保存的输出标签映射回源标签;例如,输出标签`1`可以代表MAISI标签`23`(`lung tumor`)。对于curated的肺肿瘤示例,可控大小建议设置为`0.5`或更大;较小的设置(如`0.2`)可能会导致某些随机种子下标签23对应的组件缺失或极小。
关于视野和设置的详细信息,请查看`references/fov-and-downloads.md`。关于高级辅助工具标签空间的详细信息,请查看`references/ct-mask-label-space.md`和`references/ct-from-mask-format.md`。Visual sample card
可视化样本卡片
Alongside the NIfTI pairs, the wrapper writes to the
output directory: a per-sample mid-slice triptych (axial / coronal /
sagittal) with label overlay, plus a table of the rendered config and
verifier-facing aggregates. Lets you eyeball the result without firing
up 3D Slicer. Pass to skip.
summary.html--no-summary-cardAnatomy plausibility (label-set sanity, voxel HU range as CT, image/mask
geometry match, declared output labels present, lung-lobe HU floor) is checked by
.
verifiers/ct_synthesis_quality_v1Not for clinical interpretation, training data for production deployment, or
any non-synthetic-research use.
除了NIfTI对之外,封装器还会在输出目录中写入:每个样本的中切片三联图(轴位/冠状位/矢状位)并叠加标签,以及渲染后的配置和面向验证器的汇总表格。无需启动3D Slicer即可直观查看结果。添加参数可跳过生成该文件。
summary.html--no-summary-card解剖结构合理性(标签集完整性、CT图像的体素HU范围、图像/掩码几何匹配、已声明的输出标签存在性、肺叶HU下限)由进行检查。
verifiers/ct_synthesis_quality_v1不得用于临床解读、生产部署的训练数据或任何非合成研究用途。