Takotsubo versus acute anterior STEMI: ECG-image models
Model-card revision: 0.1.1. Prepared: 2026-10-29 (JST). Weight version: v0.2.0. Companion software: v0.4.0.
Three trained models classify a prepared 12-lead ECG image as takotsubo syndrome or acute anterior ST-elevation myocardial infarction (STEMI). This repository distributes the selected ViT, ConvNeXtV2 and MLP-Mixer inference weights together, with their original configuration and license notices. The companion software provides individual-model inference, equal-weight raw-logit ensemble inference, and optional ViT/ConvNeXtV2 Grad-CAM.
The output class order is 0 = tako, 1 = AMI. Here, AMI identifies the study's acute anterior STEMI comparison group; it is not a claim of coverage of every type of myocardial infarction.
Developer: Eisuke Kagawa, ORCID 0000-0002-5583-3152. Affiliation: Hiroshima North Medical Center Asa Citizens Hospital.
| Resource | Link |
|---|---|
| Run the example | English Google Colab notebook, v0.4.0 |
| Source code | GitHub v0.4.0 |
| Software archive | Zenodo: code v0.4.0 |
| Weight archive | Zenodo: weights v0.2.0 |
| Research report | medRxiv preprint |
Research use and disclaimer
This repository and its associated model weights are intended for research. No warranty is given regarding the clinical accuracy, reliability, or fitness for clinical use of the code, model weights, predictions, or Grad-CAM visualizations.
To the fullest extent permitted by applicable law and subject to the applicable licenses, the authors and copyright holders accept no liability for claims, losses, damages, or other consequences arising from use of these materials or their outputs, including use in diagnosis or treatment decisions.
The warranty exclusions and liability limitations in the code license and the respective model-weight licenses apply. This notice summarizes intended use and does not amend those licenses.
Quick start
Google Colab
Open the v0.4.0 notebook and run its cells in order. It prepares a separate inference environment, obtains the verified v0.2.0 weight bundle from GitHub Releases by default, and offers Synthetic example, Upload from computer, and Google Drive inputs.
The synthetic trace checks software execution and has no diagnostic interpretation. Automatic device selection prefers an available GPU and warns before using CPU. The Paper, No TTA, and Custom controls select the inference workload; CPU fallback retains the selected TTA settings. Grad-CAM display is enabled by default in the notebook.
To use weights downloaded from this Hugging Face repository, follow the verified download procedure below. Before running the notebook's Prepare the weights cell, select WEIGHT_SOURCE = "local" and set WEIGHTS_DIR to the downloaded weights subdirectory, for example Path("/content/hf_snapshot/weights"). Download into the same Colab runtime, or use Drive to make the verified files accessible there. A PC-local path is not accessible from a hosted Colab runtime. The existing local-weight option does not itself verify the official checksums; complete the helper's verification first.
Download verified weights from Hugging Face
Choose a full 40-character commit SHA from this repository's Files and versions / History. Download download_verified_weights.py from that same revision to a separate working directory. The helper uses the Python standard library and does not load model tensors or execute repository model code.
Replace OWNER with the account shown on this model page and replace FULL_40_CHARACTER_COMMIT_SHA with the selected revision, then run:
python download_verified_weights.py --repo-id OWNER/takotsubo-ami-ai-ecg --revision FULL_40_CHARACTER_COMMIT_SHA --output-dir hf_snapshot
The helper downloads the 11 original release members into hf_snapshot/weights/ and checks their expected sizes and SHA-256 values. Its expected values identify the original v0.2.0 assets recorded by the companion software. Use the absolute path to hf_snapshot/weights/ for inference. Matching completed files can be reused; conflicting files are not overwritten.
To check an existing download without downloading again:
python download_verified_weights.py --output-dir hf_snapshot --verify-only
The original public descriptor is available in the fixed v0.4.0 source. Keep the selected Hugging Face commit SHA with your execution record. A branch name such as main can change over time.
CLI inference
Obtain the companion source in a separate directory:
git clone --branch v0.4.0 --depth 1 https://github.com/ekagawa007/takotsubo_ami_ai_ecg.git
cd takotsubo_ami_ai_ecg
git rev-parse HEAD
The checkout should report 6a16326b761c198c11776155102dc31d1308bfeb. Follow the CPU or CUDA setup instructions in a fresh Python 3.11+ environment. Use requirements-inference.txt; the historical requirements.txt records the training environment and is not the inference installation guide.
From that source directory, replace the image and weights paths with your own absolute paths and choose a new output filename:
python examples/predict_ensemble.py --image /path/to/prepared_ecg.png --weights-dir /path/to/hf_snapshot/weights --output outputs/prediction.json --gradcam
This uses the paper TTA settings below. For a CPU run with one unchanged view per model:
python examples/predict_ensemble.py --image /path/to/prepared_ecg.png --weights-dir /path/to/hf_snapshot/weights --output outputs/prediction_no_tta.json --device cpu --precision float32 --num-workers 0 --vit-tta 1 --convnextv2-tta 1 --mlpmixer-tta 1
Individual-model wrappers are examples/predict_vit.py, examples/predict_convnextv2.py, and examples/predict_mlpmixer.py. See the inference guide for all arguments.
These examples use the study's shared inference implementation, including its ViT checkpoint-name compatibility handling and original preprocessing. The bundle is not advertised as a drop-in transformers.pipeline() or from_pretrained() model. A generic image-classification widget does not implement the model-specific TTA and ensemble described here.
Inputs, preprocessing and outputs
The default input is a prepared 480 x 480 RGB ECG image. Single-frame PNG, JPEG, BMP, TIFF and WebP files are supported. The loader decodes the image, converts it to RGB and applies ImageNet mean/std normalization. Raw ECG signals, PDF files, animated images and multipage images are not accepted by this image CLI.
| Input policy | Preparation |
|---|---|
strict480 (default) | Require exactly 480 x 480 pixels. Other dimensions stop inference. |
square-resize | Require a square image and resize it to 480 x 480. |
center-crop | Take the central square using the shorter edge, then resize to 480 x 480. |
pad | Center the image in a white square using the longer edge, then resize to 480 x 480. |
resize (legacy) | Resize the whole image directly to 480 x 480, changing the aspect ratio for rectangles. |
Resizing uses bilinear interpolation. Cropping can remove leads or waveform segments; padding retains the full image but reduces its occupied area. These options make additional image sizes runnable and do not establish equivalence to the study's upstream ECG preparation. Inspect the prepared image before interpreting any output. See image preparation.
Outputs include per-model raw logits, softmax probabilities, predicted classes, effective settings and weight/configuration hashes. The default ensemble selects AMI when prob_AMI >= 0.5. Individual models use argmax, with an exact tie selecting tako, unless an explicit threshold is supplied. Probabilities are model outputs and are not a guarantee of calibrated clinical risk.
Optional Grad-CAM saves the prepared input, heatmaps, overlays and numerical maps. It is available for ViT and ConvNeXtV2, using separate unaugmented float32 passes. By default each map targets that individual model's TTA-logit argmax; the two targets can differ. These maps do not explain the TTA-averaged three-model ensemble. MLP-Mixer and ensemble heatmaps are not provided. See Grad-CAM methods and limitations.
Saved images and overlays contain input pixels. Keep real patient inputs and their saved outputs private; they are not included in this distribution.
Selected models and paper inference settings
| Model | Selected historical source | Distributed asset | Paper TTA |
|---|---|---|---|
| ViT | checkpoint-6900/model.safetensors | weights/vit/model.safetensors with configuration | 24 views, RandAugment magnitude 1 |
| ConvNeXtV2 | ckpt_0011.pth, ordinary model state | weights/convnextv2/model.safetensors | 1 unchanged view; no TTA |
| MLP-Mixer | ckpt_0011.pth, ordinary model state | weights/mlpmixer/model.safetensors | 32 views, RandAugment magnitude 3 |
TTA counts include the unchanged image. Each model averages its raw logits across its views. The ensemble averages the three models' raw logits with weights 1:1:1 and then applies softmax. Model probabilities are not averaged. ConvNeXtV2 swa_best.pth and the SWA state are not used.
CLI defaults are float32, seed 1234, batch size 1 and four workers; Colab CPU execution selects zero workers. TTA realizations depend on image order, dataset size, workers, numerical precision and library versions. Identical seeds alone do not establish equivalence to historical stochastic-TTA predictions.
Training and provenance
The companion repository retains self-supervised pretraining, three-class fine-tuning and final two-class fine-tuning sources for the three architectures. The clinical research task uses ECG images from takotsubo syndrome and acute anterior STEMI cases; details of the development and evaluation cohorts are described in the linked preprint. Patient ECG images, training datasets, individual prediction tables and reader-study participant records are not included here.
Training and validation losses were reviewed, and the checkpoint with the lowest validation loss among epochs without apparent signs of overfitting was selected. This records the reported selection procedure; it does not prove that overfitting was absent. See checkpoint selection.
The retained ViT pretraining source initializes from facebook/vit-mae-base, followed by local ECG training stages. The final saved checkpoint does not identify an immutable upstream revision. Configuration/image-processor references to google/vit-base-patch16-384 do not establish that those Google weights initialized the fine-tuning stages. Retained ConvNeXtV2 and MLP-Mixer pretraining sources construct their timm models with pretrained=False, followed by local checkpoints. These statements describe the available source, not a complete reconstruction of every executed run. Attribution and the limits of the available provenance are retained in THIRD_PARTY_NOTICES.md.
The export preserved all 730 selected inference tensors' names, shapes, dtypes and values against the original selected states. The ViT training-only focal_loss.alpha buffer was omitted explicitly. The public files contain inference tensors and necessary configuration, without optimizer/scheduler state or original training-machine paths.
Evaluation and software-validation scope
Study performance and reader-study results are reported in the preprint. The execution checks below are separate from that clinical evaluation and do not supply new diagnostic-performance estimates.
| Check | Completed scope and limitation |
|---|---|
| Ten real ECGs, historical evaluator comparison | The public v0.2.1 inference implementation was compared with frozen original-evaluator results at float32 and no TTA. All three models and the ensemble were within atol=rtol=1e-5, with zero class differences. This was a small numerical comparison, not a new clinical-performance evaluation. |
| v0.4.0 candidate Colab checks, 2026-10-29 | Eight runs covered generated images, computer uploads, Google Drive, input geometry options, CPU execution and A100 execution. Saved source/weight identities, predictions and Grad-CAM artifacts were checked. This was not exhaustive coverage of all inputs or settings. |
| Public v0.4.0 Colab workflow, 2026-10-29 | One generated 480 x 480 RGB image completed on A100 with CUDA float32, paper TTA and Grad-CAM. Recorded source/weight identities and nine saved files were verified. Prediction values matched the candidate run exactly; the small ViT map difference is quantified in the detailed record. This run did not include a paired Grad-CAM-off comparison. |
These checks concern the companion software and unchanged v0.2.0 assets. They do not, by themselves, constitute a test of a later download mirror. The detailed dated record is implementation status.
Historical paper-TTA numerical equivalence, a complete training rerun, all-dataset evaluation reproduction and equivalence to historical reader-study Grad-CAM images have not been established by these checks. Clinical deployment, prospective patient outcomes and performance across untested populations, image sources or ECG layouts also remain outside this validation scope.
Distribution and licenses
The 11 files under weights/ preserve the original v0.2.0 release layout. Three model.safetensors files total 958,657,088 bytes. The original GitHub/Zenodo ZIP is 958,701,120 bytes, with SHA-256:
cba7d135b1e2f5491f1c0ccab93aef8e3b65570586f8052029540b94e7fbf510
This ZIP checksum identifies the original archive, not a ZIP newly generated from this repository. The download helper checks the individual original files.
| Material | Existing terms |
|---|---|
| ViT inference weights and accompanying configuration | The author's contributions use CC BY-NC 4.0. Original MAE noncommercial and Hugging Face distribution Apache-2.0 notices are retained. Unrestricted commercial use is not granted. |
| ConvNeXtV2 and MLP-Mixer inference weights | The author's contributions use MIT terms, subject to the retained upstream notices. |
| Companion source code and the download helper | MIT. This does not change the separate weight terms. |
Copyright in the author's contributions, to the extent applicable: Copyright (c) 2026 Eisuke Kagawa. The complete bundle includes ViT's noncommercial condition. See WEIGHTS_LICENSE.md, THIRD_PARTY_NOTICES.md, MIT, CC BY-NC 4.0 and Apache-2.0. These notices preserve the existing asset-specific terms; this model card does not create or replace a license.
Citation
When using these weights, cite the weight archive. When using the companion inference software, also cite the software archive. Cite the linked preprint when discussing the study. The two Zenodo DOIs identify different materials and are version-specific.
- Kagawa, E. (2026). takotsubo_ami_ai_ecg: trained ViT, ConvNeXtV2 and MLP-Mixer inference weights (v0.2.0) [Model]. Zenodo. https://doi.org/10.5281/zenodo.23666262
- Kagawa, E. (2026). takotsubo_ami_ai_ecg: research software for ECG-image classification and Grad-CAM (v0.4.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.23763944
The software DOI identifies the archived v0.4.0 inference source, not this additional Hugging Face download helper or later model-card edits. Record this repository's commit SHA when those details matter to your use. Machine-readable software citation information is in the companion CITATION.cff.