Skip to content

Codex/use deepecg layout renderer#46

Open
robertavram-md wants to merge 4 commits into
Ahus-AIM:mainfrom
HeartWise-AI:codex/use-deepecg-layout-renderer
Open

Codex/use deepecg layout renderer#46
robertavram-md wants to merge 4 commits into
Ahus-AIM:mainfrom
HeartWise-AI:codex/use-deepecg-layout-renderer

Conversation

@robertavram-md

Copy link
Copy Markdown

No description provided.

robertavram-md and others added 4 commits March 6, 2026 21:58
… tools

- Multi-layout renderer: renders NPY ECGs in 13 different layout types with
  mask generation for U-Net training (scripts/multi_layout_renderer.py)
- Batch multi-layout rendering with phone augmentations and multi-layout-per-signal
  support (scripts/render_acs_multilayout.py)
- U-Net multi-layout training with combined ACS + HuggingFace data, phone
  augmentations, and AMP support (scripts/train_unet_multilayout.py)
- Layout classifier training on rendered data (scripts/train_layout_classifier.py)
- ONNX export for all 4 models: U-Net, layout classifier, lead ID, WCR
  (scripts/export_all_onnx.py)
- Auto-retrain orchestration script (scripts/auto_retrain_unet.sh)
- Batch prediction and full pipeline scripts
- Fix decode_image -> read_image compatibility in src/digitize.py
- Add lead_layouts_deepecg.yml config for 13 ECG layout types

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix(digitize): prevent silent layout fallback that mislabels leads

When the lead identifier couldn't match a layout, it silently defaulted to
the first entry in the candidate YAML and canonicalised leads against it,
producing CSVs that looked correct but had leads mapped to the wrong names
(e.g. a standard_3x4_with_r3 phone photo collapsed into precordial_6x1
with only one signal track populated). Three related problems:

- src/model/lead_identifier.py: the fallback warning was a plain print
  and crashed with IndexError if the candidate set was empty (e.g. a
  layout hint that didn't match any YAML entry). Raise on empty, emit a
  RuntimeWarning otherwise so the unreliable fallback is visible.

- src/digitize.py: layout_should_include_substring was only populated
  from a hardcoded filename heuristic ("limb"/"precordial"), so callers
  with a layout classifier had no way to pass their prediction through.
  Accept a literal substring in the config (e.g. "standard_3x4_with_r3")
  and keep the legacy heuristic behind the sentinel "auto_from_filename".

- src/model/inference_wrapper.py: perspective detection + cropping raised
  on zoomed-in photos without visible paper borders, aborting the whole
  request. Fall back to the full-image rectangle (matching the backend
  pipeline) and surface bounding_box_used so callers can flag this.

Also adds src/config/inference_wrapper_all_layouts.yml - a tracked
preset that points the lead identifier at lead_layouts_all.yml (13
layouts) instead of lead_layouts_reduced.yml (2 layouts), which was the
root cause of the observed fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs+meta: surface layout-hint config and digitization status

- README: new "Constraining the layout match from an upstream classifier"
  section documenting the three possible values for
  DATA.layout_should_include_substring (null, a literal substring, or the
  auto_from_filename sentinel) plus the new failure semantics (raise on
  empty candidate set, RuntimeWarning on fallback).
- src/digitize.py: extend digitization_metadata.csv with bounding_box_used
  and a status column (ok / no_canonical_lines), so runs that produced no
  canonical lines are traceable in the metadata instead of appearing as
  missing CSV files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: robertavram-md <robertavram-md@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant