File size: 2,937 Bytes
83777f5
 
 
 
 
 
 
 
 
 
 
 
ff8e6c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38b962b
ff8e6c1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8536daf
 
 
 
 
 
 
ff8e6c1
 
83777f5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
license: afl-3.0
language:
- en
tags:
- applewatch
- ecg
- electrocardiogram
- hyperkalemia
- esrd
- deeplearning
---
# Kardio-Net: A Deep Learning Model for Predicting Serum Potassium Levels from Apple Watch ECG in ESRD Patients


### I. Input preparation


1. Prerequisites

    Ensure that all ECG files are saved in *.npy format with the following shapes:
    - (5000, 12) for 12-lead ECGs
    - (500 * 30 seconds, 1) for Apple Watch ECGs
    
    Store these files in a single flat directory, and include a manifest CSV file in the same location to accompany 
    them.
    

2. Manifest File Format

    The manifest CSV file should include a header.
    Each row corresponds to one ECG file with the following columns:

    - filename: Name of the .npy file (without the extension).
    - label: serum potassium label.



### II. Inference


### For 12-Lead ECG

<!-- #region -->
1. use predict_potassium_12lead.py to get the potassium level prediction.


2. Edit data_path and manifest_path and run the predict_potassium.py script.


3. Upon completion, a file named "dataloader_0_predictions.csv" will be saved in the same directory. This file contains the inference results "preds" from the model.


4. Use generate_result.py to get the performance metric and figure.
<!-- #endregion -->

### For Single Lead / Apple Watch ECG


### A. ECG preprocessing and segmentation

<!-- #region -->
1. Use preprocessing.py for denoise, normalize, and segment ECG into 5-second for input


2. Set the following paths in preprocessing.py:

    - raw_directory = "path/to/raw_data_directory"  #raw ecg folder for target task
    - output_directory = "path/to/output_directory" #output folder for normalize ECG
    - manifest_path = "/path/to/manifest.csv"  # Manifest file path
    - output_path = "path/to/output_path"  # Output path for segmented ECGs


3. Execute predict.py.


4. If the ECG files were already normalize, can execute the segmentation function only.
<!-- #endregion -->

### B. potassium regression model

<!-- #region -->
1. use predict_potassium_1lead.py to get the potassium level prediction.


2. Edit data_path and manifest_path and run the predict_potassium.py script.


3. Upon completion, a file named "dataloader_0_predictions.csv" will be saved in the same directory. This file contains the inference results "preds" from the model.


4. Use generate_result.py to get the performance metric and figure.
<!-- #endregion -->


<!-- #region -->
Paper Link: https://www.sciencedirect.com/science/article/pii/S2405500X24007527

Citation: I-Min Chiu, Po-Jung Wu, Huan Zhang, J. Weston Hughes, Albert J. Rogers, Laleh Jalilian, Marco Perez, Chun-Hung Richard Lin, Chien-Te Lee, James Zou, David Ouyang, Serum Potassium Monitoring Using AI-Enabled Smartwatch Electrocardiograms, JACC: Clinical Electrophysiology, 2024, ISSN 2405-500X, https://doi.org/10.1016/j.jacep.2024.07.023.
<!-- #endregion -->

```python

```