APCONet is an end-to-end beat-to-beat deep learning model for stroke volume (SV) monitoring.
It predicts SV from 100Hz 20-second waveform fragments of arterial blood pressure
(ABP) and demographic information (age, sex, height, weight). Afterward, cardiac output (CO)
can be calculated by multiplying SV with heart rate (HR).
Author: Hyun-Lim Yang (VitalLab, SNUH, South Korea)
Credits:
- Hyung-Chul Lee (VitalLab, SNUH, South Korea)
- Chul-Woo Jung (VitalLab, SNUH, South Korea)
- Min-Soo Kim (InfoLab, KAIST, South Korea)
Code adjustments made by:
- Roy van Mierlo (TU/e, r.r.m.v.mierlo@tue.nl)
If you use this code in your research, please cite both the original APCONet paper and our work:
Van Mierlo, R. R., Bouwman, R. A., & Van Riel, N. A. (2024).
Reproducing and improving one-dimensional convolutional neural networks for arterial blood pressure-based cardiac output estimation.
In Proceedings of the IEEE International Symposium on Medical Measurements and Applications (MeMeA) (pp. 1–6).
@inproceedings{vanmierlo2024cnn,
title={Reproducing and improving one-dimensional convolutional neural networks for arterial blood pressure-based cardiac output estimation},
author={Van Mierlo, R. R. and Bouwman, R. A. and Van Riel, N. A.},
booktitle={IEEE International Symposium on Medical Measurements and Applications (MeMeA)},
year={2024},
pages={1--6}
}
Yang, H. L., Jung, C. W., Yang, S. M., Kim, M. S., Shim, S., Lee, K. H., & Lee, H. C. (2021). Development and validation of an arterial pressure-based cardiac output algorithm using a convolutional neural network: Retrospective study based on prospective registry data. JMIR Medical Informatics, 9(8), e24762.
@article{yang2021apconet,
title={Development and validation of an arterial pressure-based cardiac output algorithm using a convolutional neural network},
author={Yang, Hyun-Lim and Jung, Chul-Woo and Yang, Seung-Mok and Kim, Min-Soo and Shim, Sung and Lee, Kwang-Ho and Lee, Hyo-Chang},
journal={JMIR Medical Informatics},
volume={9},
number={8},
pages={e24762},
year={2021}
}
The paper authors share a de-identified dataset of pre-processed ABP waveforms, their
corresponding pulmonary artery catheter (PAC) derived SVs, and demographic information which
is used for tuning APCONet. You can download the data here.
(Only the Train.zip folder contains samples with ground truth SVs, Test.zip does
not!).
Raw data used for pre-training is available upon request at VitalDB.net.
ABP (and other) waveforms, demograpic information, and the corresponding FloTrac derived SVs
are available for download using the vitaldb python package.
ABP waveforms are found under the 'SNUADC/ART' track, FloTrac data is found under the 'EV1000/SV'
and 'Vigileo/SV' tracks. Additionally, some PAC SV data is available under the 'Vigilance/SV'
track. A .csv file of the demographic information can be downloaded by selecting all caseID's
in the online data viewer and then clicking
Actions > Dowload Clinical Info.
- Create an empty folder for storing the data (e.g. on your D: drive) that is in a path separate from this project folder. This also makes sure that there won't be any interference with your version control software when reading and writing data.
- Create a
vars.envfile in project folder containing your data folder path, the file name of the .csv file containing the demographic information, your Neptune project path, and your Neptune API token in the structure shown below. (No',", or{}is needed around the values!) You can find the API token when logging into neptune account, click on your username in the left bottom corner and then on 'Get your API token'.DATA_FOLDER_PATH={path to your data folder} DEMOGRAPHICS_FILE_NAME={e.g. demographics.csv} NPT_PROJECT={path to your Neptune project, e.g. royvanmierlo/APCONet} NPT_API_TOKEN={your Neptune API token}, } - Download the PAC data from the link above and extract the
Train.zipfolder in your data folder to the folderTrain. - Create a folder
Pretrainin your data folder, download the demographic data from the VitalDB website, and place the .csv file in thePretrainfolder.
-
apconet.py: Script to run APCONet. It contains the configurations for the training and testing processes, which can be changed in the argument parser.
Input dataset must be named and shaped as follows:Variable Name Data Type Shape of data Description np_w_$VERSION$Numpy array (batch, 2000) ABP wave data, 20 second 100Hz segment np_sv_$VERSION$Numpy array (batch, ) Target SV value np_a_$VERSION$Numpy array (batch, 4) Demographic data with order of columns: age, sex, weight, height np_c_$VERSION$Numpy array (batch, ) Case ID's of each data point (used to split dataset on patients) $VERSION$indicates the version of dataset, which is for convenience of dataset management.
Values of$VERSION$can bepretrain,train,test, or other if different naming conventions are used in preprocessing. -
arr.py: Contains functions related to signal processing, such as detect_hr and detect_peaks. -
run_train.py: Contains the functions for model starting model training.load_datasets: Load the datasets from the .npy files. Load the waveform data from the .pt file if available. Divides the waveform data by 100 to bring it closer to the range of 0-1 for easier NN handling.split_datsets: Split the dataset into train, validation and test sets based on the unique ids in np_c.run_train: Function for the training process of one fold in K-Fold cross validation.main_train: The main model training process. Calls load_datasets and split datasets, creates the data generators for the train and validation set, then creates the network structure and calls run_train.
-
trainer.py: Contains the model training processes.class Datasets: Wrapper around the PyTorch data.Dataset for creating the data generators.validate: Function for the validation process. It evaluates the model on the validation set. Can be set to either do validation on GPU or on CPU. Validation can be done on full validation dataset each validation_interval or to calculate pseudo-validation loss on a random subset of validation batches each validation_interval {######## BATCH VALIDATION STILL NEEDS TO BE PROPERLY IMPLEMENTED! ########}.cosine_annealing_lr: Cosine annealing learning rate scheduler with hard restarts and linear LR warmup at the start of training.train_with_lr_scheduler: Trains the model using a learning rate scheduler. Selects the loss, optimizer, and learning rate scheduler based on the arguments passed to the function. Then loops over the epochs and internally loops over the batches. Calls the validate function after valid_interval batches. Saves the model with the best validation loss.
-
run_test:build_x_inference: Takes the input signals and returns a list that contains two tensors: one for the waveform and the other for the demographic information.main_test: Main function for testing the model. Loads the data, runs the test and saves the results to a .txt file.
-
apconet_packages/load_model.py: Contains the definition of the deep learning model. -
apconet_packages/model_functions_inference.py: Contains EarlyStopping class for early stopping during training. Also contains other functions and classes for model training and testing purposes. -
apconet_packages/ranger_optimizer.py: Ranger deep learning optimizer - RAdam + LookAhead. -
data_extract.py: Data extraction and preprocessing script. On the top of the file are settings for sampling rate and ventricular premature beats threshold and switches for which steps in the script to run. The steps are:load_pretrain_data_from_vitaldb: Extract all case ID records from VitalDB that have both the ABP and one of the FloTrac device tracks available. For each case ID record, extract 20-second samples from the ABP track before each SV entry. Perform LOWESS smoothing on the SV values to remove fluctuations that are clinically unlikely. Samples unsuitable for training the NN model are removed based on physiological thresholds (ABP, SV, HR, PP ranges and PVB removal). For each case ID, the remaining suitable samples are saved to a case ID .npy file for easy intermediate loading (also save overview of all included case ID's and number of samples to separate file). Next load the demographic data from the downloaded .csv file and create arrays in the correct format to input into the NN model. Saves these arrays as .npy files.load_train_test_data_from_csv: Load the data from the downloaded .csv files in the Train/Train folder and create arrays in the correct format to input into the NN model. Next, split the train data into an 80/20 train-test split and save as separate arrays in .npy files.load_flotrac_pac_data_from_vitaldb: Extract all case id's from VitalDB that have an ABP, one of the FloTrac devices, and the PAC track available in their record. Other steps are the same asload_pretrain_data_from_vitaldb.
-
data_preprocessing.py: Functions to support the data loading and preprocessing:load_record_for_case_id: Returns queried tracks for the given the case_id from a record if all tracks contain data.sample_from_record: Samples 20-second ABP segments before each SV entry from a recordlowess_smoothing: Performs LOWESS smoothing on the SV values to remove fluctuationsremove_unsuitable_samples: Removes samples unsuitable for training the NN modelread_demographic_data: Reads the demographic data from the downloaded .csv filecreate_arrays: Creates arrays in the correct format to input into the NN modelread_pretrain_data_to_arrays: Reads and re-formats .npy files for pretraining dataread_train_data_to_arrays: Reads and re-formats .csv files for training dataread_ground_truth_and_estimations: Reads the ground truth and estimated SVs from a .txt file
-
EDA.py: Contains classes and functions for exploratory data analysis. -
model_performance.py: Script to evaluate the performance of the model. -
run_plotter: Script to plot the results of the model. -
statistical_analysis.py: Script to perform statistical analysis on the data. -
other_packages/custom_plots.py: Contains functions for plotting the results. -
other_packages/extract_functions.py: Contains a functions for extracting dataget_sv_flotrac_and_pac: get all data from specified folder (1 level above separate_ids) and combined all .npy files and return all the data combined of the .npy data. .npy data should contain 2 columns 1 with SV of FloTrac, EV1000 and the second with SV of PAC, Vigilance II.
-
other_packages/statistics_functions.py: Contains different error function for model analysis.