Repository navigation
[Model + Task] PTB-XL binary tasks and TaskAug ECG augmentation (Raghu et al., CHIL 2022) - #1614
LishaRanganath wants to merge 2 commits into
Conversation
Adds single-diagnosis tasks (MI, HYP, STTC, CD) on top of PTBXLDataset, a 1D ResNet baseline, and TaskAugResNet, which applies the TaskAug augmentation policy with a configurable number of stages K. TaskAug code is adapted from aniruddhraghu/ecg_aug (Apache-2.0). Includes tests, an ablation example script with a synthetic mode, and API docs. Co-authored-by: Claude <noreply@anthropic.com>
Test CoverageTotal: 86.63% (47760 / 55132 lines)
|
|
/review |
|
/review |
There was a problem hiding this comment.
Previous review
AI Review
suggestion: need change
decision: human review
Thank you for this contribution. It adds single-diagnosis PTB-XL binary tasks (MI, HYP, STTC, CD), a 1D ResNet baseline, a TaskAug-augmented variant adapted from the authors' Apache-2.0 code (license included), and an ablation example with a synthetic mode. Coverage is well above the bar: the whole repository is at 86.5%, and each changed file is at 96% or higher. Sharing with the existing PTB-XL helpers and dataset is named in the description. You are close.
To get this merged:
TaskAugResNetcrashes in training mode on inputs that are not 5000 or 2496 samples long.PTBXLDatasetdefaults to 100 Hz (1000 samples), so the first training batch hits a shape mismatch in the warp and displacement operations, which are hard-coded to 2496 samples. Eval mode works, so the failure is easy to miss. Please do one of these:- Raise a clear ValueError in
TaskAugResNet.forwardor__init__when the length is not 2496 after trimming. - Support other lengths.
Either way, state the 500 Hz requirement in theTaskAugResNetandPTBXLResNetdocstrings and add a test for it. The task docs mentionsampling_rate=500, but the model docs do not.
- Raise a clear ValueError in
- Add a test showing that training mode changes the input to the encoder, or the output, compared with eval mode. Right now nothing checks that the augmentation is applied.
Optional suggestions:
- The description says 15 unit tests, but I count 11 test methods. Please correct the number.
- The example docstring says K=2 is "best or tied" on MI. In your table the no-aug baseline (0.8213) beats every TaskAug column on MI, so please reword.
- The description calls the K sweep the paper's ablation, while the example says the paper does not report it. Please make these consistent.
- The docstring notes that the magnitudes are trained on the training loss. It could add that this tends to push them toward weaker augmentation.
Reviewed commit 08798e1
|
Thanks for the review! I pushed 4111de4, which addresses all the points: |
|
/review |
| y_true = kwargs[self.label_keys[0]].to(self.device) | ||
| if self.training: | ||
| # TaskAug conditions its magnitudes on integer class labels. | ||
| x = self.taskaug(x, y_true.view(-1).long()) |
There was a problem hiding this comment.
[low] TaskAugResNet silently assumes binary labels
The augmentation uses y_true.view(-1).long() as an index into per-class magnitudes that are built for exactly two classes. With a multilabel or multiclass dataset, such as PTBXLSuperclassClassification from the same dataset, the batch length or label values do not match, so training fails with an indexing error that does not name the cause. Fix: in TaskAugResNet.__init__, check that self.label_processor is binary (output size 1) and raise a clear ValueError otherwise, or state in the class docstring that the model is binary-only.
| ) | ||
|
|
||
|
|
||
| class PTBXLBinaryClassification(BaseTask): |
There was a problem hiding this comment.
[low] Records without a diagnostic superclass are silently labelled 0
Records with no diagnostic superclass, such as pacemaker ECGs, are kept with label 0 for every binary task. PTBXLSuperclassClassification drops them by default (drop_empty_labels=True), so the two tasks disagree on the same records. Fix: say in the class docstring that these records are negatives, or drop them to match the existing task.
| python examples/ecg/ptbxl/ptbxl_binary_classification_taskaug_resnet.py \ | ||
| --root /data/ptb-xl/1.0.3 --task HYP --ablation --train-samples 1000 | ||
|
|
||
| Findings (reference, original TaskAug code): |
There was a problem hiding this comment.
[low] Documented run command does not reproduce the reported numbers
The Findings block reports results from 100-epoch runs of the authors' code, but the How-to-run commands use the script default of 5 epochs (line 190). Fix: add --epochs 100 to the documented command, or state in the Findings block that the table needs that setting.
There was a problem hiding this comment.
AI Review
suggestion: approve
decision: human review
Thank you for this contribution. It adds binary PTB-XL tasks (MI, HYP, STTC, CD), a 1D ResNet baseline, TaskAugResNet with the adapted TaskAug augmentation policy, an ablation example, docs and tests. It looks ready to merge.
The change is self-contained. It only adds export lines and docs index entries to existing files. The reuse of the existing PTBXL helpers and PTBXLDataset is named in the description. The Apache license for the adapted code is included. The limitation that the bilevel optimization isn't reproduced is clearly stated. The dataset is existing, and the paper is cited. Coverage is good: every added file is at 96% or higher, and the repository total is 86.6%.
Optional suggestions:
TaskAugResNetonly supports binary labels. Running it on a multilabel PTB-XL task gives an obscure indexing error. A clear check in__init__would help.- Say in the task docs that records with no diagnostic superclass are labeled 0.
- The documented run command uses the default of 5 epochs, but the reported numbers used 100. Mention
--epochs 100in the docs or example. test_training_mode_augments_inputis fairly weak. It would help to check that training-mode input differs from the unaugmented input for a fixed seed.- Fix the missing newlines at the end of the example file and
warp_ops.py.
Reviewed commit 4111de4
Contributors
Course project for CSE6250 (Georgia Tech), reproducibility challenge.
Contribution type
Model + Standalone Task. The tasks and model build on the existing
PTBXLDataset, which is reused unchanged.Paper
Aniruddh Raghu, Divya Shanmugam, Eugene Pomerantsev, John Guttag, Collin M. Stultz.
"Data Augmentation for Electrocardiograms." CHIL 2022, PMLR 174:282-310.
https://proceedings.mlr.press/v174/raghu22a.html
What this adds
The paper proposes TaskAug, an ECG augmentation policy made of K chained stages, each choosing among temporal warp, baseline wander, Gaussian noise, random crop, displacement, magnitude scaling or no-op, with class-conditional magnitudes. The paper fixes K=2. This PR:
PTBXLDatasetand the helpers inpyhealth.tasks.ptbxl;PTBXLResNet(1D ResNet baseline) andTaskAugResNet(same network preceded by the TaskAug policy, with a configurable number of stagesk), applied only in training mode;pyhealth.models.taskaug, the augmentation operations adapted from the authors' code (https://github.com/aniruddhraghu/ecg_aug, Apache-2.0; license copied into the folder, modifications noted in each file);Limitations
TaskAugResNetapplies the augmentation but does not reproduce the paper's bilevel optimization of the augmentation magnitudes (validation-set hypergradient). Here the magnitudes are trained jointly with the network on the training loss. This is stated in the class docstring and the docs page. Minimizing the training loss tends to shrink the magnitudes, so the policy can drift toward little or no augmentation. In training mode TaskAugResNet needs 500 Hz signals (5000 or 2496 samples) and raises ValueError otherwise.File guide
pyhealth/tasks/ptbxl_binary.pyPTBXLBinaryClassificationandPTBXLMI,PTBXLHYP,PTBXLSTTC,PTBXLCDpyhealth/models/ptbxl_resnet.pyPTBXLResNet,TaskAugResNetpyhealth/models/taskaug/LICENSEexamples/ecg/ptbxl/ptbxl_binary_classification_taskaug_resnet.py--ablation,--synthetic)tests/core/test_ptbxl_binary_tasks.py,tests/core/test_ptbxl_taskaug_resnet.pydocs/api/tasks/pyhealth.tasks.ptbxl_binary.rst,docs/api/models/pyhealth.models.PTBXLResNet.rstdocs/api/tasks.rst,docs/api/models.rst,pyhealth/tasks/__init__.py,pyhealth/models/__init__.pyTests and checks
ruff checkclean andtools/check_pr_rules.pypasses against the currentmaster.Reproduction results (original authors' code, not this PyHealth model)
Test AUROC with 1000 training ECGs, seed 42, 100 epochs, run with https://github.com/aniruddhraghu/ecg_aug:
On MI the no-aug baseline is best and K=2 ties K=3 within noise; K=2 is best on STTC and CD; HYP prefers K=1. TaskAug clearly helps only on CD. Single seed, so small differences are within noise. The MI results and STTC K=2 come from an earlier run with identical settings.
How to run