|
# 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 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 --> |
|
|
|
```python |
|
|
|
``` |
|
|