[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79FJFKQMNF4Y6ANTHP2J6G3":3,"skill-same:01M79FJFKQMNF4Y6ANTHP2J6G3":102},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":32,"commitSha":33,"skillDirectory":34,"forksCount":14,"repositoryHtmlUrl":35,"repositoryHomepageUrl":6,"ownerHtmlUrl":36,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":37,"install":38,"resources":51},"01M79FJFKQMNF4Y6ANTHP2J6G3","nv-generate-mr-brain-finetune",null,"Used for finetuning NV-Generate-CTMR MR-brain diffusion UNet from a NIfTI datalist. Not for clinical or production data approval.","Elogic360\u002Fsoftware-factory","Elogic360","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F156535519?v=4","01M74NH3F0RB13PWB7JZDE2V80","elogic360","01M74NH3FPC65082MDZVMFHDM3",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: nv-generate-mr-brain-finetune\ndescription: Used for finetuning NV-Generate-CTMR MR-brain diffusion UNet from a NIfTI datalist. Not for clinical or production data approval.\nlicense: Apache-2.0\nallowed-tools: Bash\nmetadata:\n  author: NVIDIA MedTech Team\n  tags:\n    - MedTech\n    - MRI\n    - brain\n    - finetune\n---\n\n# NV-Generate-MR-Brain-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR `rflow-mr-brain` diffusion UNet from user-supplied NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- The wrapper stages the config glue locally and delegates execution to existing upstream scripts: `scripts.diff_model_create_training_data`, `scripts.diff_model_train`, and optionally `scripts.diff_model_infer`. It does not execute the notebook.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `finetuned_checkpoint`, optional `inference_outputs`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (the same one driven from cell `[10]` of `train_diff_unet_tutorial.ipynb`). The wrapper stages those JSON files for you and exposes the most-tuned fields as CLI flags; the sections below document the fields, their defaults, and how to monitor\u002Ftune a run.\n\n## Instructions\n- Read `skill_manifest.yaml` before changing arguments, side effects, or validation gates.\n- Run `scripts\u002Frun_mr_brain_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_mr_brain_finetune.py\", args=[...])`; otherwise run the Bash\u002FPython command below.\n- Use `--preflight` first when checking a new datalist; remove `--preflight` only when the user explicitly wants to launch GPU finetuning.\n- For a staged preflight input bundle directory, use `BUNDLE\u002Fpreflight_datalist.json` as the datalist and `BUNDLE\u002Fpreflight_dataset` as `--data-base-dir` when those files are present.\n\n## Examples\n\nValidate and stage a preflight finetune check from an input bundle (the recommended first step — no GPU, no training). This is the single canonical command; replace `INPUT_BUNDLE` and `OUT_DIR` with your paths:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri_t1 \\\n  --preflight\n```\n\nFor real GPU finetuning and other variations, see [Usage](#2-usage-one-line-training) below.\n\n## Available Scripts\n| Script | Purpose | Arguments |\n|---|---|---|\n| `scripts\u002Frun_mr_brain_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri_t1] [--num-gpus N] [--no-amp] [--model-config FILE] [--run-inference] [--preflight]` |\n\n## Prerequisites\n- `NV_GENERATE_ROOT` may point to a current checkout of `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` containing `scripts\u002Fdiff_model_create_training_data.py`, `scripts\u002Fdiff_model_train.py`, and `scripts\u002Fdiff_model_infer.py`.\n- If `NV_GENERATE_ROOT` is unset, the wrapper searches `.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR`.\n- `CUDA_VISIBLE_DEVICES` is optional and can be used to select the GPU for real training.\n- Runtime requirements: NVIDIA CUDA GPU for real training, Python packages from the upstream `requirements.txt`, and downloaded MR-brain weights.\n- Side effects: writes staged configs, embeddings, checkpoints, optional inference images, and logs under the caller-provided `--output-dir`; may write model caches under the upstream checkout and `~\u002F.cache\u002Fhuggingface\u002F`; may contact `https:\u002F\u002Fhuggingface.co` for model assets and `https:\u002F\u002Fgithub.com` for the upstream checkout.\n- The datalist is a MONAI-style JSON object with `training[].image` paths relative to `--data-base-dir`. `training[].modality` is optional and defaults to `mri_t1`.\n\n## 1. Config and environment JSON (adapt to your data)\n\nThis is a thin wrapper around the upstream `train_diff_unet_tutorial.ipynb` flow. Each run performs four steps, delegating the heavy lifting to the model author's scripts:\n\n1. **Stage configs** — copy the three config JSONs and rewrite only the run-specific paths and `n_epochs` (notebook cell 15).\n2. `python -m scripts.diff_model_create_training_data` → latent `*_emb.nii.gz` embeddings (cell 17).\n3. **Write embedding sidecars** — a `\u003Cemb>.nii.gz.json` per embedding with `spacing`\u002F`modality` (and body-region indices when the model uses them). This is the one piece of glue that lives in the notebook (cell 19), not in upstream `scripts\u002F`, and `diff_model_train` requires it; the skill owns it.\n4. `python -m scripts.diff_model_train` (cell 21), optionally `python -m scripts.diff_model_infer`.\n\n**Tune by editing the config JSON, not by adding flags.** All training\u002Finference hyperparameters (`lr`, `batch_size`, `cache_rate`, inference `dim`\u002F`spacing`\u002F`num_inference_steps`\u002F`cfg_guidance_scale`, …) live in `config_maisi_diff_model_rflow-mr-brain.json`. Edit the upstream copy, or pass your own with `--model-config FILE` (and `--env-config` \u002F `--model-def` for the other two). The wrapper only ever rewrites the fields below.\n\nEnvironment JSON (`environment_maisi_diff_model_rflow-mr-brain.json`) — fields the wrapper rewrites per run:\n\n| Field | Set from | Notes |\n|---|---|---|\n| `data_base_dir` | `--data-base-dir` | Root for relative `training[].image` paths. |\n| `json_data_list` | your datalist | Staged copy with per-entry `modality` filled in. |\n| `embedding_base_dir`, `model_dir`, `output_dir` | `--output-dir` | Latent embeddings, checkpoints, inference images. |\n| `modality_mapping_path` | upstream | Maps modality name → integer code. |\n| `model_filename` | `--model-filename` | Output checkpoint name (default `diff_unet_3d_rflow-mr-brain_v0.pt`). |\n| `existing_ckpt_filepath` | upstream weights \u002F `--existing-ckpt-filepath` | Starting checkpoint; cleared by `--train-from-scratch`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | VAE used to encode\u002Fdecode latents. |\n\nModel config (`config_maisi_diff_model_rflow-mr-brain.json`) — the only fields the wrapper touches:\n\n| Field | Set from | Default | Notes |\n|---|---|---|---|\n| `diffusion_unet_train.n_epochs` | `--epochs` | `2` (upstream config ships `1000`) | Convenience override (cell 15 does the same); wrapper default is small for verification. |\n| `diffusion_unet_inference.modality` | `--modality` | from `modality_mapping.json` | Kept consistent with the training modality for optional `--run-inference`. |\n\nEverything else in that file (`lr`, `batch_size`, `cache_rate`, the rest of `diffusion_unet_inference`) is left exactly as written — edit the JSON to change it.\n\nRuntime flags (not config fields): `--num-gpus N` (`>1` launches `torch.distributed.run`), `--no-amp` (disable mixed precision, passed through to `diff_model_train`).\n\n`--modality` selects the integer code from `configs\u002Fmodality_mapping.json`. Supported brain values: `mri` (8), `mri_t1` (9, default), `mri_t2` (10), `mri_flair` (11), `mri_swi` (20), and their `*_skull_stripped` variants (29\u002F30\u002F31\u002F32). Per-case `training[].modality` overrides `--modality`. The modality also feeds the step-3 embedding sidecars.\n\nFor an end-to-end reference including example data download and checkpoint loading, see the upstream tutorial `train_diff_unet_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir PATH_TO_INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune \\\n  --epochs 2 \\\n  --modality mri_t1 \\\n  --run-inference\n```\n\nReplace `PATH_TO_DATALIST.json` and `PATH_TO_DATA_ROOT` with the user's actual paths. Do not use the fixture datalist for real training; it is a preflight-only placeholder.\n\n## 3. Monitor training (TensorBoard)\n\n`scripts.diff_model_train` writes TensorBoard event files under the staged `model_dir` (`OUT_DIR\u002Fartifacts\u002Fmodels`). Launch TensorBoard against the output directory and watch the loss curve:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_mr_brain_finetune\u002Fartifacts\n```\n\nThe run summary is written to `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` (checkpoint path, embedding sidecars, inference outputs); the JSON the wrapper prints to stdout mirrors the same paths plus `exit_code` and a `stderr_tail` for quick triage.\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Loss not decreasing \u002F unstable** — lower `diffusion_unet_train.lr` (default `1e-5`) in the model-config JSON, or keep AMP on (default); `--no-amp` is slower but more numerically stable on older GPUs.\n- **Out-of-memory** — keep `diffusion_unet_train.batch_size` at `1` and `cache_rate` at `0` in the config JSON, and confirm the autoencoder\u002FUNet fit your GPU before scaling. Multi-GPU (`--num-gpus N`) shards the batch via `torch.distributed.run`.\n- **Few cases \u002F quick check** — keep `--epochs` small (the wrapper default `2` is for verification, not convergence; the upstream config ships `1000`).\n- **Wrong modality conditioning** — set `--modality` or per-case `training[].modality` to a value present in `configs\u002Fmodality_mapping.json`; a mismatch produces a clear error rather than silently mislabeling latents.\n- **Slow startup on first run** — `diff_model_create_training_data` precomputes latent embeddings once; reuse the same `--output-dir` to avoid recomputing them.\n\n## 5. Evaluate the finetuned model\n\nUse the staged checkpoint (`OUT_DIR\u002Fartifacts\u002Fmodels\u002F\u003Cmodel_filename>`) as the diffusion UNet for generation, then inspect the synthesized volumes:\n\n- Pass `--run-inference` here for a quick built-in sanity render, or\n- Point the [`nv-generate-mr-brain`](..\u002Fnv-generate-mr-brain\u002FSKILL.md) inference skill at the finetuned checkpoint to generate fresh brain MRI volumes for qualitative review.\n\nThis skill gates file accounting and command provenance only — anatomical realism and downstream utility must be judged by a domain expert on the generated images.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with the existing diffusion training scripts. The skill itself stages the required config and datalist glue locally and does not depend on the notebook or PR #33.\n- Full training can be expensive and is not deterministic across hardware, CUDA, and package versions.\n- The wrapper gates file accounting and command provenance, not anatomical realism or downstream model utility.\n- Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission, or production training-data approval.\n\n## Troubleshooting\n| Error | Cause | Fix |\n|---|---|---|\n| `diffusion training scripts were not found` | `NV_GENERATE_ROOT` does not point at a current NV-Generate-CTMR checkout. | Clone or update `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` and set `NV_GENERATE_ROOT`. |\n| `missing datalist image` | `training[].image` paths are not relative to `--data-base-dir` or files are absent. | Fix the datalist or pass the correct data root. |\n| CUDA or MONAI import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` in the selected environment. |\n","# NV-Generate-MR-Brain-Finetune\n\n## Purpose\n- Used for finetuning the NV-Generate-CTMR `rflow-mr-brain` diffusion UNet from user-supplied NIfTI training volumes.\n- Not for clinical interpretation, regulatory use, or approving synthetic data for production training.\n- The wrapper stages the config glue locally and delegates execution to existing upstream scripts: `scripts.diff_model_create_training_data`, `scripts.diff_model_train`, and optionally `scripts.diff_model_infer`. It does not execute the notebook.\n- Manifest I\u002FO: inputs are `datalist` and `data_base_dir`; outputs are `finetuned_checkpoint`, optional `inference_outputs`, and `result_json`.\n- The underlying training contract is the upstream config\u002Fenv JSON (the same one driven from cell `[10]` of `train_diff_unet_tutorial.ipynb`). The wrapper stages those JSON files for you and exposes the most-tuned fields as CLI flags; the sections below document the fields, their defaults, and how to monitor\u002Ftune a run.\n\n## Instructions\n- Read `skill_manifest.yaml` before changing arguments, side effects, or validation gates.\n- Run `scripts\u002Frun_mr_brain_finetune.py` from the Medical AI Skills repo root.\n- If a host agent exposes `run_script`, use `run_script(\"scripts\u002Frun_mr_brain_finetune.py\", args=[...])`; otherwise run the Bash\u002FPython command below.\n- Use `--preflight` first when checking a new datalist; remove `--preflight` only when the user explicitly wants to launch GPU finetuning.\n- For a staged preflight input bundle directory, use `BUNDLE\u002Fpreflight_datalist.json` as the datalist and `BUNDLE\u002Fpreflight_dataset` as `--data-base-dir` when those files are present.\n\n## Examples\n\nValidate and stage a preflight finetune check from an input bundle (the recommended first step — no GPU, no training). This is the single canonical command; replace `INPUT_BUNDLE` and `OUT_DIR` with your paths:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir OUT_DIR \\\n  --modality mri_t1 \\\n  --preflight\n```\n\nFor real GPU finetuning and other variations, see [Usage](#2-usage-one-line-training) below.\n\n## Available Scripts\n| Script | Purpose | Arguments |\n|---|---|---|\n| `scripts\u002Frun_mr_brain_finetune.py` | Primary entrypoint declared by `skill_manifest.yaml`. | `DATALIST.json --data-base-dir DATA_DIR --output-dir OUT_DIR [--epochs N] [--modality mri_t1] [--num-gpus N] [--no-amp] [--model-config FILE] [--run-inference] [--preflight]` |\n\n## Prerequisites\n- `NV_GENERATE_ROOT` may point to a current checkout of `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` containing `scripts\u002Fdiff_model_create_training_data.py`, `scripts\u002Fdiff_model_train.py`, and `scripts\u002Fdiff_model_infer.py`.\n- If `NV_GENERATE_ROOT` is unset, the wrapper searches `.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR`.\n- `CUDA_VISIBLE_DEVICES` is optional and can be used to select the GPU for real training.\n- Runtime requirements: NVIDIA CUDA GPU for real training, Python packages from the upstream `requirements.txt`, and downloaded MR-brain weights.\n- Side effects: writes staged configs, embeddings, checkpoints, optional inference images, and logs under the caller-provided `--output-dir`; may write model caches under the upstream checkout and `~\u002F.cache\u002Fhuggingface\u002F`; may contact `https:\u002F\u002Fhuggingface.co` for model assets and `https:\u002F\u002Fgithub.com` for the upstream checkout.\n- The datalist is a MONAI-style JSON object with `training[].image` paths relative to `--data-base-dir`. `training[].modality` is optional and defaults to `mri_t1`.\n\n## 1. Config and environment JSON (adapt to your data)\n\nThis is a thin wrapper around the upstream `train_diff_unet_tutorial.ipynb` flow. Each run performs four steps, delegating the heavy lifting to the model author's scripts:\n\n1. **Stage configs** — copy the three config JSONs and rewrite only the run-specific paths and `n_epochs` (notebook cell 15).\n2. `python -m scripts.diff_model_create_training_data` → latent `*_emb.nii.gz` embeddings (cell 17).\n3. **Write embedding sidecars** — a `\u003Cemb>.nii.gz.json` per embedding with `spacing`\u002F`modality` (and body-region indices when the model uses them). This is the one piece of glue that lives in the notebook (cell 19), not in upstream `scripts\u002F`, and `diff_model_train` requires it; the skill owns it.\n4. `python -m scripts.diff_model_train` (cell 21), optionally `python -m scripts.diff_model_infer`.\n\n**Tune by editing the config JSON, not by adding flags.** All training\u002Finference hyperparameters (`lr`, `batch_size`, `cache_rate`, inference `dim`\u002F`spacing`\u002F`num_inference_steps`\u002F`cfg_guidance_scale`, …) live in `config_maisi_diff_model_rflow-mr-brain.json`. Edit the upstream copy, or pass your own with `--model-config FILE` (and `--env-config` \u002F `--model-def` for the other two). The wrapper only ever rewrites the fields below.\n\nEnvironment JSON (`environment_maisi_diff_model_rflow-mr-brain.json`) — fields the wrapper rewrites per run:\n\n| Field | Set from | Notes |\n|---|---|---|\n| `data_base_dir` | `--data-base-dir` | Root for relative `training[].image` paths. |\n| `json_data_list` | your datalist | Staged copy with per-entry `modality` filled in. |\n| `embedding_base_dir`, `model_dir`, `output_dir` | `--output-dir` | Latent embeddings, checkpoints, inference images. |\n| `modality_mapping_path` | upstream | Maps modality name → integer code. |\n| `model_filename` | `--model-filename` | Output checkpoint name (default `diff_unet_3d_rflow-mr-brain_v0.pt`). |\n| `existing_ckpt_filepath` | upstream weights \u002F `--existing-ckpt-filepath` | Starting checkpoint; cleared by `--train-from-scratch`. |\n| `trained_autoencoder_path` | upstream weights \u002F `--trained-autoencoder-path` | VAE used to encode\u002Fdecode latents. |\n\nModel config (`config_maisi_diff_model_rflow-mr-brain.json`) — the only fields the wrapper touches:\n\n| Field | Set from | Default | Notes |\n|---|---|---|---|\n| `diffusion_unet_train.n_epochs` | `--epochs` | `2` (upstream config ships `1000`) | Convenience override (cell 15 does the same); wrapper default is small for verification. |\n| `diffusion_unet_inference.modality` | `--modality` | from `modality_mapping.json` | Kept consistent with the training modality for optional `--run-inference`. |\n\nEverything else in that file (`lr`, `batch_size`, `cache_rate`, the rest of `diffusion_unet_inference`) is left exactly as written — edit the JSON to change it.\n\nRuntime flags (not config fields): `--num-gpus N` (`>1` launches `torch.distributed.run`), `--no-amp` (disable mixed precision, passed through to `diff_model_train`).\n\n`--modality` selects the integer code from `configs\u002Fmodality_mapping.json`. Supported brain values: `mri` (8), `mri_t1` (9, default), `mri_t2` (10), `mri_flair` (11), `mri_swi` (20), and their `*_skull_stripped` variants (29\u002F30\u002F31\u002F32). Per-case `training[].modality` overrides `--modality`. The modality also feeds the step-3 embedding sidecars.\n\nFor an end-to-end reference including example data download and checkpoint loading, see the upstream tutorial `train_diff_unet_tutorial.ipynb`.\n\n## 2. Usage (one-line training)\n\nPreflight only:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nPreflight bundle input:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_INPUT_BUNDLE\u002Fpreflight_datalist.json \\\n  --data-base-dir PATH_TO_INPUT_BUNDLE\u002Fpreflight_dataset \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune_preflight \\\n  --preflight\n```\n\nGPU finetuning:\n\n```bash\nexport NV_GENERATE_ROOT=\"${NV_GENERATE_ROOT:-.workbench_data\u002Fupstreams\u002FNV-Generate-CTMR}\" && \\\npython -m pip install -r \"$NV_GENERATE_ROOT\u002Frequirements.txt\" && \\\npython skills\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py \\\n  PATH_TO_DATALIST.json \\\n  --data-base-dir PATH_TO_DATA_ROOT \\\n  --output-dir runs\u002Fnv_generate_mr_brain_finetune \\\n  --epochs 2 \\\n  --modality mri_t1 \\\n  --run-inference\n```\n\nReplace `PATH_TO_DATALIST.json` and `PATH_TO_DATA_ROOT` with the user's actual paths. Do not use the fixture datalist for real training; it is a preflight-only placeholder.\n\n## 3. Monitor training (TensorBoard)\n\n`scripts.diff_model_train` writes TensorBoard event files under the staged `model_dir` (`OUT_DIR\u002Fartifacts\u002Fmodels`). Launch TensorBoard against the output directory and watch the loss curve:\n\n```bash\npython -m pip install tensorboard && \\\ntensorboard --logdir runs\u002Fnv_generate_mr_brain_finetune\u002Fartifacts\n```\n\nThe run summary is written to `OUT_DIR\u002Fartifacts\u002Fworkflow_summary.json` (checkpoint path, embedding sidecars, inference outputs); the JSON the wrapper prints to stdout mirrors the same paths plus `exit_code` and a `stderr_tail` for quick triage.\n\n## 4. Hyperparameter tuning and common pitfalls\n\n- **Loss not decreasing \u002F unstable** — lower `diffusion_unet_train.lr` (default `1e-5`) in the model-config JSON, or keep AMP on (default); `--no-amp` is slower but more numerically stable on older GPUs.\n- **Out-of-memory** — keep `diffusion_unet_train.batch_size` at `1` and `cache_rate` at `0` in the config JSON, and confirm the autoencoder\u002FUNet fit your GPU before scaling. Multi-GPU (`--num-gpus N`) shards the batch via `torch.distributed.run`.\n- **Few cases \u002F quick check** — keep `--epochs` small (the wrapper default `2` is for verification, not convergence; the upstream config ships `1000`).\n- **Wrong modality conditioning** — set `--modality` or per-case `training[].modality` to a value present in `configs\u002Fmodality_mapping.json`; a mismatch produces a clear error rather than silently mislabeling latents.\n- **Slow startup on first run** — `diff_model_create_training_data` precomputes latent embeddings once; reuse the same `--output-dir` to avoid recomputing them.\n\n## 5. Evaluate the finetuned model\n\nUse the staged checkpoint (`OUT_DIR\u002Fartifacts\u002Fmodels\u002F\u003Cmodel_filename>`) as the diffusion UNet for generation, then inspect the synthesized volumes:\n\n- Pass `--run-inference` here for a quick built-in sanity render, or\n- Point the [`nv-generate-mr-brain`](..\u002Fnv-generate-mr-brain\u002FSKILL.md) inference skill at the finetuned checkpoint to generate fresh brain MRI volumes for qualitative review.\n\nThis skill gates file accounting and command provenance only — anatomical realism and downstream utility must be judged by a domain expert on the generated images.\n\n## Limitations\n- Requires a current upstream `NV-Generate-CTMR` checkout with the existing diffusion training scripts. The skill itself stages the required config and datalist glue locally and does not depend on the notebook or PR #33.\n- Full training can be expensive and is not deterministic across hardware, CUDA, and package versions.\n- The wrapper gates file accounting and command provenance, not anatomical realism or downstream model utility.\n- Not for clinical deployment, clinical interpretation, autonomous diagnosis, regulatory submission, or production training-data approval.\n\n## Troubleshooting\n| Error | Cause | Fix |\n|---|---|---|\n| `diffusion training scripts were not found` | `NV_GENERATE_ROOT` does not point at a current NV-Generate-CTMR checkout. | Clone or update `https:\u002F\u002Fgithub.com\u002FNVIDIA-Medtech\u002FNV-Generate-CTMR` and set `NV_GENERATE_ROOT`. |\n| `missing datalist image` | `training[].image` paths are not relative to `--data-base-dir` or files are absent. | Fix the datalist or pass the correct data root. |\n| CUDA or MONAI import failure | Runtime environment lacks upstream dependencies. | Install `\"$NV_GENERATE_ROOT\u002Frequirements.txt\"` in the selected environment. |\n",{"name":5,"license":15,"metadata":24,"description":7,"allowed-tools":31},{"tags":25,"author":30},[26,27,28,29],"MedTech","MRI","brain","finetune","NVIDIA MedTech Team","Bash","main","c475fc64e94e803b50d14a791dfee8853fbb2c5c","skills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory","https:\u002F\u002Fgithub.com\u002FElogic360","2026-11-08 22:21:22",{"source":8,"skillName":5,"commands":39,"prompt":49,"zipAvailable":50},[40,43,46],{"tool":41,"command":42},"npx","npx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-mr-brain-finetune",{"tool":44,"command":45},"bunx","bunx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-mr-brain-finetune",{"tool":47,"command":48},"pnpm","pnpm dlx skills add Elogic360\u002Fsoftware-factory --skill nv-generate-mr-brain-finetune","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FSKILL.md",true,[52,58,62,66,70,74,80,84,88,94,98],{"path":53,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":56,"sourceHtmlUrl":57},"BENCHMARK.md","REFERENCE","参考文档",4492,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002FBENCHMARK.md",{"path":59,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":60,"sourceHtmlUrl":61},"evals\u002Fevals.json",1228,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fevals\u002Fevals.json",{"path":63,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":64,"sourceHtmlUrl":65},"fixtures\u002Fpreflight_datalist.json",130,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_datalist.json",{"path":67,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":68,"sourceHtmlUrl":69},"fixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",133,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002Fpreflight_dataset\u002FimagesTr\u002Fplaceholder_mri_t1.txt",{"path":71,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":72,"sourceHtmlUrl":73},"fixtures\u002FREADME.md",228,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ffixtures\u002FREADME.md",{"path":75,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":78,"sourceHtmlUrl":79},"scripts\u002Frun_mr_brain_finetune.py","SCRIPT","脚本",27467,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fscripts\u002Frun_mr_brain_finetune.py",{"path":81,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":82,"sourceHtmlUrl":83},"skill_manifest.yaml",6150,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill_manifest.yaml",{"path":85,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":86,"sourceHtmlUrl":87},"skill-card.md",3741,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill-card.md",{"path":89,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":92,"sourceHtmlUrl":93},"skill.oms.sig","OTHER","其他",6329,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fskill.oms.sig",{"path":95,"resourceType":76,"resourceTypeDesc":77,"sizeBytes":96,"sourceHtmlUrl":97},"tests\u002Ftest_run_mr_brain_finetune.py",6761,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Ftests\u002Ftest_run_mr_brain_finetune.py",{"path":99,"resourceType":54,"resourceTypeDesc":55,"sizeBytes":100,"sourceHtmlUrl":101},"validators\u002Foutput_schema.json",3842,"https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fnv-generate-mr-brain-finetune\u002Fvalidators\u002Foutput_schema.json",[103,110,117,124,131,138],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":19},"01M79G206MT3J6S0GY3C45P2KV","vss-summarize-video","Use to summarize a recorded video via the LVS summarization microservice (HITL-gated) with a VLM fallback. Not for report generation or live RTSP captioning.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-summarize-video\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":19},"01M79G1WN63PGRE8CKD47WEBQ5","vss-setup-video-analytics-api","Use to deploy the vss-video-analytics-api REST service standalone (config-source, data-log bind, Elasticsearch, optional Kafka). Not for full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-video-analytics-api\u002FSKILL.md",[],[],{"skillNo":118,"name":119,"nameZh":6,"description":120,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":121,"categories":122,"keywords":123,"publishedAt":19},"01M79G1S9F7VY3EF6H53PRP5AN","vss-setup-behavior-analytics","Use to deploy the vss-behavior-analytics service standalone (entrypoint, config-source, optional calibration). Not for the full warehouse deploy.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-setup-behavior-analytics\u002FSKILL.md",[],[],{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":128,"categories":129,"keywords":130,"publishedAt":19},"01M79G1N1S1Y27PFZPYMNK1MTQ","vss-search-archive","Use this skill to run top-level VSS fusion search on archived video, or to ingest video files \u002F RTSP streams for search. Do NOT use for ad-hoc visual Q&A (use vss-ask-video), live captioning (use vss-deploy-dense-captioning), or video summarization and reports (use vss-summarize-video).","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-search-archive\u002FSKILL.md",[],[],{"skillNo":132,"name":133,"nameZh":6,"description":134,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":135,"categories":136,"keywords":137,"publishedAt":19},"01M79G1H6WN0Q6C0VCAXCZX6B7","vss-query-analytics","Use this skill when reading video-analytics metrics, incidents, alerts, and sensor data via the VA-MCP server (port 9901). Not for live VLM or incident-range narrative reports.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-query-analytics\u002FSKILL.md",[],[],{"skillNo":139,"name":140,"nameZh":6,"description":141,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":142,"categories":143,"keywords":144,"publishedAt":19},"01M79G1DYPNXQS7QHZ0AAF5FX5","vss-manage-video-io-storage","Use to call the VIOS REST API (sensor list, timelines, clip extraction, snapshots, add\u002Fdelete sensors and streams). Not for VLM inference or search.","https:\u002F\u002Fgithub.com\u002FElogic360\u002Fsoftware-factory\u002Fblob\u002Fmain\u002Fskills\u002Fnvidia\u002Fvss-manage-video-io-storage\u002FSKILL.md",[],[]]