• Stars
    star
    148
  • Rank 249,983 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

CNN for heartbeat classification

ECG_Heartbeat_Classification

Description of the approach : https://blog.goodaudience.com/heartbeat-classification-detecting-abnormal-heartbeats-and-heart-diseases-from-ecgs-913449c2665

Requirement : Keras, tensorflow, numpy

Heartbeat Classification : Detecting abnormal heartbeats and heart diseases from

ECGs

Figure 1 : https://en.wikipedia.org/wiki/Electrocardiography

An ECG is a 1D signal that is the result of recording the electrical activity of the heart using an electrode. It is one of the tool that cardiologists use to diagnose heart anomalies and diseases.

In this blog post we are going to use an annotated dataset of heartbeats already preprocessed by the authors of this paper to see if we can train a model to detect abnormal heartbeats.

Dataset

The original datasets used are the MIT-BIH Arrhythmia Dataset and The PTB Diagnostic ECG Database that were preprocessed by [1] based on the methodology described in III.A of the paper in order to end up with samples of a single heartbeat each and normalized amplitudes as :

Figure 2 : Example of preprocessed sample from the MIT-BIH dataset

MIT-BIH Arrhythmia dataset :

  • Number of Categories: 5
  • Number of Samples: 109446
  • Sampling Frequency: 125Hz
  • Data Source: Physionet’s MIT-BIH Arrhythmia Dataset
  • Classes: [’N’: 0, ‘S’: 1, ‘V’: 2, ‘F’: 3, ‘Q’: 4]

The PTB Diagnostic ECG Database

  • Number of Samples: 14552
  • Number of Categories: 2 ( Normal vs Abnomal)
  • Sampling Frequency: 125Hz
  • Data Source: Physionet’s PTB Diagnostic Database

The published preprocessed version of the MIT-BIH dataset does not fit the description that authors provided of it in their paper as the former is heavily unbalanced while the latter is not. This made it so my results are not directly comparable to theirs. I sent the authors an email to have the same split as them and I’ll update my results if I get a reply. A similar issue exists for the PTB dataset.

Model

Similar to [1] I use a neural network based on 1D convolutions but without the residual blocks :

Figure 3 : Keras model

Code :

Results

MIT-BIH Arrhythmia dataset :

  • Accuracy : 98.5
  • F1 score : 91.5

The PTB Diagnostic ECG Database

  • Accuracy : 98.3
  • F1 score : 98.8

Transferring representations

Since the PTB dataset is much smaller than the MIT-BIH dataset we can try and see if the representations learned from MIT-BIH dataset can generalize and be useful to the PTB dataset and improve the performance.

This can be done by loading the weights learned in MIT-BIH as initial point of training the PTB model.

From Scratch :

  • Accuracy : 98.3
  • F1 score :** 98.8**

Freezing the Convolution Layer and Training the Fully connected ones :

  • Accuracy : 95.6
  • F1 score : 96.9

Training all layers :

  • Accuracy : 99.2
  • F1 score : 99.4

We can see the freezing the first layers does not work very well. But if we initialize the weights with those learned on MIT-BIH and train all layers we are able to improve the performance compared to training from scratch.

Code to reproduce the results is available at : https://github.com/CVxTz/ECG_Heartbeat_Classification

More Repositories

1

image_search_engine

Image search engine
Python
232
star
2

time_series_forecasting

Python
194
star
3

EEG_classification

EEG Sleep stage classification using CNN with Keras
Python
145
star
4

medical_image_segmentation

Medical image segmentation ( Eye vessel segmentation)
Python
124
star
5

audio_classification

CNN 1D vs 2D audio classification
Jupyter Notebook
103
star
6

recommender_transformer

Python
82
star
7

graph_classification

Learning from graph data using Keras
Python
64
star
8

music_genre_classification

music genre classification : LSTM vs Transformer
Python
61
star
9

rubiks_cube

Rubik's Cube solver using reinforcement learning
Python
53
star
10

kinship_prediction

Deep Neural Networks for Kinship prediction using face photos
Python
47
star
11

face_age_gender

Can we predict the age and gender of someone given a picture of their face ?
Python
42
star
12

COLA_pytorch

COLA contrastive pre-training method implemented in PyTorch
Python
40
star
13

DeepTabular

Python
37
star
14

fingerprint_denoising

U-Net for fingerprint denoising
Python
26
star
15

IntegratedGradientsPytorch

Integrated gradients attribution method implemented in PyTorch
Python
23
star
16

sudoku_solver

Solving a Sudoku Puzzle from a screenshot
Python
22
star
17

llm-serve-tutorial

Python
21
star
18

RL

RL algorithm implementations from scratch.
Python
17
star
19

distill-llm

Python
17
star
20

FastImageClassification

A Step-By-Step tutorial to build and deploy an image classification API
Python
14
star
21

Recommender_keras

Basic recommendation system for Movilens dataset using Keras
Python
12
star
22

xumi

Python
9
star
23

ner_playground

Python
6
star
24

celery_ml_deploy

Python
6
star
25

knowledge_distillation

Knowledge Distillation
Python
5
star
26

gcp_model_deploy_example

Python
5
star
27

handwriting_forensics

Python
5
star
28

TagSuggestionImages

Suggest multiple Tags/Labels that better fit an image
Python
4
star
29

active_learning

Active Learning Applied to image and tabular data
Python
4
star
30

code_search

Python
4
star
31

nicegui_tutorial

Python
4
star
32

learning_to_abstain

Know what you don't know
Python
3
star
33

malignancy_detection

malignancy detection using CNNs with Keras
Python
3
star
34

LLM-Voice

Python
3
star
35

ReconstructionAuxLoss

Improve Neural Network's Generalization Performance By Adding an Unsupervised Auxiliary Loss - Pytorch Lightning
Python
2
star
36

bleach_bot

Python
2
star
37

doc-llm

Python
2
star
38

interpretable_nlp

Python
1
star
39

streamlit_demo

Python
1
star
40

prefect_mlops

1
star
41

dimensionality_reduction

HTML
1
star
42

ToyImageClassificationDataset

Toy Image Classification Dataset Annotated with Labelme
Python
1
star
43

constrained_llm_generation

Python
1
star