Segmentation
Use this sub-skill for medical image segmentation tasks in Attention-Gated
Networks. It covers 2D/3D U-Net variants, CT deep-supervision networks,
attention-gated U-Nets, non-local blocks, NIfTI datasets, segmentation
training/validation scripts, and feature or attention map exports.
Read first
- Read api-reference.md when you need exact
model names, wrapper methods, dataset class signatures, metric functions, or
hookable layer names.
- Read data-layout.md before arranging NIfTI data
or debugging split, image/label, and transform problems.
- Read workflows.md for training, validation,
checkpoint use, and safe attention/feature map export.
- Read troubleshooting.md for CUDA, memory,
SimpleITK, torchsample, NIfTI, shape, metric, or layer-hook failures.
- Run run_segmentation.py for skill-owned
training commands that replace the source repo's root training entry point.
- Run validate_and_export_maps.py to
replace hard-coded validation and feature-map scripts with a parameterized,
skill-owned helper.
- For fast environment validation, run the root helper
../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode segmentation.
When to use this sub-skill
Use this route when the user asks to:
- train a segmentation network from the repository configs;
- choose between baseline U-Net, non-local U-Net, CT deep supervision, and
multi-attention U-Net variants;
- validate a segmentation checkpoint and compute dice, IoU, precision/recall,
mean distance, or Hausdorff-style distances;
- arrange 3D NIfTI data for
acdc_sax, ukbb_sax, rvsc_sax, or test_sax;
- export NIfTI predictions, attention volumes, feature maps, or slice previews;
- debug 3D shape, memory, CUDA, SimpleITK, torchsample, or layer-hook issues.
Route ultrasound scan-plane classification and 2D attention overlays to
../classification/SKILL.md instead.
Quick workflow
Install the repository with CUDA-enabled PyTorch, torchsample, NIfTI, and
visualization dependencies. Then run:
python ../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode segmentation
Arrange NIfTI files under split directories with paired image/ and
label/ subfolders. See data-layout.md.
Copy a CT config and replace data_path.acdc_sax with the current dataset
root. The stock configs use output_nc=4, tensor_dim='3D', and
gpu_ids=[0].
Relative config paths are resolved from the explicit --repo-root; relative
data_path values are resolved from the config file's parent. NIfTI data and
model weights/checkpoints must exist externally. The bundled runner and
check_env.py --config ... fail fast on missing or private /vol/... paths;
they never fabricate data.
4. Train with the bundled replacement:
python scripts/run_segmentation.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json
Validate a checkpoint or export maps with the bundled helper:
python scripts/validate_and_export_maps.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --checkpoint path/to/checkpoint.pth --output-dir /tmp/ag-net-validation --mode validate
For safe smoke validation or map export without private paths, use:
python scripts/validate_and_export_maps.py \
--repo-root /path/to/Attention-Gated-Networks \
--config configs/config_unet_ct_multi_att_dsv.json \
--output-dir /tmp/ag-net-segmentation \
--mode both
Key decisions
- CUDA is required for the unmodified source wrappers. A CPU-only install does
not verify the selected segmentation workflows.
unet_ct_dsv is the simpler CT deep-supervision route; use
unet_ct_multi_att_dsv when attention maps are a first-class goal.
- Real CT configs use large volumes (
160 x 160 x 96 patches). The generated
helper's 16 x 16 x 16 synthetic volume is only a wiring smoke.
- The source validation and map-export scripts hard-code private paths. Prefer
the bundled helper or explicitly parameterize a project-local copy.
- The source CRF post-processing script is reference-only, not bundled as a
safe helper.
Expected outputs
Training writes checkpoints and logs below the configured checkpoint directory
and experiment name. Validation writes NIfTI predictions and CSV metrics. The
bundled helper writes synthetic or fixture NIfTI outputs, metrics.json,
feature/attention-map NIfTI files, and middle-slice preview PNGs to the selected
output directory.
1---2name: segmentation3description: "Guides Attention-Gated Networks medical image segmentation4 workflows, including 3D U-Net training, validation, NIfTI layouts, and5 attention or feature-map export."6disable-model-invocation: true7metadata:8 source: https://skillmd.com/skills/vectorspacelab/segmentation9 disco-role: operating10license: MIT11---1213# Segmentation1415Use this sub-skill for medical image segmentation tasks in Attention-Gated16Networks. It covers 2D/3D U-Net variants, CT deep-supervision networks,17attention-gated U-Nets, non-local blocks, NIfTI datasets, segmentation18training/validation scripts, and feature or attention map exports.1920## Read first2122- Read [api-reference.md](references/api-reference.md) when you need exact23 model names, wrapper methods, dataset class signatures, metric functions, or24 hookable layer names.25- Read [data-layout.md](references/data-layout.md) before arranging NIfTI data26 or debugging split, image/label, and transform problems.27- Read [workflows.md](references/workflows.md) for training, validation,28 checkpoint use, and safe attention/feature map export.29- Read [troubleshooting.md](references/troubleshooting.md) for CUDA, memory,30 SimpleITK, torchsample, NIfTI, shape, metric, or layer-hook failures.31- Run [run_segmentation.py](scripts/run_segmentation.py) for skill-owned32 training commands that replace the source repo's root training entry point.33- Run [validate_and_export_maps.py](scripts/validate_and_export_maps.py) to34 replace hard-coded validation and feature-map scripts with a parameterized,35 skill-owned helper.36- For fast environment validation, run the root helper37 `../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode segmentation`.3839## When to use this sub-skill4041Use this route when the user asks to:4243- train a segmentation network from the repository configs;44- choose between baseline U-Net, non-local U-Net, CT deep supervision, and45 multi-attention U-Net variants;46- validate a segmentation checkpoint and compute dice, IoU, precision/recall,47 mean distance, or Hausdorff-style distances;48- arrange 3D NIfTI data for `acdc_sax`, `ukbb_sax`, `rvsc_sax`, or `test_sax`;49- export NIfTI predictions, attention volumes, feature maps, or slice previews;50- debug 3D shape, memory, CUDA, SimpleITK, torchsample, or layer-hook issues.5152Route ultrasound scan-plane classification and 2D attention overlays to53`../classification/SKILL.md` instead.5455## Quick workflow56571. Install the repository with CUDA-enabled PyTorch, torchsample, NIfTI, and58 visualization dependencies. Then run:5960 ```bash61 python ../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode segmentation62 ```63642. Arrange NIfTI files under split directories with paired `image/` and65 `label/` subfolders. See [data-layout.md](references/data-layout.md).663. Copy a CT config and replace `data_path.acdc_sax` with the current dataset67 root. The stock configs use `output_nc=4`, `tensor_dim='3D'`, and68 `gpu_ids=[0]`.6970Relative config paths are resolved from the explicit `--repo-root`; relative71`data_path` values are resolved from the config file's parent. NIfTI data and72model weights/checkpoints must exist externally. The bundled runner and73`check_env.py --config ...` fail fast on missing or private `/vol/...` paths;74they never fabricate data.754. Train with the bundled replacement:7677 ```bash78 python scripts/run_segmentation.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json79 ```80815. Validate a checkpoint or export maps with the bundled helper:8283 ```bash84 python scripts/validate_and_export_maps.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --checkpoint path/to/checkpoint.pth --output-dir /tmp/ag-net-validation --mode validate85 ```86876. For safe smoke validation or map export without private paths, use:8889 ```bash90 python scripts/validate_and_export_maps.py \91 --repo-root /path/to/Attention-Gated-Networks \92 --config configs/config_unet_ct_multi_att_dsv.json \93 --output-dir /tmp/ag-net-segmentation \94 --mode both95 ```9697## Key decisions9899- CUDA is required for the unmodified source wrappers. A CPU-only install does100 not verify the selected segmentation workflows.101- `unet_ct_dsv` is the simpler CT deep-supervision route; use102 `unet_ct_multi_att_dsv` when attention maps are a first-class goal.103- Real CT configs use large volumes (`160 x 160 x 96` patches). The generated104 helper's `16 x 16 x 16` synthetic volume is only a wiring smoke.105- The source validation and map-export scripts hard-code private paths. Prefer106 the bundled helper or explicitly parameterize a project-local copy.107- The source CRF post-processing script is reference-only, not bundled as a108 safe helper.109110## Expected outputs111112Training writes checkpoints and logs below the configured checkpoint directory113and experiment name. Validation writes NIfTI predictions and CSV metrics. The114bundled helper writes synthetic or fixture NIfTI outputs, `metrics.json`,115feature/attention-map NIfTI files, and middle-slice preview PNGs to the selected116output directory.