Switch to unified view

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