This repository contains the code for the 7th place solution of the PhysioNet - Digitization of ECG Images 2025 Competition here.
Solution Summary: here
Our pipeline uses rotation, lead detection, lead segmentation, digitization, and out-of-distribution detection models. We modified the ECG-image-kit repository to create lead detection training data, relied on the competition data for digitization, and used out-of-distribution detection models to optimize our ensemble. For more details, keep reading!
Please read the solution summary for more details.
The listed hardware requirements are a guideline. We used consumer hardware (4090/5090) for most experiments, but rented 1xA100 and 1xH200 in the final week of the competition. Some affordable cloud options are Runpod and Paperspace.
| Component | Recommended |
|---|---|
| OS | Ubuntu 22.04 |
| RAM | ≥ 32 GB |
| Disk Space | ≥ 300 GB |
| CPU Cores | ≥ 8 |
| CUDA Version | 12.4 |
| GPU | NVIDIA A100 |
- Get bash script for miniconda download from here
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
- Execute setup script
chmod u+x ./Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh
This part sets up an environment for generating data with our modified version of ecg-image-kit, and downloading the competition dataset from here. After completing all the steps below, we list the expected directory structure.
-
Set up a conda environment """ cd ./ecg-image-generator/ conda env create -f environment_droplet.yml conda activate ecg-gen-env pip install -r requirements.txt """
-
Generate data. This will use ~100GB of disk space. """ cd ../ mkdir ./data/generated/ chmod u+x ./generate.sh ./generate.sh """
-
Download the competition dataset from here, and other data sources from here. All data should be placed under
./data/raw/. Your directory structure should now look like this.
./data/
├── augment_images/
├── generated/
├── processed/
├── ptbxl/
├── raw/
./ecg-image-generator/
./src/
generate.sh
README.md
requirements.txt
run.sh
train.py
This part sets up an environment for training models and provides sample commands to test the environment. Most models can be trained on <16GB of vRAM with a lower batch size. You can tune the data_cfg.batch_size and encoder_cfg.use_checkpoint as needed.
- Create environment
conda create --prefix ../pnet_env python=3.10
conda activate ../pnet_env
conda install nvidia::cuda
conda install pytorch==2.5.1 torchaudio==2.5.1 torchvision==0.20.1 monai==1.4.0 wandb==0.19.6 tqdm==4.67.1
pip install -r requirements.txt
- Test training scripts
chmod u+x ./run.sh
To completely reproduce the digitization models in our final submission, you will need to run the training script multiple times. At each stage, the starting weights need to be initialized from the previous stage.
Here is the rough training plan by stage. For more details, please refer to the configuration files in the intermediate checkpoints here.
| Stage | Verticalflip | Horizontalflip | Loss | Resize |
|---|---|---|---|---|
| 1 | False | True | SNRLoss | (384, 1248) |
| 2 | False | True | SNRLoss | (320, 3072) |
| 3 | True | True | SNRv2Loss | (320, 5120) |
| 4 | True | True | SNRv2Loss | (320, 5888) |
| 5 | True | True | SNRv2Loss | (320, 8704) |
To train a model, run the following commands. Each model takes 35-40 hours to train. You can train for 250 epochs and get the same performance.
You can repeat this step to train multiple models for an ensemble.
# Make executable
chmod u+x run.sh
# Run in background
nohup ./run.sh > nohup.out &