Lightweight two-layer nested sleep staging method based on deep learning, Wearable device
By employing a lightweight two-layer nested sleep staging method on wearable devices, and using two identical 3-class neural network models for sleep staging, the problem of excessive resource consumption in existing technologies is solved, achieving efficient and flexible sleep staging and low-power sleep monitoring.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING SONGGUO BRAIN MACHINE TECHNOLOGY CO LTD
- Filing Date
- 2025-02-12
- Publication Date
- 2026-05-15
AI Technical Summary
Existing deep learning sleep staging algorithms are inefficient on resource-constrained wearable devices, making it difficult to meet the needs of coarse classification, and existing methods consume too much hardware resources.
A lightweight, two-layer nested sleep staging method based on deep learning is adopted. It uses two identical 3-class neural network models for staging. First, a coarse classification is performed, and then a fine classification is performed according to the needs, thereby reducing hardware overhead and power consumption.
It enables efficient and flexible sleep staging on wearable devices, reduces computational load and power consumption, adapts to actual needs, and maintains high classification performance.
Smart Images

Figure CN120093216B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sleep monitoring technology based on electroencephalogram (EEG) signals, specifically relating to a lightweight two-layer nested sleep staging method and wearable device based on deep learning. Background Technology
[0002] Sleep is crucial for health, an essential physiological process, and a vital component of the body's recovery and memory consolidation. Insufficient or irregular sleep can lead to various physiological and psychological problems and illnesses, such as weakened immunity, memory decline, depression, anxiety, and mood instability. A survey released by the World Health Organization shows that 27% of the global population has sleep problems, and sleep quality assessment is an important early risk indicator that can effectively reduce the incidence of various diseases.
[0003] Sleep staging is an important method for assessing sleep quality. During sleep, brain activity undergoes a series of cyclical changes. The latest sleep staging standards—the American Academy of Sleep Medicine (AASM) standards—divide adult sleep into five consecutive stages: wake (W), non-rapid eye movement (NREM), and rapid eye movement (REM). The NREM stage is further divided into N1 (N1), N2 (N2), and N3 (N3). When people have sleep disorders or related illnesses, their normal rhythm is disrupted, manifesting as changes in the proportions of different stages in the sleep cycle, or difficulty entering a particular stage of sleep. Therefore, sleep staging can effectively support the assessment of sleep quality, thus providing a standard diagnostic method for sleep problems. Sleep staging is achieved by analyzing recorded polysomnography (PSG). PSG contains different types of physiological signals, such as electroencephalogram (EEG), electrooculogram (EOG), electrocardiogram (ECG), electromyogram (EMG), nasal and oral airflow, and oxygen saturation. Sleep experts comprehensively analyze the physiological signals from each channel in the PSG and define the various stages of sleep according to sleep staging standards.
[0004] Manually labeling sleep stages is time-consuming, labor-intensive, inefficient, and the results are susceptible to the subjective influence of experts. To address these issues, many early studies used machine learning (ML) methods for sleep staging. This involved extracting various handcrafted features from the sleep signal generator (PSG) and then classifying the sleep using ML algorithms. However, the effectiveness of this method heavily relied on the selected handcrafted features. With the development of deep learning (DL), many studies have focused on sleep staging using DL algorithms. Compared to ML, DL does not rely on handcrafted feature extraction; the model automatically learns the features of the original signal during training, completing the end-to-end classification task and exhibiting superior performance. For example, Y. Dai et al. proposed a Transformer-based MultiChannelSleepNet model that uses EEG and EOG channels for sleep staging. This model uses a Transformer encoder for single-channel feature extraction and multi-channel feature fusion. This method achieved an accuracy of 87.2% and a macro F1 score of 81.2 on the Sleep-EDF-20 dataset. Y. Lin et al. proposed a deep network based on multi-view fusion. The architecture includes a multi-scale local feature extractor (MSLFE) and a generalized relation modeling (GRM) module. The method achieves a classification accuracy of over 84% on the Sleep-EDF dataset. The best-performing model has 1.485M parameters and a computational cost of 69.76MFLOPs.
[0005] However, existing technologies all use a single deep network to directly perform 5-category sleep staging, while practical applications often require coarse classification, that is, merging N1, N2, and N3 into the NREM stage. Although existing methods can meet this requirement, they consume more hardware resources in coarse classification scenarios, posing a significant challenge for resource-constrained wearable or embedded devices. These sleep staging algorithms implemented through deep learning cannot run efficiently on low-power, low-memory devices, which limits their application in real-world scenarios. Summary of the Invention
[0006] To address the aforementioned problems in existing technologies, this invention provides a lightweight two-layer nested sleep staging method based on deep learning. The technical problem to be solved by this invention is achieved through the following technical solution:
[0007] In a first aspect, embodiments of the present invention provide a lightweight two-layer nested sleep staging method based on deep learning, comprising:
[0008] Acquire the PSG signal to be tested, including electroencephalogram (EEG) signals and electrooculogram (EOG) signals, preprocess the PSG signal to be tested, and filter the EEG signals in the preprocessed PSG signal to be tested.
[0009] The filtered PSG signal to be tested is input into the trained first-stage neural network model to obtain the first predicted sleep period; the first predicted sleep period includes at least one of the W stage, NREM stage, and REM stage.
[0010] If an NREM stage exists in the first predicted sleep period, the filtered PSG signal to be tested corresponding to the NREM stage is input into the trained second-stage neural network model to obtain the second predicted sleep period; the second predicted sleep period includes at least one of N1 stage, N2 stage, and N3 stage; the network structure of the second-stage neural network model is the same as that of the first-stage neural network model.
[0011] In one embodiment of the present invention, the preprocessing of the PSG signal to be tested includes:
[0012] The PSG signal to be tested is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage within a preset time threshold.
[0013] In one embodiment of the present invention, both the first-stage neural network model and the second-stage neural network model include three CNN modules, one BiGRU module, and one fully connected layer connected in sequence.
[0014] In one embodiment of the present invention, the three CNN modules have the same network structure; each CNN module includes a convolutional layer, a normalization layer, an activation layer and a pooling layer connected in sequence.
[0015] In one embodiment of the present invention, the size of the convolution kernels of the convolutional layers in the three CNN modules increases sequentially.
[0016] In one embodiment of the present invention, the BiGRU module includes a BiGRU layer and a normalization layer connected in sequence.
[0017] In one embodiment of the invention, a dropout layer is further included between the last CNN module and the BiGRU module.
[0018] In one embodiment of the present invention, the process of training the first-stage neural network model and the second-stage neural network model includes:
[0019] Training PSG signals and verification PSG signals, including electroencephalogram (EEG) signals and electrooculogram (EOG) signals, are acquired. The training PSG signals and verification PSG signals are preprocessed respectively, and the EEG signals in the preprocessed training PSG signals and verification PSG signals are filtered respectively. The filtered training PSG signals and verification PSG signals include PSG signals of W phase, N1 phase, N2 phase, N3 phase and REM phase respectively.
[0020] The filtered training PSG signal and the PSG signal of the verification PSG signal in stages N1, N2 and N3 are merged to form the PSG signal of the corresponding NREM stage.
[0021] The PSG signals of the W stage, NREM stage and REM stage in the filtered training PSG signal are input into the initial first-stage neural network model for training, and the PSG signals of the W stage, NREM stage and REM stage in the filtered verification PSG signal are used to verify the trained first-stage neural network model, thus obtaining the trained first-stage neural network model.
[0022] The PSG signal of the NREM stage in the filtered training PSG signal is input into the initial second-stage neural network model for training, and the PSG signal of the NREM stage in the filtered verification PSG signal is used to verify the trained second-stage neural network model, thus obtaining the trained second-stage neural network model.
[0023] In one embodiment of the present invention, preprocessing is performed on the training PSG signal and the verification PSG signal, respectively, including:
[0024] The training PSG signal is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage at the preset time threshold.
[0025] The verification PSG signal is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage within a preset time threshold.
[0026] Secondly, embodiments of the present invention provide a wearable device that integrates a first-stage neural network model and a second-stage neural network model, and executes the lightweight two-layer nested sleep staging method based on deep learning as described in any one of the first aspects according to user needs; wherein,
[0027] If the user requires the output of three-stage sleep periods, the first predicted sleep period is displayed on the display interface of the wearable device, and the first predicted sleep period is stored on the wearable device.
[0028] If the user requires the output of five-stage sleep periods, the first predicted sleep period and the second predicted sleep period will be displayed on the display interface of the wearable device.
[0029] The beneficial effects of this invention are:
[0030] The proposed lightweight, two-layer nested sleep staging method based on deep learning offers advantages such as greater suitability for deployment on edge hardware devices like wearables and better adaptation to practical needs. Specifically, it transforms an existing single-stage 5-class classification task into a two-stage 3-class classification task. Compared to using a 5-class neural network model, the proposed method uses 3-class models for both stages. In terms of model complexity and parameter count, the overhead of the 3-class model is significantly lower than that of the 5-class model. This is crucial for applications on edge hardware devices like wearables, as these devices typically have limited computing power and storage space. Even though the proposed method requires two 3-class models, their scale is much smaller than a single 5-class model. Furthermore, the two 3-class models share the same network structure, allowing for hardware reuse across both stages, further reducing hardware overhead. The proposed method achieves classification performance comparable to existing 5-class models while being much smaller in scale, realizing a lightweight sleep staging algorithm that is more suitable for deployment on edge hardware devices like wearables. Furthermore, in practical applications of sleep staging algorithms, sometimes fine classification is not required, and only a rough classification of the three stages W, NREM, and REM is needed. In this case, when deploying the method proposed in this invention in hardware, the output of the first-stage neural network model can be directly used as the final result without starting the second-stage neural network model. This further reduces the amount of computation, thereby reducing power consumption and computational latency, making it more suitable for sleep monitoring devices that require real-time processing and feedback. The method proposed in this invention can adjust whether to start the second-stage neural network model according to actual needs, making the application more flexible.
[0031] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0032] Figure 1 This is a flowchart illustrating a lightweight two-layer nested sleep staging method based on deep learning provided in an embodiment of the present invention.
[0033] Figure 2 This is a schematic diagram illustrating the framework implementation of the lightweight two-layer nested sleep staging method based on deep learning provided in an embodiment of the present invention.
[0034] Figure 3 This is a schematic diagram of the structure of the first-stage neural network model provided in an embodiment of the present invention;
[0035] Figure 4 This is a schematic diagram of the structure of the CNN module in the first-stage neural network model provided in this embodiment of the invention;
[0036] Figure 5 This is a schematic diagram of the structure of the BiGRU module in the first-stage neural network model provided in this embodiment of the invention;
[0037] Figure 6 This is a schematic diagram illustrating the implementation of the BiGRU layer in the BiGRU module provided in this embodiment of the invention;
[0038] Figure 7 This is a schematic diagram illustrating the implementation of GRU units in the BiGRU layer provided in an embodiment of the present invention. Detailed Implementation
[0039] The present invention will be further described in detail below with reference to specific embodiments, but the implementation of the present invention is not limited thereto.
[0040] Firstly, please see Figure 1 This invention provides a lightweight two-layer nested sleep staging method based on deep learning, specifically including the following steps:
[0041] S10. Acquire the PSG signal to be tested, including EEG signal and EEG signal, preprocess the PSG signal to be tested, and filter the EEG signal in the preprocessed PSG signal to be tested.
[0042] This invention uses the AASM (American Academy of Sleep Medicine) standard for sleep staging. Sleep staging typically uses information from one or more channels of the PSG (multiple channels refer to physiological signals from different sources) to determine the current sleep stage. Given the availability of numerous open-source sleep datasets, this invention uses these datasets for algorithm testing and verification during the design phase. Since the original open-source datasets contain too many PSG signals from the waking state, the PSG signals to be tested need to be pruned after obtaining them from the original open-source datasets. This pruned segments retain the waking segments before entering the non-waking stage (within a preset time threshold) and the waking segments after exiting sleep and entering the waking stage (within a preset time threshold). More specifically:
[0043] The open-source dataset was cropped to retain only the 30-second (preset time threshold of 30 seconds) wakefulness segment before entering the non-wake stage (where "entering the non-wake stage" refers to the moment of first entering the N1 stage from the W stage) and the 30-second wakefulness segment after exiting the sleep state and entering the wakefulness stage (where "exiting the sleep state" refers to the moment of entering the W stage from the last sleep stage REM).
[0044] Furthermore, embodiments of the present invention require filtering of the EEG signals in the PSG signal to be tested. This is because: according to existing research, the EEG waves mainly used for sleep staging include delta waves, theta waves, alpha waves, beta waves, and sleep spindle waves, with a frequency range mainly covering below 35Hz. This frequency range contains the vast majority of useful information, and since there is a large amount of ultra-low frequency noise below 0.5Hz, bandpass filtering of 0.5Hz to 35Hz is performed on the PSG signal to be tested to remove useless high-frequency components and ultra-low frequency noise, thereby improving classification performance.
[0045] Existing methods classify sleep into 5 categories (W, N1, N2, N3, REM) based on the AASM standard. However, in practical applications, N1, N2, and N3 are often merged into a single label, NREM, making 5-stage classification wasteful of hardware resources. In the AASM sleep staging standard, N1, N2, and N3 stages all belong to the NREM stage and share similar characteristics. Therefore, a neural network model can be used for the first stage of coarse classification of the input raw PSG signal, dividing it into three stages: W, NREM, and REM. If the output is W or REM, the classification task is complete. If the output is NREM, a second stage of fine classification is needed for the raw PSG signal corresponding to the NREM stage. The input to the second-stage neural network model is the raw PSG signal identified as belonging to the NREM stage in the first-stage model. Thus, the function of the second-stage neural network model is to further classify the input PSG signal corresponding to the NREM stage into N1, N2, and N3 stages. Ultimately, through the first stage of coarse classification and the second stage of fine classification, five stages of classification—W, N1, N2, N3, and REM—can be achieved.
[0046] As can be seen, this invention addresses the practical application needs of sleep staging, such as... Figure 2The diagram illustrates how a 5-class classification task can be transformed into two 3-class classification tasks. Two identical network models—a first-stage neural network model and a second-stage neural network model—are used to implement the two classification stages respectively. In terms of hardware implementation, the two stages reuse the same network structure, reducing hardware overhead. Furthermore, the second-stage model can be activated or deactivated according to actual needs, making the application more flexible while also reducing power consumption. The specific implementation includes the following steps S20 and S30:
[0047] S20. Input the filtered PSG signal to be tested into the trained first-stage neural network model to obtain the first predicted sleep period; the first predicted sleep period includes at least one of the W stage, NREM stage, and REM stage.
[0048] Typically, network models use a combination of data from several channels of the PSG signal as input. During model testing, the inventors discovered that lightweight network models exhibited poor classification performance when using only EEG signals, but their performance improved significantly after incorporating EEG signals. Therefore, this invention uses a combination of EEG and EEG signals for classification tasks. Existing sleep staging research typically employs two types of input: directly using the raw PSG signal as network model input, or using a time-frequency plot of the PSG signal as model input. While some studies have shown that time-frequency plots provide more information, their limited resolution does not significantly improve model classification performance. Furthermore, obtaining a time-frequency plot requires transformation calculations on the raw PSG signal, increasing computational complexity and resource pressure on edge devices. Therefore, this invention uses the raw PSG signal as model input.
[0049] Furthermore, in this embodiment of the invention, the first-stage neural network model is a 3-classification model. The input PSG signal is the PSG signal to be tested after preprocessing and filtering in S10. By inputting the PSG signal to be tested into the trained first-stage neural network model, the first predicted sleep period can be obtained. The first predicted sleep period includes at least one of the W stage, NREM stage, and REM stage.
[0050] This invention provides a network structure for a first-stage neural network model, as shown in the embodiment of the invention. Figure 3As shown, the first-stage neural network model comprises three sequentially connected CNN (Convolutional Neural Network) modules, one BiGRU (Bidirectional Gate Recurrent Unit) module, and one fully connected layer. The CNN is primarily used to extract spatial features of the PSG signal, while the BiGRU is mainly used to capture the temporal dependencies of the PSG signal. The fully connected layer maps the output of the last time step of the BiGRU to the three classification results. More specifically:
[0051] In this embodiment of the invention, the three CNN modules have the same network structure; each CNN module is as follows: Figure 4 As shown, it includes a convolutional layer (CNN), a normalization layer (BN), an activation layer (ReLU), and a pooling layer (POOL) connected in sequence. The CNN module receives multi-channel PSG signals. The convolutional layers in the three CNN modules use convolutional kernels of progressively increasing size. They are connected in series to progressively extract abstract features from each channel. For example, after three CNN modules, the number of output channels are 8, 16, and 32, respectively. Specifically:
[0052] Convolutional layers (CNNs) implement basic convolution operations to extract spatial features from the input PSG signal. The calculation formula is as follows:
[0053]
[0054] Formula (1) describes the computation process of mapping elements in an input sample to the output through a one-dimensional convolutional layer, C in K represents the total number of input channels of the input feature map of the convolutional layer CNN, and K represents the size of the convolutional kernel. in (n·S+kP) represents the c-th feature in the input feature map of the convolutional layer CNN. in The element value at the (n·S+kP)th position of the input channel, where n represents the c-th element in the output feature map of the convolutional layer CNN. out The nth data position of each output channel, S represents the stride of the convolutional layer (CNN), k represents the position of the convolutional kernel, P represents the padding size, and W(c out ,c in ,k) represents the c-th out In the convolution kernel of the nth output channel, the cth... in The weight value of the k-th position of each input channel, b(c out ) represents the cth out The bias value of each output channel, c out The value ranges from 1 to C. out C outThe output channel of the feature map of the convolutional layer CNN is represented by out(c out (n) represents the c-th element in the output feature map. out The output value of the nth data position of each output channel.
[0055] Normalized batch normalization (BN) layers apply normalization to each mini-batch of data in each layer, keeping the data distribution relatively stable during training and thus mitigating the vanishing and exploding gradient problems. The introduction of BN layers makes network training more efficient, improving training effectiveness and generalization ability. The normalized batch normalization formula is:
[0056]
[0057]
[0058]
[0059] Where, x i Let m represent the i-th sample in the mini-batch, and m represent the total number of data points in the mini-batch. x represents i The standardized result, μ B and These are the mean and variance of the small batch of data, respectively. The calculation formulas are shown in equations (3) and (4). ε is a very small positive number used to prevent division by zero errors. γ and β are learnable parameters used to restore the expressive power of the data.
[0060] The ReLU activation layer, placed after the Batch Normalization (BN) layer, enables the network to express and learn more complex nonlinear relationships. The introduction of ReLU also controls the output range of the network layers, making the training of deep networks more stable. Its expression is:
[0061] ReLU(x) = max(x,0) (5);
[0062] Here, x represents the input feature map of the ReLU activation layer, and max is the maximum value operation. The ReLU function essentially retains the positive values of the input feature map while equalizing all negative values to 0. It introduces non-linearity and solves the gradient vanishing problem. Moreover, its expression is very concise and easy to implement through circuits.
[0063] The pooling layer POOL preferentially selects the max pooling layer. The max pooling layer performs downsampling, reducing the spatial size of the feature map, significantly reducing the computational cost of subsequent network layers, improving the training and inference speed of the network model, and reducing the amount of data can alleviate overfitting to some extent. The calculation process is as follows:
[0064] out1(c,n1)=max[in(c,n1·S1+k1)],k1=0,1,...,K1-1 (6);
[0065] Wherein, in(c,n1·S1+k1) represents the element value at position n1·S1+k1 of the c-th channel in the pooling layer's input feature map, S1 represents the stride of the pooling layer, n1 represents the n1-th data position of the c-th channel in the pooling layer's output feature map, k1 represents the data position in the pooling layer window, K1 represents the size of the pooling layer window, and out1(c,n1) represents the output value at position n1 of the c-th channel in the pooling layer's output feature map.
[0066] Furthermore, in this embodiment of the invention, the BiGRU module includes a BiGRU layer and a normalization layer connected in sequence. The BiGRU module captures the temporal dependencies of the feature maps output by the CNN module from both positive and negative directions. The BiGRU module is as follows... Figure 5 The diagram shows a structure consisting of a BiGRU layer and a BN layer. The BiGRU layer comprises two GRU units, and its implementation is as follows: Figure 6 As shown, the implementation of a single GRU unit is as follows: Figure 7 As shown, the calculation formula is as follows:
[0067] z t =σ(W z ·[h t-1 ,x t ]+b z (7);
[0068] r t =σ(W r ·[h t-1 ,x t ]+b r (8);
[0069]
[0070] Among them, z t This represents the output of the gate at time step t, r. t Let σ represent the output of the reset gate at time step t, σ represent the Sigmoid activation function, tanh represent the Tanh activation function, and h represent the output of the reset gate at time step t. t-1 h represents the hidden layer state output at time step t-1. t x represents the hidden layer state output at time step t. t This represents the input feature map at time t. W represents the candidate hidden layer state output at time step t. z W r Wh Let b represent the weight matrices of each gate. z b r b h The symbols represent the biases of each gate, and ⊙ represents the Hadamard product, which is the element-wise multiplication of vectors. Compared to GRU, BiGRU can capture the temporal dependencies of the input feature map from both positive and negative directions, and can more comprehensively capture the feature information of each channel in PSG, thereby improving the accuracy of sleep staging. For example, the hidden layer size of a BiGRU layer is 32, and the number of output channels is 64.
[0071] Furthermore, in this embodiment of the invention, the fully connected layer maps the output of the last time step of the BiGRU module to the three classification results. The calculation formula for the fully connected layer is as follows:
[0072] out = W·in + b (11);
[0073] Where W represents the weight matrix of the fully connected layer, which is obtained during the training phase, in represents the input feature vector of the fully connected layer, b represents the bias vector of the fully connected layer, and out represents the output vector of the fully connected layer.
[0074] Furthermore, in this embodiment of the invention, a dropout layer is also included between the last CNN module and the BiGRU module. The dropout layer can prevent overfitting and improve the model's generalization ability. For example, the parameter of the dropout layer can be set to 0.5.
[0075] S30. If an NREM stage exists in the first predicted sleep period, the filtered PSG signal to be tested corresponding to the NREM stage is input into the trained second-stage neural network model to obtain the second predicted sleep period. The second predicted sleep period includes at least one of N1, N2, and N3 stages. The second-stage neural network model has the same network structure as the first-stage neural network model, except that the network parameters are different. The input of the second-stage neural network model is the filtered PSG signal to be tested corresponding to the NREM stage, and the output is the second predicted sleep period including at least one of N1, N2, and N3 stages. For details, please refer to S20, which will not be repeated here.
[0076] Furthermore, the process of training the first-stage neural network model and the second-stage neural network model in this embodiment of the invention includes:
[0077] Training and validation PSG signals, including EEG and EEG signals, were acquired. Both training and validation PSG signals were preprocessed, and the EEG signals within the preprocessed training and validation PSG signals were then filtered. The filtered training and validation PSG signals included PSG signals from the W, N1, N2, N3, and REM stages, respectively. The N1, N2, and N3 stage PSG signals from the filtered training and validation PSG signals were then merged to obtain the corresponding NREM stage PSG signals. The filtered training PSG signals... The PSG signals of the W, NREM, and REM stages are input into the initial first-stage neural network model for training. The trained first-stage neural network model is then validated using the PSG signals of the W, NREM, and REM stages in the filtered validation PSG signal, resulting in a well-trained first-stage neural network model. The PSG signal of the NREM stage in the filtered training PSG signal is then input into the initial second-stage neural network model for training. The trained second-stage neural network model is then validated using the PSG signal of the NREM stage in the filtered validation PSG signal, resulting in a well-trained second-stage neural network model.
[0078] This invention applies preprocessing and filtering to training and verification PSG signals similar to that used for the PSG signals under test. For example, preprocessing of the training and verification PSG signals includes: cropping the training PSG signal to retain the awake segment before entering the non-awake phase (a preset time threshold) and the awake segment after exiting sleep and entering the awake phase (a preset time threshold); cropping the verification PSG signal to retain the awake segment before entering the non-awake phase and the awake segment after exiting sleep and entering the awake phase (a preset time threshold). Bandpass filtering of 0.5Hz to 35Hz is applied to the EEG signals in both the training and verification PSG signals to remove useless high-frequency components and ultra-low-frequency noise.
[0079] This invention validates the proposed method using the PyTorch platform. The training processes for the first and second stage neural network models are the same, differing only in the input data. The first stage model receives PSG signals from three stages: W, NREM, and REM, while the second stage model receives PSG signals from the NREM stage. The cross-entropy loss function is used during training. In PyTorch, the cross-entropy loss function already includes a Softmax activation layer, eliminating the need to add a Softmax layer at the end of the network model architecture. The optimizer used is AdamW, which includes L2 regularization and has higher computational efficiency compared to Adam. The initial learning rate during training is set to 0.0008, and the training process is monitored. When network performance stagnates, the learning rate is proactively reduced to further improve performance. To prevent overfitting during training, an early stopping method is used to monitor the training process. The total number of training cycles is set to 100. After each training cycle, the model is evaluated on the validation set. Training is stopped when the loss on the validation set no longer improves within 10 cycles. The network model that performs best on the validation set before training stops is recorded as the first-stage neural network model and the second-stage neural network model.
[0080] To verify the effectiveness of the lightweight two-layer nested sleep staging method based on deep learning provided in this embodiment of the invention, the following experiments were conducted.
[0081] This invention validates the proposed method on the publicly available datasets SleepEDF-20 and SleepEDF-78. The SleepEDF dataset was obtained from a study on the effects of age on sleep in healthy Caucasians from 1987 to 1991. SleepEDF-20 included 20 participants aged 25-34 years. PSG (Physical Sleep Gauge) was recorded twice, approximately 20 hours each time, at the participants' homes over two 24-hour periods. Data from the second night for participant 13 was lost due to cassette tape or laser disk malfunction; a total of 39 PSG files were recorded. SleepEDF-78 included 78 participants aged 25-101 years. Data from the first night for participants 36 and 52, and the second night for participant 13, was lost due to cassette tape or laser disk malfunction; a total of 153 PSG files were recorded. Both EEG and EOG signals were sampled at 100 Hz.
[0082] According to the AASM standard, the N4 stages in the SleepEDF dataset were merged into the N3 stages, and motion and unknown segments were removed. The remaining data will be used for model evaluation. The SleepEDF dataset uses 30-second intervals to label the PSG (Physical Sequence of Organisms) for sleep stages. Due to the large amount of data on awake states in the SleepEDF dataset, only the first 30 seconds before entering a non-awake state and the first 30 seconds of awake state after waking up are retained in each PSG file. Table 1 shows the distribution of each label in the processed SleepEDF-20 and SleepEDF-78 datasets.
[0083] The two-stage progressive sleep staging method proposed in this invention requires special processing of the dataset when training the two-stage neural network models separately. The dataset used for training and validating the first-stage neural network model needs to have stages N1, N2, and N3 merged into the NREM stage. The dataset used for training and validating the second-stage neural network model needs to have stages W and REM removed. Finally, when using the trained two-stage network models for full-stage 5-class classification validation, all data and labels are retained.
[0084] To facilitate comparison with experimental results from other studies, the proposed two-stage progressive sleep staging method is first divided into 20 subsets. One subset is designated as the validation set each time, and the remaining 19 subsets are used as the training set for 3-class classification training of the first-stage and second-stage neural network models, respectively. Then, the validation set is used to perform overall 5-class classification validation on both trained models, thus obtaining the experimental results. This process is repeated 20 times, each time using a different subset as the validation set. Finally, the average of the 20 experimental results is used to obtain the 20-fold cross-validation result.
[0085] During training, the two-stage network models were trained separately and tested on a 3-class classification scale for each stage. Finally, the two trained network models were used simultaneously to complete a 5-class classification test. Table 2 shows the results of the individual tests on the two-stage network models, and Table 3 shows the results of the 5-class classification test using the trained two-stage models.
[0086] For evaluating the overall performance of a model, three metrics are commonly used: accuracy, macro F1 score, and Kappa coefficient. These metrics are defined as follows:
[0087]
[0088] Where Acc. represents accuracy, C represents the total number of label categories, and TP j Let N represent the true number of instances of the j-th label, and N represent the total number of samples.
[0089]
[0090] Where MF1. represents the macro F1 score, F1 j Let represent the F1 score of the j-th label.
[0091]
[0092] Where k' represents the Kappa coefficient, p o p represents the consistency between the model's predictions and actual observations. e This indicates the consistency between classifier predictions and actual observations due to random chance.
[0093] Regarding the single-stage 3-class classification task, as shown in Table 2, the accuracy of the first-stage neural network model on both datasets reached over 90%, the macro F1 score reached over 87, and the Kappa coefficient reached over 87; the accuracy of the second-stage neural network model on both datasets reached over 84%, the macro F1 score reached over 80, and the Kappa coefficient reached over 78.
[0094] When using a two-stage network model for 5-class classification, Table 3 shows that the accuracy reached 90.81% on the SleepEDF-20 dataset, the macro F1 score reached 87.44, and the Kappa coefficient reached 87.54; on the SleepEDF-78 dataset, the accuracy reached 84.35%, the macro F1 score reached 80.01, and the Kappa coefficient reached 78.71.
[0095] The experimental results show that the sleep staging algorithm designed in this invention has only 0.016M parameters and only 2.03MOPs of computation in a single stage model, while maintaining high classification performance. It is very suitable for deployment on wearable devices with limited resources, such as wearable devices.
[0096] Table 1. Distribution of the SleepEDF dataset
[0097]
[0098] Table 2. Results of the two-stage model test
[0099]
[0100] Table 3. Model test results at all stages
[0101]
[0102] In summary, the lightweight two-layer nested sleep staging method based on deep learning proposed in this invention has the advantages of being more suitable for deployment on edge hardware devices such as wearables and better adapting to actual needs. Specifically, it transforms an existing single-stage 5-class classification task into a two-stage 3-class classification task. Compared to using a 5-class neural network model, the neural network models in both stages of the proposed method are 3-class models. In terms of model complexity and parameter count, the overhead of the 3-class model is much lower than that of the 5-class model. This is very important for applications on edge hardware devices such as wearables, because edge devices typically have lower computing power and smaller storage space. Even though the proposed method requires two 3-class models, their scale is much smaller than that of a single 5-class model. Moreover, the network structures of the two 3-class models are identical, allowing the two stages to reuse the same network structure in hardware implementation, further reducing hardware overhead. The proposed method can achieve classification performance comparable to existing 5-class models, while being much smaller in scale, realizing a lightweight sleep staging algorithm that is more suitable for deployment on edge hardware devices such as wearables. Furthermore, in practical applications of sleep staging algorithms, sometimes fine classification is not required, and only a rough classification of the three stages W, NREM, and REM is needed. In this case, when deploying the method proposed in this invention in hardware, the output of the first-stage neural network model can be directly used as the final result without starting the second-stage neural network model. This further reduces the amount of computation, thereby reducing power consumption and computational latency, making it more suitable for sleep monitoring devices that require real-time processing and feedback. The method proposed in this invention can adjust whether to start the second-stage neural network model according to actual needs, making the application more flexible.
[0103] Secondly, embodiments of the present invention provide a wearable device that integrates a first-stage neural network model and a second-stage neural network model, and executes any one of the lightweight two-layer nested sleep staging methods based on deep learning according to user needs; wherein,
[0104] If the user requires the output of three-stage sleep periods, the first predicted sleep period will be displayed on the display interface of the wearable device and stored on the wearable device.
[0105] If the user requires the output of five stages of sleep, then the first and second predicted sleep stages will be displayed on the wearable device's display interface.
[0106] As for the wearable device embodiment of the second aspect, since it is basically similar to the method embodiment of the first aspect, the description is relatively simple, and relevant details can be found in the description of the method embodiment of the first aspect.
[0107] In the description of this invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0108] Although the invention has been described herein in conjunction with various embodiments, those skilled in the art, by reviewing the specification and accompanying drawings, will understand and implement other variations of the disclosed embodiments in carrying out the claimed invention. In the specification, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude a plurality. While certain measures are described in different embodiments, this does not mean that these measures cannot be combined to produce good results.
[0109] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. A lightweight two-layer nested sleep staging method based on deep learning, characterized in that, When applied to wearable devices, the method includes: Acquire the PSG signal to be tested, including electroencephalogram (EEG) signals and electrooculogram (EOG) signals, preprocess the PSG signal to be tested, and filter the EEG signals in the preprocessed PSG signal to be tested. The filtered PSG signal to be tested is input into the trained first-stage neural network model to obtain the first predicted sleep period; the first predicted sleep period includes at least one of the W stage, NREM stage, and REM stage. If an NREM stage exists in the first predicted sleep period, the filtered PSG signal to be tested corresponding to the NREM stage is input into the trained second-stage neural network model to obtain the second predicted sleep period; the second predicted sleep period includes at least one of N1 stage, N2 stage, and N3 stage; both the second-stage neural network model and the first-stage neural network model include three CNN modules, one BiGRU module, and one fully connected layer connected in sequence, and the size of the convolutional kernels of the convolutional layers in the three CNN modules increases sequentially; If the user requires a three-stage sleep period, the first predicted sleep period is displayed on the display interface of the wearable device and stored on the wearable device; if the user requires a five-stage sleep period, the first predicted sleep period and the second predicted sleep period are displayed on the display interface of the wearable device.
2. The lightweight two-layer nested sleep staging method based on deep learning according to claim 1, characterized in that, The preprocessing of the PSG signal to be tested includes: The PSG signal to be tested is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage within a preset time threshold.
3. The lightweight two-layer nested sleep staging method based on deep learning according to claim 1, characterized in that, The three CNN modules have the same network structure; each CNN module includes a convolutional layer, a normalization layer, an activation layer, and a pooling layer connected in sequence.
4. The lightweight two-layer nested sleep staging method based on deep learning according to claim 1, characterized in that, The BiGRU module includes a BiGRU layer and a normalization layer connected in sequence.
5. The lightweight two-layer nested sleep staging method based on deep learning according to claim 1, characterized in that, Between the last CNN module and the BiGRU module, there is also a dropout layer.
6. The lightweight two-layer nested sleep staging method based on deep learning according to claim 1, characterized in that, The process of training the first-stage neural network model and the second-stage neural network model includes: Training PSG signals and verification PSG signals, including electroencephalogram (EEG) signals and electrooculogram (EOG) signals, are acquired. The training PSG signals and verification PSG signals are preprocessed respectively, and the EEG signals in the preprocessed training PSG signals and verification PSG signals are filtered respectively. The filtered training PSG signals and verification PSG signals include PSG signals of W phase, N1 phase, N2 phase, N3 phase and REM phase respectively. The filtered training PSG signal and the PSG signal of the verification PSG signal in stages N1, N2 and N3 are merged to form the PSG signal of the corresponding NREM stage. The PSG signals of the W stage, NREM stage and REM stage in the filtered training PSG signal are input into the initial first-stage neural network model for training, and the PSG signals of the W stage, NREM stage and REM stage in the filtered verification PSG signal are used to verify the trained first-stage neural network model, thus obtaining the trained first-stage neural network model. The PSG signal of the NREM stage in the filtered training PSG signal is input into the initial second-stage neural network model for training, and the PSG signal of the NREM stage in the filtered verification PSG signal is used to verify the trained second-stage neural network model, thus obtaining the trained second-stage neural network model.
7. The lightweight two-layer nested sleep staging method based on deep learning according to claim 6, characterized in that, Preprocessing is performed on the training PSG signal and the verification PSG signal respectively, including: The training PSG signal is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage at the preset time threshold. The verification PSG signal is cropped to retain the awake segment before entering the non-awake stage and the awake segment after exiting the sleep state and entering the awake stage within a preset time threshold.