Upload
others
View
7
Download
0
Embed Size (px)
Citation preview
SLEEP STAGE SCORING USING CNNs AND RNNs
SUMMER INTERNSHIP PROJECT REPORT
Deepak S 2016103516
Bhargav K 2016103514
Srikrishna B 2016103068
Ambika S 2016103007
COLLEGE OF ENGINEERING, GUINDY
ANNA UNIVERSITY: CHENNAI 600 025
MAY 2018
1. PROBLEM STATEMENT
Analyzing the sleep of patients, known as sleep stage scoring, is an expensive
and time-consuming process that cannot scale to a large number of people.
Using wearable EEG and automating sleep stage scoring is a potential solution
to this problem. In this project, a method to automate sleep stage scoring using
deep learning is brought forward.
2. FUNCTIONAL DESCRIPTION
Millions of people use smartphone apps, bedside monitors, and wearable items
including bracelets and smart watches to informally collect and analyze data
about their sleep. Smart technology can record sounds and movement during
sleep, journal hours slept, and monitors heartbeat and respiration. Using a
companion app, data from some devices can be synced to a smartphone or
tablet, or uploaded to a PC. The preliminary purpose though, is to do the same
using a person’s brain signals as opposed to recording sounds or movements.
The deep learning model consists of two neural networks that work
collaboratively to score sleep stages. The first network works on extracting time
invariant features which are then used by the second network to learn sleep
stage transition rules. From this learning experience, the network becomes
equipped to predict or score sleep stages from any input that’s given to it. The
output obtained can thus be used for sleep pattern analysis by experts who can
use these results to detect sleep-related disorders or the ill effects that irregular
or disrupted sleep patterns have on other bodily or cerebral functions. If
nurtured, the model will be mature enough to tabulate information on a timely
basis as against number of samples which will be helpful in deepening the scope
for research and may also greatly save manual labor and resource expenditure.
On an application level, it can be used to set an alarm by tapping information
from sleep stages that are classified against time intervals. This could paint a
clear picture in terms of when a person should be woken up within a desired
time frame. Using this information, the user is also informed about how much
more sleep he needs get in order to make up for all the time that he would have
spent sleeping in restlessness.
3. WORKFLOW
Fig 3.1 General workflow
3.1 SLEEP EDF DATASET
This collection of polysomnograms and hypnograms comes from two studies;
data from a study of age effects on sleep in healthy subjects and data from a
study of Temazepam effects on sleep. However, only the former was chosen to
compute the results. The PSG files are whole-night polysomnographic sleep
recordings containing EEG (from Fpz-Cz and Pz-Oz electrode locations), EOG
(horizontal), submental chin EMG, and an event marker; the SC* PSG.edf.
Files often also contain oro-nasal respiration and rectal body temperature.
The HYP files contain annotations of the sleep patterns that correspond to the
PSGs. These patterns (hypnograms) consist of sleep stages W, R, 1, 2, 3, 4, M
(Movement time) and ‘?’(not scored). All hypnograms were manually scored by
well-trained technicians. The SC files were obtained in a 1987-1991 study of
age effects on sleep in 79 healthy Caucasians aged 25-101, without any sleep-
related medication.
Two PSGs of about 20 hours each were recorded during two subsequent day-
night periods at the subjects' homes. The subjects currently included here,
numbers 00 through 19, are 10 males and 10 females, and were 25-34 years old
at the time of the recordings. Subjects continued their normal activities but wore
a modified Walkman-like cassette-tape recorder.
3.2 DATA PREPROCESSING
Pre-processing is a technique used to cleanse a raw data set. As the data had
been gathered as an amalgamation of signals from various cerebral cross-
sections, they had to be scripted to a format that is consumable by the neural
network. Hence, this technique had been adopted to differentiate the unknown
sleep stages from the known and discard all ambiguous data or in broader terms,
the ones corresponding to the minority sleep stages. Hence, the data along with
their respective labels were extracted from the EDF files and were later
transformed into NumPy arrays.
Fig 3.2 Input data
Fig 3.3 Data extraction
Fig 3.4 Label extraction
3.3 MODEL DESIGN
There are many applications that are equipped to predict a person’s sleep quality
based on their movements in bed or by recording their breathing patterns.
Lesser known are methods that can perform detailed studies using one’s brain
signals. This was the motivation behind scoring sleep stages using deep
learning. The neural network was used to accomplish this task as electrical
signals in general are sensitive and demand to be analyzed carefully. The model
learns how to differentiate between the five main sleep categories and classifies
a cluster of input samples by making an educated guess.
3.4 TRAINING
Training is the process by which a model learns how to coherently identify or
classify the data that it sees. To draw a parallel, it works similar to the human
brain where one learns how to recognize worldly entities by visually perceiving
them. Similarly, the model is trained to classify sleep stages by learning which
frequencies and amplitudes are best suited to each of the five main sleep
categories.
3.5 PREDICTION
Prediction is the process by which the model uses the information that it has
learnt in the past to classify unseen data. The model scores sleep stages using
the knowledge that gains from visiting the training inputs so as to accomplish
this feat.
4. RESULTS AND SCREENSHOTS
4.1 DATA PREPARATION
The prediction is to be made on data formatted as numpy arrays. For this, the
EDF files of arbitrary subjects are pre-processed and converted to the said
format. This data is then given as input to the neural network. The extraction of
features happens in the two CNN layers while the sleep transition stages are
learnt by the LSTM layers in the latter half of the algorithm. The working is
explicitly portrayed in the pictures given below.
Fig
4.1 CNN layer 1
Fig 4.2 CNN layer 2
Fig 4.3 Adding the CNN layers
Fig 4.4 LSTM cells
4.2 EVALUATION CRITERIA
Confusion Matrix
A confusion matrix is a table that is used to outline the efficiency of a
classification model on a set of test data for which the true values are known. It
contains information about actual and predicted classifications performed by a
classification system. Each column of the matrix depicts an instance in a
predicted class while each row depicts an instance in an actual class.
The confusion matrix for a given number of samples for two subjects is shown
in Figure 4.5
Recall
Recall measures the proportion of positives that are correctly identified as such.
It can be thought of as a measure of classifier’s completeness.
Precision
Precision is the fraction of relevant instances among the retrieved instances. It
can be thought of as a measure of a classifier’s exactness.
Accuracy
Accuracy is the number of correct predictions made out of the total number of
predictions made.
● True Positive (TP) : number of correctly recognized observations for
class a class C.
● False Positive (FP): number of observations that were incorrectly
assigned to a class C.
● True Negative (TN) : number of correctly recognized observations that do not belong to a class C.
● False Negative (FN) : number of observations that were not recognized as belonging to a class C.
Fig 4.5 Confusion matrix
The average accuracy is found to be : 89.8%
The predicted output is plotted in Figure 4.6 with the number of samples along
X-axis and classes along the Y-axis
Fig 4.6 Predicted output with X axis as Samples and
Y axis as Sleep Stage labels