# Classification of Sleep Stage with Biosignal Images Using Convolutional Neural Networks
## 4 Sleep-Stage Classification Using CNN
### Structure of CNN Model  
Deep learning is a kind of machine learning algorithm. In recent years, classification techniques using deep learning have shown excellent performance in several fields of application such as text analysis and image classification. The ability to extract information from large amounts of data is one of the key reasons to adopt deep learning techniques in sleep-stage classification. Another advantage of deep learning is its ability to deal with very large datasets with high performance. Deep learning can learn features directly from the raw input data with no or little prior knowledge. In sleep-stage classification, the number of epochs in a single dataset is huge. For this reason, we adapted a deep learning algorithm to handle PSG signals. The deep learning model used in our study is a CNN suitable for classifying large images. The CNN is usually composed of several convolutional layers, followed by several fully connected layers and a Softmax regression layer that outputs class probabilities. The CNN is a normalized multi-layer perceptron composed of a part that effectively extracts features contained in an image and a part that classifies images from features. The convolutional layer filters the image with a two-dimensional array value according to the image to be trained and extracts features. The following layers include more convolutions that can describe higher-order features. The MaxPool layer reduces the size of the feature map by converting the local features of the image into one representative scalar value and extracting the features of the image. The MaxPool layers are used to reduce computational cost and to regularize. The dropout reduces the learning time by preventing the creation of excessive nodes and layers. The flatten layer transforms the output value into one dimension to determine the result value. The network description of the CNN used in this study can be found in Table 1. The input to the CNN consists of the EEG and EOG images of the time domain and the frequency domain for each epoch. The output of the last fully connected layer is fed to a four-way Softmax which produces a probability over the four class labels. The CNN has convolutional layers of 3 \(\times\) 3 filter and a MaxPool layer of a 2 \(\times\) 2 filter. The convolutional and MaxPool layers are consistently arranged throughout the network architecture. As the activation function to each layer, Rectified Linear Units (ReLU) are applied to prevent negative values from passing through to the next layer. The batch normalization is followed by a dropout with a ratio of 0.25 or 0.5. The first convolutional layer filters the 216 \(\times\) 144 input image with 32 kernels. The second convolutional layer takes as input the output of the first convolutional layer and filters the 108 \(\times\) 72 input with 64 kernels. The second convolutional layer connects to the flatten layer. The flatten layer converts the 54 \(\times\) 36 output of the convolutional layer into a one-dimensional vector of size 124,416. The two-unit-dense layer at the end of the layers \begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Layer** & **Filter** & **Kernel** & **Output** & **Dropout** & **Activation** \\ \hline Input & & & (216,144) & & \\ Conv2D & 32 & (3,3) & & 0.25 & ReLU \\ MaxPool & & (2,2) & (108,72) & & \\ Conv2D & 64 & (3,3) & & & \\ MaxPool & & (2,2) & (54,36) & & \\ Flatten & & & (124,416) & & \\ Dense & & & (256) & 0.5 & ReLU \\ Dense & & & (4) & & Softmax \\ \hline \hline \end{tabular}
\end{table} 
Table 1: CNN architecture for sleep-stage classification. predicts four classes from the dataset. The first dense layer converts the 124,416 input to 256 vectors, and the second dense layer converts it to four values. The Softmax activation function in the dense layer will output a value between 0 and 1 according to the confidence of the class to which the images belong.