Input: XML file(s)
Ouput: ECG tracing file(s) (.csv) and diagnosis label file (.csv)
Before running the script, please define 3 variables in the script:
data_root_folder = '<Replace this string with the path of the folder where the XML files are stored>'
output_root_folder = '<Replace this string with the path of the output target folder>'
output_file_name = '<Replace this string with the name of the output label csv file>'
# e.g.
data_root_folder = './Lab_project/ECG/sample_2021_4_6/raw_data/'
output_root_folder = './Lab_project/ECG/sample_2021_4_6/'
output_file_name = 'sample_data_label_summary.csv'Ribeiro, A.H., Ribeiro, M.H., Paixão, G.M.M. et al. Automatic diagnosis of the 12-lead ECG using a deep neural network.
Nat Commun 11, 1760 (2020). https://doi.org/10.1038/s41467-020-15432-4
- The scripts and detail of this model are available at: Here
- Model Download: Here
- Test Data Download: Here
- numpy>=1.14.3
- pandas>=0.22
- tensorflow=2.2
- h5py>=2.8
- xmljson>=0.1.9
- scipy>=1.1
- scikit-learn>=0.20
- tqdm>=4.26
- xarray>=0.11.2
- seaborn>=0.9
- openpyxl>=3.0
Activate the anaconda.
conda activateEnter the python environment.
conda activate <name of environment>e.g.
conda activate ecgEnter the folder where the "automatic-ecg-diagnosis" repository was cloned.
cd <path of folder>e.g.
cd /user/scripts/ECG/automatic-ecg-diagnosis-master/Run the script.
python predict.py <path to test data (HDF5 file)> <path to model (HDF5 file)>e.g.
python predict.py ./data/ecg_tracings.hdf5 ./model/model.hdf5The prediction result is stored in the file dnn_output.npy, it is located in the same folder that appeared in STEP 3.
Load & convert the prediction result from probability to binary label.
- Copy script
script_7_prob2bin.pyfrom this repository to the same folder that appeared in STEP 3. - Define the paths in the script.
data_path = '<Replace this string with the path of prediction result file (dnn_output.npy)>'
outout_path = '<Replace this string with the path of output transformed file path + / + output transformed file name>'
# e.g.
data_path = './automatic-ecg-diagnosis-master/dnn_output.npy'
outout_path = './automatic-ecg-diagnosis-master/dnn_output_bin.csv'- Save & Run the script.
python script_7_prob2bin.py- The converted binary prediction results will be stored in the specified folder as a CSV file.
Your binary prediction result should be exactly the same as the content of file dnn_output_bin.csv
Extract ECG signals from xml file as a csv file by using ECGToolkit. (:warning: Windows Only :warning:) (script_0_xml2csv.bat)
cd <The path to the folder of xml2csv.bat>
script_0_xml2csv <The path to the folder of ECG toolkit> <The path to the folder of HL7 xml files> <The path to the folder of output csv files>NOTE: <The path to the folder of ECG toolkit>, this folder should be exactly the same as the image below.

e.g.
cd D:\ECG\
script_0_xml2csv D:\ECG\ECGToolkit\ D:\ECG\ECG_data_2batch\1dAVB\ D:\ECG\ECG_data_2batch_csv\1dAVB\Diagnosis conclusion extraction. (script_1_label_extract.py)
ECG signals resampling, from 500Hz to 400Hz. (script_2_ecg_resample.py)
Scale ECG signals, ECG signal X/600 currently. (script_3_scale.py)
ECG signals padding, 4000x12 to 4096x12 (script_4_padding.py)
Pack padded csv files into hdf5 file. (script_5_csv2hdf5.py)
Sort the ground truth label with the same order as data saved in the hdf5 file (script_6_order_label.py)