classification
Guides Attention-Gated Networks ultrasound classification workflows, including Sononet training, evaluation, HDF5 data layout, and attention overlays.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- classification
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Guides Attention-Gated Networks ultrasound classification workflows, including Sononet training, evaluation, HDF5 data layout, and attention overlays.
- disable-model-invocation
- true
02 资源文件 6
- 参考文档references/api-reference.md6.5 KB
- 参考文档references/data-layout.md3.3 KB
- 参考文档references/troubleshooting.md4.1 KB
- 参考文档references/workflows.md5.0 KB
- 脚本scripts/export_attention_overlay.py8.4 KB
- 脚本scripts/run_classifier.py13.4 KB
03 SKILL.md 正文
Classification
Use this sub-skill for ultrasound scan-plane classification tasks in
Attention-Gated Networks. It covers Sononet, Sononet2, Sononet Grid Attention,
FeedForwardClassifier, AggregatedClassifier, the HDF5 ultrasound loader,
classification training/testing scripts, and attention overlay export.
Read first
- Read api-reference.md when you need exact model names, wrapper behavior, config fields, aggregation modes, or class and function signatures.
- Read data-layout.md before preparing the ultrasound HDF5 file or debugging loader/sampler failures.
- Read workflows.md for training, testing, checkpoint evaluation, model inspection, and safe attention-overlay export.
- Read troubleshooting.md when CUDA, torchsample, Visdom, sampler, HDF5, or overlay failures appear.
- Run run_classifier.py for skill-owned training and testing commands that replace the source repo's root entry points.
- Run export_attention_overlay.py to replace the source repo's hard-coded attention visualization script 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 classification.
When to use this sub-skill
Use this route when the user asks to:
- train or test ultrasound scan-plane classification models;
- choose between
sononet,sononet2, andsononet_grid_attention; - configure
aggregated_classifier, deep supervision, or attention aggregation; - inspect classifier outputs, class counts, losses, or scikit-learn metrics;
- prepare or validate the
usHDF5 dataset layout; - export compatibility-score attention maps or overlay PNGs;
- debug classification-specific CUDA, Visdom, sampler, HDF5, or checkpoint issues.
Route 3D segmentation, NIfTI validation, and multi-attention U-Net feature-map
exports to ../segmentation/SKILL.md instead.
Quick workflow
-
Install the repository with CUDA-enabled PyTorch and the legacy
torchsampledependency. Then run:python ../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode classification -
Prepare an ultrasound HDF5 file with
x_train,p_train,x_val,p_val,x_test,p_test, andlabel_names. See data-layout.md. -
Copy a Sononet config and replace its dataset path. The source configs use
model.output_nc=14,input_nc=1,tensor_dim='2D', andgpu_ids=[0]. -
Train with the bundled replacement when real data is available:
Relative config paths are resolved from the explicit --repo-root; relative
data_path values are resolved from the config file's parent. The HDF5 data
file and any checkpoint/weights must already exist outside this skill. Bundled
runners and check_env.py --config ... reject missing or private /vol/...
paths before constructing a dataset.
python scripts/run_classifier.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --mode train
-
Evaluate a checkpoint with the bundled replacement:
python scripts/run_classifier.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --mode test -
For attention models, use
model_type='sononet_grid_attention'and read workflows.md before choosingaggregation_modeandaggregation. -
Export a safe synthetic overlay, or adapt the command for a real 2D input:
python scripts/export_attention_overlay.py \ --repo-root /path/to/Attention-Gated-Networks \ --config configs/config_sononet_grid_att_8.json \ --output-dir /tmp/ag-net-attention
Key decisions
- CUDA is required for the unmodified wrappers because the model and tensor
paths call
.cuda(). - The stock ultrasound configs assume 14 classes. Do not reuse them unchanged for a different HDF5 label set.
AggregatedClassifieris for multiple-output attention models. Plain Sononet classifiers useFeedForwardClassifier.- Synthetic smoke checks prove wiring only; they do not replace training on the real ultrasound HDF5 file or evaluating a real checkpoint.
- The original attention visualization script hard-codes private paths. Use the bundled helper or parameterize your own script rather than running it as-is.
The source train_classifaction.py contains a 10-hour sleep after the final
epoch's updates. It is retained in the source checkout for provenance; use the
bundled runner when a bounded run without that hold is required.
Expected outputs
Training writes checkpoints and logs below the configured checkpoint directory
and experiment name. Testing writes accumulated metrics and a test_result.pkl
inside the model save directory. The bundled attention helper writes overlay
PNGs and .npy arrays to the requested 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).