Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Arrhythmia Detection Using Convolutional

Neural Models

Jorge Torres Ruiz1(&), Julio David Buldain Pérez2,


and José Ramón Beltrán Blázquez2
1
Accenture, María Zambrano 31, 50018 Zaragoza, Spain
jorge.torres.ruiz93@gmail.com
2
Department of Electronic and Communication Engineering,
University of Zaragoza, 50018 Zaragoza, Spain
{buldain,jrbelbla}@unizar.es

Abstract. Mostly all works dealing with ECG signal and Convolutional Net-
work approach use 1D CNNs and must train them from scratch, usually
applying a signal preprocessing, such as noise reduction, R-peak detection or
heartbeat detection. Instead, our approach was focused on demonstrating that
effective transfer learning from 2D CNNs can be done using a well-known CNN
called AlexNet, that was trained using real images from ImageNet Large Scale
Visual Recognition Challenge (ILSVRC) 2012. From any temporal signal, it is
possible to generate spectral images (spectrograms) than can be analysed by 2D
CNN to do the task of extracting automatic features for the classification stage.
In this work, the power spectrogram is generated from a randomly ECG seg-
ment, so no conditions of signal extraction are applied. After processing the
spectrogram with the CNN, its outputs are used as relevant features to be dis-
criminated by a Multi Layer Perceptron (MLP) which classifies them into
arrhythmic or normal rhythm segments. The results obtained are in the 90%
accuracy range, as good as the state of the art published with 1D CNNs, con-
firming that transfer learning is a good strategy to develop decision models in
signal and image medical tasks.

Keywords: Neural network  Transfer learning  Electrocardiogram


Arrhythmia detection  Convolutional network  Spectrogram

1 Introduction

An electrocardiogram (ECG) is a medical test that helps doctors to diagnose heart


pathologies. This signal is recorded with a series of electrodes placed over the patient’s
body, typically on his chest, that measure the heart’s electrical activity. Over the years,
algorithms have tried to help doctors in ECG analysis exploring several ways such as
eliminating noise, marking the beat’s starting point or calculating the beat variability
[1–4]. But, as ECG is a very complex signal, algorithms have problems to produce a
real diagnosis. Recently, machine learning has entered in this field to overcome these
difficulties. Bibliography shows that neural networks output outstanding results,

© Springer International Publishing AG, part of Springer Nature 2019


F. De La Prieta et al. (Eds.): DCAI 2018, AISC 800, pp. 120–127, 2019.
https://doi.org/10.1007/978-3-319-94649-8_15
Arrhythmia Detection Using Convolutional Neural Models 121

reaching over 90% accuracy in arrhythmia detection and, in some particular applica-
tions, using deep learning the results increase almost to 100%, as in Kiranyaz et al. [5].
Most studies use electrocardiographic signals and apply some type of preprocessing
to train neural networks in ECG analysis. We have tried to explore this classification
problem from a different point of view. This paper’s main idea was inspired in the
research carried by Nguyen and Bui [6]. They tried to classify vocal audio signals using
their spectrogram for searching similarities with other previously classified spectro-
grams. Following this idea, we used a convolutional neural network (CNN) to extract
automatically characteristics from spectrograms which have been generated from ECG
segments.
Several studies have used CNNs to extract features from ECG signals and evaluate
these features for different purposes such heartbeat classification or QRS detection.
Rajendra et al. [7] trained a 1D CNN in order to extract characteristics from ECG beat
and classified them into five different heartbeat types (non-ectopic, supraventricular
ectopic, ventricular ectopic, fusion and unknown). They used wavelets to remove noise
and a R-peak detection algorithm to segment the signal into heartbeats for feeding the
CNN. The output layer from the CNN was a fully-connected layer with five neurons
which determine the heartbeat type from the fed ECG beat. In a similar way, Pyakillya
et al. [8] tried to classify heartbeats into four different types (normal sinus rhythm,
arrhythmic, other kind of rhythm and very noisy) using a 1D CNN. They preprocessed
the signal by applying standard procedures like mean subtraction and fed the CNN with
that data, where its last layer was a softmax layer with four outputs. On the other hand,
Xiang et al. [9] combined two 1D CNNs in order to automatically detect QRS complex
from ECG signals. They fed one CNN with ECG segments, that were preprocessed by
averaging and difference operations, to extract coarse-grained features. Another CNN
was fed with ECG segments preprocessed by difference operation to extract fine-
grained features. The features extracted from both CNNs were concatenated and sent to
a MLP which determines if a QRS complex appears in the signal received.
Mostly all works dealing with ECG signal and CNN approach use 1D CNNs and
must train them from scratch, usually applying a signal preprocessing, such noise
reduction, R-peak detection or heartbeat detection. Instead, our approach was focused
on demonstrating that effective transfer learning from 2D CNNs can be done using a
well known CNN architecture trained by Krizhevsky et al. [10] called AlexNet.
This CNN was trained using real images from ImageNet Large Scale Visual Recog-
nition Challenge (ILSVRC) 2012. ImageNet consists of 1.2 million 256  256 images
belonging to 1000 categories. In Hoo-Chang et al. [11] it is proposed that this transfer
learning can accelerate substantially the model development when using images in
medical decision models. Instead of using the temporal signal, it is possible to generate
spectral images (spectrograms) than can be analysed by 2D CNN to do the same task of
extracting automatic features for the classification stage. In this work, the power
spectrogram is generated from a randomly ECG segment, so no conditions of signal
extraction are applied. The phase spectrogram is not included in this analysis and is left
to future works to determine if its inclusion is useful or not. The only specification of
the spectrogram image is that it must be adjusted to fit with the input of the AlexNet.
After the CNN has processed the spectrogram, its outputs are used as relevant features
to be discriminated by a Multi Layer Perceptron (MLP) which classifies them into
122 J. T. Ruiz et al.

arrhythmic or normal rhythm segment. Fine tuning of the AlexNet was not applied
during the learning stage of the MLP.
We have used the MIT-BIH Arrhythmia Database [12] to generate training and
validation samples. This database has become one of the most popular databases used
in arrhythmia detection or classification. It contains 48 half-hour records where each
record presents two electrocardiograms took on different derivations. All electrocar-
diograms have been revised by independent cardiologists, marking the beginning of
each beat, the type of beat and additional information such as rhythm changes or noise
artefacts. These characteristics make the database well suited for machine learning.
In the next section, the methodology for generating input data to the models is
explained. Section 3 shows the first experiment results, using the outputs of the second
convolutional layer of AlexNet as features for a MLP with one hidden layer. Section 4
deals with the results obtained when the MLP has two hidden layers, and Sect. 5
explain a second experiment where the output of the last convolutional layer from the
CNN is used as features, showing that results get better as deeper is the representation
used from the CNN. Last section makes a discussion and proposes future
investigations.

2 Methodology

From each signal in the database, we extracted segments of 2048 samples in both
derivations with same starting point randomly generated. For both segments we cal-
culated their spectrogram using a Hamming window of 2048/60 samples and 50%
overlapping, without applying a low-pass filter. The frequency range covered up to
360 Hz, which is the maximum frequency present in the ECGs from the database
(Fig. 1).

Fig. 1. Left image shows a ECG segment from one signal in MIT-BIH database. The image at
the right plots a segment extracted from the same patient’s signal but with the second derivation.

The trained convolutional network (AlexNet) chosen for the feature extraction stage
requires an image input of size 227  227 pixels, for this reason we decided to
combine spectrograms from both derivations to generate this input image format, by
Arrhythmia Detection Using Convolutional Neural Models 123

generating a matrix of 227  114 elements from the first spectrogram and a matrix of
227  113 elements from the second. We scaled each matrix to range [0–255] in order
to store the data as images with one byte per pixel. With both matrixes scaled to the
same range, we combined them over the temporal axis saving the result as a grayscale
image.
From each electrocardiogram record stored in the database, we have generated 602
images, being 301 from its first half signal and another 301 images from the second
half. We have used the first half samples for training and the second ones for validating
the MLPs (Fig. 2).

Fig. 2. Both figures show spectrograms generated from signal segments with 2048 samples,
where the left one has been taken from a normal rhythm patient and the right one corresponds to
an ill patient with a heart pathology. It can be noticed that the heart pathology changes the rhythm
that a normal heart would make, having more power across its higher frequencies.

3 First Experiment

As first experiment, the spectrogram images were processed by AlexNet, extracting its
activations on the second convolutional layer. This decision was based in the fact that
higher layers in a convolutional network tend to present specialized filters for the kind
of objects that the images used for training contain. As AlexNet was trained with real
world images, we expected to eliminate this filter particularization influence by using
low level layers activations as the first trial. So, we used these characteristics to train
one MLP that will detect if the segment contains arrhythmic beats. We configured a
MLP with one hidden layer and one sigmoid neuron on its output layer, which will
output a response in range [0–1], where 0 means that the segment contains arrhythmic
beats and 1 that the beats are normal.
We varied the number of hidden neurons over different trials in order to estimate
the number of hidden neurons that gets the best classification, trying with 60, 80, 100,
110, 120, 130, 150 and 200 neurons. Finally, we calculated the confusion matrix for
each classifier in order to compare their classifying performance, extracting the clas-
sification measures: TPR (true positive rate), FNR (false negative rate), FPR (false
positive rate), TNR (true negative rate), PPV (possible predictive value), FDR (false
124 J. T. Ruiz et al.

discovery rate), FOR (false omission rate), NPV (negative predictive value), and the
overall accuracy. As Fig. 3 shows, the classifier with 130 hidden neurons achieves the
best results, having an accuracy over 85%.

Fig. 3. Overall, the classifiers with one hidden layer give an accuracy between 82% and 85%.
The best test results are achieved by the MLP with 130 hidden neurons, reaching an accuracy of
85.3%. Also, the false positive rate and the false negative rate are below 20%.

4 Test for MLP with Two Hidden Layers

After seeing that a MLP with one hidden layer can classify segments with more than
80% accuracy, we tested if a two hidden layer MLP can improve the results. Increasing
the number of hidden layers of a MLP allows to generate better decision regions when
the problem presents a non-linear behavior. We used a pyramidal architecture with a
larger number of neurons in the first hidden layer and a small number in the second,
trying with 100-25-1, 120-30-1, 120-50-1 and 300-100-1 architectures. Overall the
results increased in a 2% respect to the previous classifiers. The test classification
results are shown in Fig. 4.

5 Second Experiment

As second experiment, we tested if extracting the activations on the last convolutional


layer from AlexNet can improve the results. This idea was inspired in the research
carried by Simonyan and Zisserman [13] where they claim that increasing the number
of convolutional layers helps in the image processing. So, we trained the previous
MLPs with activations extracted from the last convolutional layer. The test results are
shown in Fig. 5. Overall, all the classifiers improved the results that achieved in the
Arrhythmia Detection Using Convolutional Neural Models 125

Fig. 4. Results from classifiers with two hidden layers improved the overall results about 1–2%,
reaching the MLP with 120 neurons on its first layer and 30 on its last hidden layer an accuracy
of 86%.

first experiment. This result is shocking when we consider that the last convolutional
layer of the AlexNet includes specialized filters that recognize shapes of real world
things like cars, dogs, houses etc. Even with this set of filters, so little adapted to the
kind of images present in a spectrogram, increasing the depth of the CNN substantially
improves the results of the classification. The best result gives an accuracy around 90%

Fig. 5. Results from classifiers trained with activations from the AlexNet’s last convolutional
layer. The accuracy increased almost 4 points compared to the previous experiment, getting close
to 90% accuracy. MLP with two hidden layer and architecture of 120 neurons on its first hidden
layer and 30 on its second hidden layer gives an accuracy of 89.9%, classifying the arrhythmic
segments with 89.7% precision and the normal segments with 90.1%.
126 J. T. Ruiz et al.

and was obtained for the MLP with two hidden layers, with 120 and 30 neurons, which
was trained with activations from the last convolutional layer.

6 Conclusions and Future Work

We tried transfer learning method to explore a new way of analysing the electrocar-
diograms, avoiding the hand-made signal preprocessing and extracting the relevant
characteristics automatically. The results show that our first try can classify ECG
segments with a 90% accuracy, which is in the state of the art level. This good result is
obtained with a convolutional network generated with real world images, instead of
spectrograms images, which confirms that transfer learning strategy can be applied
easily as first development stage in medical image classification tasks. As we do not
apply any fine-tuning of the CNN, we can think that the classification accuracy could
increase a few more points with simple improvements. Our main interest for future
research is to generate CNNs, specifically trained for analysing spectrograms of electric
signals, that can be used as transferable modules for automatic feature generation in
other biomedical fields as electroencephalography and electromyography. Another
aspect to explore is if phase coefficients can contribute to get better accuracy, also dealt
and processed with specifical CNNs. Another interesting goal is that the exact classi-
fication type of the arrhythmia signal could be tried with this methodology.

Acknowledgements. We would like to thank the company Sallén Tech of the Gunnevo group
for financing the publication of this work.

References
1. Ho, K.K.L., Moody, G.B., Peng, C.-K.: Predicting survival in heart failure cases and controls
using fully automated methods for deriving nonlinear and conventional indices of heart rate
dynamics. Circulation 96, 842–848 (1997)
2. Thakor, N.V., Zhu, Y.-S.: Applications of adaptive filtering to ECG analysis: noise
cancellation and arrhythmia detection. IEEE Trans. Biomed. Eng. 38(8), 785–794 (1991)
3. Antunes, E., Brugada, J., Steurer, G., Andries, E., Brugada, P.: The Differential Diagnosis of
a Regular Tachycardia with a Wide QRS Complex on the 12-Lead ECG: Ventricular
Tachycardia, Supraventricular Tachycardia with Aberrant Intraventricular Conduction, and
Supraventricular Tachycardia with Anterograde Conduction over an Accessory Pathway
(1994)
4. Tsipouras, M.G., Fotiadis, D.I., Sideris, D.: An arrhythmia classification system based on the
RR-interval signal. Artif. Intell. Med. 33, 237–250 (2005)
5. Kiranyaz, S., Ince, T., Hamila, R., Gabbouj, M.: Convolutional neural networks for patient-
specific ECG classification. In: 37th IEEE Engineering in Medicine and Biology Society
Conference (EMBC 2015) (2015)
6. Nguyen, Q.T., Bui, T.D.: Speech classification using SIFT features on spectrogram images.
Vietnam J. Comput. Sci. 3(4), 247–257 (2016)
7. Acharyaa, U.R., Oha, S.L., Hagiwaraa, Y., Tana, J.H., Adama, M., Gertychd, A., Sane, T.R.:
A deep convolutional neural network model to classify heartbeats. Comput. Biol. Med. 89,
389–396 (2017)
Arrhythmia Detection Using Convolutional Neural Models 127

8. Pyakillya, B., Kazachenko, N., Mikhailovsky, N.: Deep learning for ECG classification. IOP
Conf. Series J. Phys. Conf. Series 913 (2017). 012004
9. Xiang, Y., Lin, Z., Meng, J.: Automatic QRS complex detection using two-level
convolutional neural network. BioMed. Eng. OnLine (2018)
10. Krizhevsky, A., Sutskever, I., Hinton, G.E.: ImageNet classification with deep convolutional
neural networks. In: NIPS (2012)
11. Hoo-Chang, S., Roth, H.R., Gao, M., Le, L., Ziyue, X., Nogues, I., Yao, J., Mollura, D.,
Summers, R.M.: Deep convolutional neural networks for computer-aided detection: CNN
architectures, dataset characteristics and transfer learning. IEEE Trans. Med. Imaging 35(5),
1285–1298 (2016)
12. MIT-BIH Arrhythmia Database [Internet]. Harvard-MIT Division of Health Sciences and
Technology (1980). https://www.physionet.org/physiobank/database/mitdb/. Accessed Feb
2018
13. Simonyan, K., Zisserman, A.: Very deep convolutional networks for large-scale image
recognition. In: ICLR (2015)

You might also like