a b/README.md
1
[![license](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](./LICENSE)
2
3
## ECG classification using MIT-BIH dataset 
4
5
This repo is an implementation of https://www.nature.com/articles/s41591-018-0268-3 and https://arxiv.org/abs/1707.01836
6
7
and focus on training using a MIT-BIH dataset. If you want to train using CINC or open irhythm data, see the open source which the authors of the original research paper have coded at https://github.com/awni/ecg
8
9
Introduction to MIT-BIH dataset at physionet : https://physionet.org/physiobank/database/mitdb/
10
11
### Dependency (Updated, April 1, 2025)
12
13
- Python == 3.12.9
14
- Flask==3.1.0
15
- gevent==24.11.1
16
- keras==3.9.1
17
- numpy==2.1.3
18
- pip-tools==7.4.1
19
- scikit-learn==1.6.1
20
- scipy==1.15.2
21
- six==1.17.0
22
- tensorflow==2.19.0
23
- tensorflow-metal==1.2.0
24
- tqdm==4.67.1
25
- Werkzeug==3.1.3
26
- wfdb==4.2.0
27
28
29
30
31
### Data setup and train 
32
33
I recommend using a vitual enviroment for Python, so run setup.sh in order to install and to activate it. 
34
```
35
$ git clone https://github.com/physhik/ecg-mit-bih.git
36
$ cd ecg-mit-bih
37
$ python -m venv ecg-env
38
$ source ./ecg-env/bin/activate
39
(ecg-env) $ pip install -r requrirements.txt
40
(ecg-env) $ python src/data.py --downloading True
41
(eng-env) $ python src/train.py
42
```
43
Now you have a trained model for ECG classification 
44
45
46
### Test
47
48
Predict an annotation of [CINC2017 data](https://physionet.org/challenge/2017/) or your own data(csv file)
49
50
It randomly chooses one of data, and predict the slices of the signal.
51
52
Run predict.py in the virtual environment we have already set up.
53
```
54
(ecg-env) $ python src/predict.py --cinc_download True
55
```
56
--cinc_download branch is used at first to download the CINC2017 data.
57
58
See src/config.py and customize your parameters or learn better way to train and test 
59
60
61
### Jupyter notebook example
62
63
In case, you do not have a GPU above a decent performance, you might be able to use Google colab. Follow the [Jupyter notebook](https://github.com/physhik/ecg-mit-bih/blob/master/src/practice/ecg_mit.ipynb).
64
65
66
### Flask web app
67
68
The flask web app is based on the keras-flask-deploy [Github repo](https://github.com/mtobeiyf/keras-flask-deploy-webapp). 
69
70
#### Run app.py
71
```
72
(ecg-env) $ python src/app.py
73
```
74
75
![png](src/static/asset/capture1.png)
76
77
and choose a csv heart heat signal and click predict, and see the result. 
78
79
![png](src/static/asset/capture2.png)
80
81
I have put one csv file in static/asset directory. The first value of the column become sample rate of the web app. If you use your own heart beat csv file, insert the sample at the first, too.   
82
83
### Using Docker, Buld and run an image for the ECG trained model.(Not yet updated)
84
85
86
After installation of Docker, 
87
88
```
89
$ docker-compose up -d .  
90
```
91
92
93
94
### Introduction to ECG 
95
96
I presented a bit more about ECG classfications on my personal blog, http://physhik.github.io 
97
98
Find the posts from tags or categories easily.  
99
100
### Reference to 
101
102
The original research papers
103
https://www.nature.com/articles/s41591-018-0268-3
104
https://arxiv.org/abs/1707.01836
105
106
The open source by authors
107
https://github.com/awni/ecg
108
109
also noticable 
110
https://github.com/fernandoandreotti/cinc-challenge2017/tree/master/deeplearn-approach