{"id":15358076,"url":"https://github.com/antonior92/automatic-ecg-diagnosis","last_synced_at":"2025-09-12T11:49:43.786Z","repository":{"id":39728413,"uuid":"234625472","full_name":"antonior92/automatic-ecg-diagnosis","owner":"antonior92","description":"Scripts and modules for training and testing neural network for ECG automatic classification. Companion code to the paper  \"Automatic diagnosis of the 12-lead ECG using a deep neural network\". ","archived":false,"fork":false,"pushed_at":"2023-03-25T00:40:18.000Z","size":720,"stargazers_count":378,"open_issues_count":5,"forks_count":125,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-22T18:03:05.750Z","etag":null,"topics":["atrial-fibrillation","atrial-fibrillation-detection","convolutional-neural-networks","deep-learning","ecg","ecg-classification","ecg-signal"],"latest_commit_sha":null,"homepage":"https://www.nature.com/articles/s41467-020-15432-4","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/antonior92.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-01-17T19:53:47.000Z","updated_at":"2025-03-21T09:56:28.000Z","dependencies_parsed_at":"2022-08-28T03:11:33.593Z","dependency_job_id":"87102f42-a9bc-476f-8d51-841330337168","html_url":"https://github.com/antonior92/automatic-ecg-diagnosis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonior92%2Fautomatic-ecg-diagnosis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonior92%2Fautomatic-ecg-diagnosis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonior92%2Fautomatic-ecg-diagnosis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antonior92%2Fautomatic-ecg-diagnosis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antonior92","download_url":"https://codeload.github.com/antonior92/automatic-ecg-diagnosis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246230523,"owners_count":20744347,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atrial-fibrillation","atrial-fibrillation-detection","convolutional-neural-networks","deep-learning","ecg","ecg-classification","ecg-signal"],"created_at":"2024-10-01T12:39:53.664Z","updated_at":"2025-03-29T19:04:29.554Z","avatar_url":"https://github.com/antonior92.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Automatic ECG diagnosis using a deep neural network\nScripts and modules for training and testing deep neural networks for ECG automatic classification.\nCompanion code to the paper \"Automatic diagnosis of the 12-lead ECG using a deep neural network\".\n https://www.nature.com/articles/s41467-020-15432-4.\n\n--------\n\nCitation:\n```\nRibeiro, A.H., Ribeiro, M.H., Paixão, G.M.M. et al. Automatic diagnosis of the 12-lead ECG using a deep neural network.\nNat Commun 11, 1760 (2020). https://doi.org/10.1038/s41467-020-15432-4\n```\n\nBibtex:\n```\n@article{ribeiro_automatic_2020,\n  title = {Automatic Diagnosis of the 12-Lead {{ECG}} Using a Deep Neural Network},\n  author = {Ribeiro, Ant{\\^o}nio H. and Ribeiro, Manoel Horta and Paix{\\~a}o, Gabriela M. M. and Oliveira, Derick M. and Gomes, Paulo R. and Canazart, J{\\'e}ssica A. and Ferreira, Milton P. S. and Andersson, Carl R. and Macfarlane, Peter W. and Meira Jr., Wagner and Sch{\\\"o}n, Thomas B. and Ribeiro, Antonio Luiz P.},\n  year = {2020},\n  volume = {11},\n  pages = {1760},\n  doi = {https://doi.org/10.1038/s41467-020-15432-4},\n  journal = {Nature Communications},\n  number = {1}\n}\n```\n-----\n\n## Requirements\n\nThis code was tested on Python 3 with Tensorflow `2.2`. There is an older branch ([`tensorflow-v1`](https://github.com/antonior92/automatic-ecg-diagnosis/tree/tensorflow-v1)) that \ncontain the code implementation for Tensorflow `1.15`.\n\n**For pytorch users:** If you are interested in a pytorch implementation, take a look in the repository: https://github.com/antonior92/ecg-age-prediction. \nThere we provide a implementation in PyTorch of the same resnet-based model. The problem there is the age prediction from the ECG, nontheless simple modifications should suffice for dealing with abnormality classification.\n\n## Model\n\nThe model used in the paper is a residual neural. The neural network architecture implementation in Keras is available in ``model.py``. To print a summary of the model layers run:\n```bash\n$ python model.py\n```\n\n![resnet](https://media.springernature.com/full/springer-static/image/art%3A10.1038%2Fs41467-020-15432-4/MediaObjects/41467_2020_15432_Fig3_HTML.png?as=webp)\n\nThe model receives an input tensor with dimension `(N, 4096, 12)`, and returns an output tensor with dimension `(N, 6)`,\nfor which `N` is the batch size.\n\nThe model can be trained using the script `train.py`. Alternatively,\npre-trained weighs for the models described in the paper are also \navailable in: https://doi.org/10.5281/zenodo.3625017. Or in the mirror dropbox \nlink [here](https://www.dropbox.com/s/5ar6j8u9v9a0rmh/model.zip?dl=0).  \nUsing the command line, the weights can be downloaded using\n```\nwget https://www.dropbox.com/s/5ar6j8u9v9a0rmh/model.zip?dl=0 -O model.zip\nunzip model.zip\n```\n\n- **input**: `shape = (N, 4096, 12)`. The input tensor should contain the  `4096` points of the ECG tracings\nsampled at `400Hz` (i.e., a signal of approximately 10 seconds). Both in the training and in the test set, when the\nsignal was not long enough, we filled the signal with zeros, so 4096 points were attained. The last dimension of the \ntensor contains points of the 12 different leads. The leads are ordered in the following order: \n`{DI, DII, DIII, AVR, AVL, AVF, V1, V2, V3, V4, V5, V6}`. All signal are represented as\n32 bits floating point numbers at the scale 1e-4V: so if the signal is in V it should be multiplied by \n1000 before feeding it to the neural network model. \n\n\n- **output**: `shape = (N, 6)`. Each entry contains a probability between 0 and 1, and can be understood as the\nprobability of a given abnormality to be present. The abnormalities it predicts are  **(in that order)**: 1st degree AV block(1dAVb),\n right bundle branch block (RBBB), left bundle branch block (LBBB), sinus bradycardia (SB), atrial fibrillation (AF),\nsinus tachycardia (ST).  The abnormalities are not mutually exclusive, so the probabilities do not necessarily\nsum to one. \n\n![abnormalities](https://media.springernature.com/full/springer-static/image/art%3A10.1038%2Fs41467-020-15432-4/MediaObjects/41467_2020_15432_Fig1_HTML.png?as=webp)\n\n## Datasets\n\n- The testing dataset described in the paper can be downloaded in:\n[doi: 10.5281/zenodo.3625006](https://doi.org/10.5281/zenodo.3625006). There is also  a mirror\ndropbox link [here](https://www.dropbox.com/s/p3vd3plcbu9sf1o/data.zip?dl=0). \nUsing the command line:\n```\nwget https://www.dropbox.com/s/p3vd3plcbu9sf1o/data.zip?dl=0 -O data.zip\nunzip data.zip\n```\n- Part of the training data (the CODE-15\\% dataset) is openly available in: [doi: 10.5281/zenodo.4916206 ](https://doi.org/10.5281/zenodo.4916206).\n- The full CODE dataset that was used for training is available upon request for research purposes: [doi: 10.17044/scilifelab.15169716](https://doi.org/10.17044/scilifelab.15169716)\n\n## Scripts\n\n- ``train.py``: Script for training the neural network. To train the neural network run: \n```bash\n$ python train.py PATH_TO_HDF5 PATH_TO_CSV\n```\nPre-trained models obtained using such script can be downloaded from [here](https://doi.org/10.5281/zenodo.3625017)\n\n\n- ``predict.py``: Script for generating the neural network predictions on a given dataset.\n```bash\n$ python predict.py PATH_TO_HDF5_ECG_TRACINGS PATH_TO_MODEL  --ouput_file PATH_TO_OUTPUT_FILE \n```\nThe folder `./dnn_predicts` contain the output obtained by applying this script to the models available in\n[here](https://doi.org/10.5281/zenodo.3625017) to make the predictions on tracings from \n[this test dataset](https://doi.org/10.5281/zenodo.3625006).\n\n\n- ``generate_figures_and_tables.py``: Generate figures and tables from the paper \"Automatic Diagnosis o\nthe Short-Duration12-Lead ECG using a Deep Neural Network\". Make sure to execute the script from the root folder,\nso all relative paths are correct. So first run:\n```\n$ cd /path/to/automatic-ecg-diagnosis\n```\nThen the script\n ```bash\n$ python generate_figures_and_tables.py\n```\nIt should generate the tables and figure in the folder `outputs/`\n\n- ``model.py``: Auxiliary module that defines the architecture of the deep neural network.\nTo print a summary of the model  layers run:\n```bash\n$ python model.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonior92%2Fautomatic-ecg-diagnosis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantonior92%2Fautomatic-ecg-diagnosis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantonior92%2Fautomatic-ecg-diagnosis/lists"}