segmentation
Guides Attention-Gated Networks medical image segmentation workflows, including 3D U-Net training, validation, NIfTI layouts, and attention or feature-map export.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- segmentation
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Guides Attention-Gated Networks medical image segmentation workflows, including 3D U-Net training, validation, NIfTI layouts, and attention or feature-map export.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-reference.md6.1 KB
- 参考文档references/data-layout.md3.2 KB
- 参考文档references/troubleshooting.md4.6 KB
- 参考文档references/workflows.md4.1 KB
- 脚本scripts/run_segmentation.py7.6 KB
- 脚本scripts/validate_and_export_maps.py11.3 KB
03 SKILL.md 正文
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, ortest_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/andlabel/subfolders. See data-layout.md. -
Copy a CT config and replace
data_path.acdc_saxwith the current dataset root. The stock configs useoutput_nc=4,tensor_dim='3D', andgpu_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_dsvis the simpler CT deep-supervision route; useunet_ct_multi_att_dsvwhen attention maps are a first-class goal.- Real CT configs use large volumes (
160 x 160 x 96patches). The generated helper's16 x 16 x 16synthetic 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.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).