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, and sononet_grid_attention;
- configure
aggregated_classifier, deep supervision, or attention aggregation;
- inspect classifier outputs, class counts, losses, or scikit-learn metrics;
- prepare or validate the
us HDF5 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
torchsample dependency. 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, and label_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', and gpu_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 choosing aggregation_mode and
aggregation.
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.
AggregatedClassifier is for multiple-output attention models. Plain
Sononet classifiers use FeedForwardClassifier.
- 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.
1---2name: classification-23description: "Guides Attention-Gated Networks ultrasound classification4 workflows, including Sononet training, evaluation, HDF5 data layout, and5 attention overlays."6disable-model-invocation: true7metadata:8 source: https://skillmd.com/skills/vectorspacelab/classification-29 disco-role: operating10license: MIT11---1213# Classification1415Use this sub-skill for ultrasound scan-plane classification tasks in16Attention-Gated Networks. It covers Sononet, Sononet2, Sononet Grid Attention,17`FeedForwardClassifier`, `AggregatedClassifier`, the HDF5 ultrasound loader,18classification training/testing scripts, and attention overlay export.1920## Read first2122- Read [api-reference.md](references/api-reference.md) when you need exact23 model names, wrapper behavior, config fields, aggregation modes, or class and24 function signatures.25- Read [data-layout.md](references/data-layout.md) before preparing the26 ultrasound HDF5 file or debugging loader/sampler failures.27- Read [workflows.md](references/workflows.md) for training, testing,28 checkpoint evaluation, model inspection, and safe attention-overlay export.29- Read [troubleshooting.md](references/troubleshooting.md) when CUDA,30 torchsample, Visdom, sampler, HDF5, or overlay failures appear.31- Run [run_classifier.py](scripts/run_classifier.py) for skill-owned training32 and testing commands that replace the source repo's root entry points.33- Run [export_attention_overlay.py](scripts/export_attention_overlay.py) to34 replace the source repo's hard-coded attention visualization script with a35 parameterized, skill-owned helper.36- For fast environment validation, run the root helper37 `../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode classification`.3839## When to use this sub-skill4041Use this route when the user asks to:4243- train or test ultrasound scan-plane classification models;44- choose between `sononet`, `sononet2`, and `sononet_grid_attention`;45- configure `aggregated_classifier`, deep supervision, or attention aggregation;46- inspect classifier outputs, class counts, losses, or scikit-learn metrics;47- prepare or validate the `us` HDF5 dataset layout;48- export compatibility-score attention maps or overlay PNGs;49- debug classification-specific CUDA, Visdom, sampler, HDF5, or checkpoint50 issues.5152Route 3D segmentation, NIfTI validation, and multi-attention U-Net feature-map53exports to `../segmentation/SKILL.md` instead.5455## Quick workflow56571. Install the repository with CUDA-enabled PyTorch and the legacy58 `torchsample` dependency. Then run:5960 ```bash61 python ../../scripts/check_env.py --repo-root /path/to/Attention-Gated-Networks --mode classification62 ```63642. Prepare an ultrasound HDF5 file with `x_train`, `p_train`, `x_val`, `p_val`,65 `x_test`, `p_test`, and `label_names`. See [data-layout.md](references/data-layout.md).663. Copy a Sononet config and replace its dataset path. The source configs use67 `model.output_nc=14`, `input_nc=1`, `tensor_dim='2D'`, and `gpu_ids=[0]`.684. Train with the bundled replacement when real data is available:6970Relative config paths are resolved from the explicit `--repo-root`; relative71`data_path` values are resolved from the config file's parent. The HDF5 data72file and any checkpoint/weights must already exist outside this skill. Bundled73runners and `check_env.py --config ...` reject missing or private `/vol/...`74paths before constructing a dataset.7576 ```bash77 python scripts/run_classifier.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --mode train78 ```79805. Evaluate a checkpoint with the bundled replacement:8182 ```bash83 python scripts/run_classifier.py --repo-root /path/to/Attention-Gated-Networks --config path/to/config.json --mode test84 ```85866. For attention models, use `model_type='sononet_grid_attention'` and read87 [workflows.md](references/workflows.md) before choosing `aggregation_mode` and88 `aggregation`.897. Export a safe synthetic overlay, or adapt the command for a real 2D input:9091 ```bash92 python scripts/export_attention_overlay.py \93 --repo-root /path/to/Attention-Gated-Networks \94 --config configs/config_sononet_grid_att_8.json \95 --output-dir /tmp/ag-net-attention96 ```9798## Key decisions99100- CUDA is required for the unmodified wrappers because the model and tensor101 paths call `.cuda()`.102- The stock ultrasound configs assume 14 classes. Do not reuse them unchanged103 for a different HDF5 label set.104- `AggregatedClassifier` is for multiple-output attention models. Plain105 Sononet classifiers use `FeedForwardClassifier`.106- Synthetic smoke checks prove wiring only; they do not replace training on the107 real ultrasound HDF5 file or evaluating a real checkpoint.108- The original attention visualization script hard-codes private paths. Use the109 bundled helper or parameterize your own script rather than running it as-is.110111The source `train_classifaction.py` contains a 10-hour sleep after the final112epoch's updates. It is retained in the source checkout for provenance; use the113bundled runner when a bounded run without that hold is required.114115## Expected outputs116117Training writes checkpoints and logs below the configured checkpoint directory118and experiment name. Testing writes accumulated metrics and a `test_result.pkl`119inside the model save directory. The bundled attention helper writes overlay120PNGs and `.npy` arrays to the requested output directory.