Lightweight automatic sleep staging method capable of being used for on-chip migration

By building a lightweight deep learning model of multi-layer convolutional neural network and channel attention mechanism, the problem of high computational complexity of sleep staging model is solved, and efficient real-time sleep monitoring on embedded devices is realized, and multi-channel and multi-modal physiological signal input is supported.

CN120345857APending Publication Date: 2025-07-22FUDAN UNIVERSITY
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202510331996.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-20
Publication Date
2025-07-22

AI Technical Summary

Technical Problem

The existing sleep staging model has high computational complexity and is difficult to run in real time on embedded devices, which cannot meet the daily sleep monitoring needs.

Method used

Build a lightweight deep learning model of multi-layer convolutional neural network and channel attention mechanism, combining efficient training strategies to reduce the amount of model parameters and inference time, and is suitable for embedded devices.

Benefits of technology

It realizes efficient real-time sleep monitoring on embedded devices, maintains high classification accuracy, supports multi-channel and multi-modal physiological signal input, and is suitable for resource-constrained devices such as STM32 microcontrollers and Raspberry Pi.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120345857A_ABST
    Figure CN120345857A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of biomedical engineering, and particularly relates to a lightweight automatic sleep staging method capable of being used for on-chip migration. The method comprises the following steps: carrying out filtering and baseline correction preprocessing on an electroencephalogram signal; constructing a lightweight deep learning model composed of a multi-layer one-dimensional convolutional neural network, a channel attention module, a full connection layer and a Softmax layer; performing model training by adopting a cross entropy loss function and double optimizers, and optimizing the model in combination with a cross validation strategy; and compressing the model parameter quantity and the reasoning operation time to generate a deployable file. According to the method, the number of convolution channels is adjusted layer by layer, the dimensionality of a full connection layer is cut, the trainable parameter quantity of the model is compressed to be less than 200000, the feature selectivity is improved through the lightweight channel attention module on the premise that the calculation burden is hardly increased, the method can be deployed in embedded equipment to realize real-time sleep monitoring, and the method is suitable for popularization and application. And a solution is provided for portable medical diagnosis.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of biomedical engineering, and particularly relates to a lightweight automatic sleep staging method. Background Art

[0002] Sleep is an important physiological activity of humans. Good sleep can help the human body to self-regulate and self-repair, and plays a key role in maintaining physical and mental health. However, statistics from the World Health Organization show that approximately 27% of the global population is suffering from sleep disorders such as insomnia, sleep apnea, and restless legs syndrome. These sleep problems not only affect the quality of daily life, but are also closely related to various chronic diseases such as cardiovascular diseases, metabolic syndrome, and neurodegenerative diseases. Therefore, monitoring and improving sleep has become a focus of clinical diagnosis and treatment and scientific research.

[0003] The "Manual for the Scoring of Sleep and Associated Events" established by the American Academy of Sleep Medicine (AASM) has established the gold standard for modern sleep staging. This system divides the sleep cycle into five stages: wakefulness (Wake), non-rapid eye movement sleep N1, N2, N3, and rapid eye movement sleep (REM), each corresponding to specific physiological characteristics: the Wake stage is mainly dominated by alpha waves (8-13 Hz) and beta waves (13-30 Hz), the N1 stage is mainly dominated by theta waves (4-8 Hz), the N2 stage shows sleep spindles (12-16 Hz) and K-complex waves, the N3 stage is slow-wave sleep with a delta wave (0.5-4 Hz) proportion exceeding 20%, and the REM stage is characterized by low-amplitude mixed-frequency brain waves and rapid eye movements. Different sleep stages reflect different activity states of the brain and are closely related to functions such as physical recovery and memory consolidation.

[0004] Modern sleep monitoring relies on polysomnography (PSG) to collect multi-modal signals such as electroencephalogram (EEG), electrooculogram (EOG), and electromyogram (EMG), providing the gold standard for the diagnosis of sleep disorders. Among them, sleep staging based on PSG signals is a key link in evaluating sleep quality. However, manual annotation of sleep stages has deficiencies such as time-consuming, laborious, strong subjectivity, and poor consistency. These limitations have prompted researchers to introduce machine learning algorithms into the field of sleep research, creating a new paradigm for automatic sleep staging.

[0005] Traditional methods adopt feature engineering strategies to extract features from dimensions such as time domain, frequency domain, and nonlinear dynamics, and combine classifiers such as support vector machines (SVM) and random forests to achieve automatic sleep staging. To a certain extent, the accuracy of staging is improved, but it relies on artificial features and is difficult to comprehensively capture the complex patterns of sleep signals. Deep learning technology has made breakthroughs through end-to-end feature learning. Convolutional neural networks (CNNs) can automatically identify the spatial patterns of electroencephalogram (EEG), recurrent neural networks (RNNs) can effectively capture the temporal features of sleep stage transitions, and the attention mechanism enhances the model's ability to focus on key information. Although deep learning has made remarkable progress in the field of sleep staging, its disadvantages such as large model size, high computational requirements, and long training time have gradually emerged. Summary of the Invention

[0006] The purpose of the present invention is to provide a lightweight automatic sleep staging method that can be used for on-chip migration, aiming to solve the problems of high computational complexity of sleep staging models and difficulty in real-time operation on embedded devices in the prior art, and to provide a solution for daily sleep monitoring.

[0007] The lightweight automatic sleep staging method provided by the present invention can be used for on-chip migration. By introducing a multi-layer convolutional neural network and a channel attention mechanism to construct a lightweight deep learning model, combined with an efficient training strategy, while ensuring the accuracy, the number of model parameters and the inference time are significantly reduced, which is suitable for real-time sleep monitoring of embedded devices. The specific steps are as follows:

[0008] (1) Obtain the Sleep-EDF dataset for model training;

[0009] (2) Preprocessing of the original EEG signals; including using a Butterworth filter for band-stop filtering and low-frequency filtering to remove noise, then using the moving average method to perform baseline correction on the signals to ensure that the signal quality meets the model input requirements, and then performing segmentation processing. Each segment of data has a length of 30 seconds, and the sleep stage labels are retained to construct training samples;

[0010] (3) Construction of the sleep staging model; specifically, use the Pytorch framework to construct a sleep staging model that supports single-channel and multi-channel inputs. This model is divided into two parts: feature extraction and classification output. The feature extraction part includes 4 one-dimensional convolutional modules and 2 channel attention modules, and the classification output part includes 3 fully connected layers and a Softmax output layer;

[0011] (4) Training and optimization of the sleep staging model; specifically, input the preprocessed EEG signals into the above sleep staging model, use the cross-entropy loss function and the Adam optimizer for initial training, switch to the SGD optimizer for fine-tuning during the training process, and use cross-validation to evaluate the model performance;

[0012] (5) Prediction and deployment of the sleep staging model; for the trained model, calculate the order of magnitude of the model parameters and the single-inference operation time, and generate a deployable model file.

[0013] Furthermore:

[0014] In step (1), the Sleep-EDF dataset is a public dataset that contains polysomnogram (PSG) records from multiple healthy subjects. It is divided into a standard version (Sleep-EDF20) and an extended version (Sleep-EDF78) according to the number of subjects. It covers 2-channel EEG (FPz-Cz / Pz-Oz), 1-channel EOG, and 30s-epoch sleep stage labels annotated according to the AASM standard, and is widely used in sleep stage classification and analysis.

[0015] In step (3), for the sleep staging model, where:

[0016] The first convolutional module has an adjustable number of input channels. When the number of channels is 1, it is a single-channel input, and when the number of channels is greater than 1, it is a multi-channel input. The number of output channels is 16, the convolutional kernel size is 7, the stride is 4, the padding is 1, followed by a batch normalization layer and a ReLU activation function;

[0017] The second convolutional module has 16 input channels, 32 output channels, a convolutional kernel size of 7, a padding of 1, followed by a Dropout layer, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 9 and a stride of 4;

[0018] The third convolutional module has 32 input channels, 64 output channels, a convolutional kernel size of 5, a padding of 1, followed by a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 7 and a stride of 3;

[0019] The fourth convolutional module has 64 input and output channels, a convolutional kernel size of 3, a padding of 1, followed by a Dropout layer, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 5 and a stride of 3;

[0020] Embed a channel attention module after the second and fourth convolutional modules. Generate a channel description vector through global average pooling, compress it to 1 / 16 of the original number of channels after passing through two fully connected layers and then restore it, and use the Sigmoid function to generate channel weight coefficients to achieve adaptive calibration of feature channels;

[0021] The first fully connected layer maps the features to 128 dimensions, the second layer reduces to 64 dimensions, and the third layer outputs a 5-dimensional classification result corresponding to five sleep stages: W, N1, N2, N3, and REM [1]The probability, the first two convolutional layers are followed by a Dropout layer and a ReLU activation function, and the Softmax layer normalizes the output probability to generate the final classification result;

[0022] The above sleep staging model is designed according to the lightweight requirements, that is, the number of channels in the convolutional layer doubles layer by layer, the size of the convolutional kernel decreases layer by layer, the dimension of the fully connected layer decreases step by step, and finally the number of parameters is reduced by more than 85%, while the performance indicators remain basically unchanged; in addition, by introducing a channel attention module, the number of additional trainable parameters is less than 1000, accounting for less than 0.4%, but the achieved performance improvement exceeds 1%, achieving a good balance between model performance and scale.

[0023] Specifically, the present invention compresses the total estimated size of the model from more than 20MB to less than 2.5MB, and compresses the number of trainable parameters from more than 2,000,000 to less than 200,000.

[0024] In step (4), the model training and optimization are specifically as follows:

[0025] This task is a five-classification task, and the cross-entropy loss function is used as the loss function to measure the difference between the predicted probability distribution and the true distribution. The function is defined as:

[0026]

[0027] where N is the number of samples, y i,c is the true label of sample i, using one-hot encoding, is the predicted probability that sample i belongs to class c;

[0028] The original dataset is divided into a training set and a test set in a ratio of 7:3. The training set data is divided by 10-fold cross-validation, the batch size is 128, and the total number of training epochs is 30;

[0029] In the initial stage of training, the Adam optimizer is used. This is an optimization algorithm that dynamically adjusts the learning rate according to the parameter gradient, and uses its adaptive learning rate characteristic to quickly approach the local optimum;

[0030] After the rapid convergence in the initial stage, it enters the fine-tuning stage, switches to the SGD optimizer with momentum, and calculates the gradient by randomly selecting a small batch of data to update the model parameters;

[0031] An early stopping mechanism is added during training. When the validation set loss does not decrease for 5 consecutive epochs, the training is terminated and rolled back to the best weights;

[0032] Add a weight_decay parameter to the classifier to limit the weight size, and at the same time use a Dropout layer to prevent the model from overfitting;

[0033] The performance of the model is evaluated using metrics such as Accuracy, F1-Score, and Cohen's Kappa coefficient.

[0034] In step (5), the model deployment and prediction are as follows:

[0035] During training, the time.time() module is called for timing. On the Sleep-EDF20 dataset, the training time for a single epoch is < 2 seconds; after training is completed, a.pth model file is generated, and the size of this file is less than 1MB. It can be converted into formats such as ONNX to adapt to resource-constrained devices like STM32; during the model validation phase, an independent test set is used, which contains 5 nights of sleep data in the Sleep-EDF78 dataset that did not participate in training, and the required time is less than 30 seconds, having significant advantages for embedded applications.

[0036] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0037] The present invention constructs a lightweight sleep staging model by introducing a multi-layer convolutional neural network and a channel attention mechanism. This model significantly reduces the number of parameters and the inference time, while maintaining a high classification accuracy, enabling the model to operate efficiently on resource-constrained embedded devices. During the model training process of the present invention, a combined strategy of the Adam optimizer and the SGD optimizer is adopted, combined with cross-validation and early stopping mechanisms, further optimizing the training efficiency and generalization ability of the model. The present invention achieves a smaller model size and a shorter training time, generating a model file suitable for deployment on embedded devices, making this method highly practical and scalable in practical applications.

[0038] The method of the present invention supports the input of multi-channel and multi-modal physiological signals, and realizes multi-modal fusion by adjusting the number of input channels. The method supports the prediction of sleep stages on various resource-constrained devices, including STM32 single-chip microcontrollers, Raspberry Pi, etc. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] Figure 1 is a flowchart of the lightweight automatic sleep staging method of the present invention.

[0040] Figure 2 is a comparison diagram of EEG signals before and after preprocessing.

[0041] Figure 3 is an architecture diagram of the lightweight sleep staging model proposed by the present invention.

[0042] Figure 4 is a schematic diagram of the principle of the channel attention module.

[0043] Figure 5 This is a performance comparison chart between the method of the present invention and the existing single-channel sleep staging algorithm.

[0044] Figure 6 This is a comparison chart of the improvement in classification performance under the multi-channel input configuration.

[0045] Figure 7 This is a confusion matrix chart of five sleep stages under the multi-channel input configuration. From left to right, they are 1-channel, 2-channel, and 3-channel inputs.

[0046] Figure 8 This is a performance comparison chart of the ablation experiment of the channel attention module.

[0047] Figure 9 This is a comparison chart of the model parameter magnitude and trainable parameters. On the left is CNN, and on the right is CNN+SEBlock.

[0048] Figure 10 This is a chart of the model prediction results. Detailed implementation manners

[0049] The present invention will be further introduced below through embodiments in conjunction with the accompanying drawings.

[0050] The flowchart of the lightweight automatic sleep staging method provided by the present invention is as Figure 1 shown. First, the original EEG signals are obtained from the Sleep-EDF database, and signal preprocessing is performed, including filtering and baseline correction, to improve the signal quality. Then, a lightweight model is constructed, combining a convolutional neural network and a channel attention module, to enhance the feature extraction ability without significantly increasing the model magnitude. In the model training and optimization stage, a dual optimizer and cross-validation strategy are adopted. The accuracy of the trained model reaches 85.6%, which is higher than that of the same type of literature. At the same time, the model magnitude and training time are much lower than those of similar models. After training is completed, the model is exported for easy use in practical applications. When data to be predicted is input, the model can quickly output the corresponding sleep stage results.

[0051] After obtaining the Sleep-EDF dataset, since its sampling rate is 100Hz, in order to correspond to the sleep labels, the data is segmented, with 3000 data points in each segment. After processing, statistical analysis is performed on the sleep labels, and the number and proportion of the five types of sleep labels obtained are shown in the following table.

[0052] Sleep stage Epoch number Ratio W 10197 23.06% N1 2804 6.34% N2 17799 40.25% N3 5703 12.90% REM 7717 17.45% Total 44220 100.00% 。

[0053] The EEG data preprocessing process is designed based on the characteristics of physiological signals and the sources of noise, including filtering and baseline correction. Filtering is the basic operation of preprocessing. A 47 - 53 Hz Butterworth band - stop filter (4th order) is used to effectively eliminate the 50 Hz power - line interference. After removing the power - line interference, a Butterworth low - pass filter with a cut - off frequency of 35 Hz (6th order) is used. There are often low - frequency trend terms in EEG signals, and baseline correction is required. The moving average method is adopted. First, the mean value of the signals within each sliding window is calculated and used as the baseline component of that window. Then, the original signal is subtracted by the corresponding baseline component to remove the low - frequency interference. The comparison of EEG signals before and after preprocessing is as Figure 2 shown.

[0054] The lightweight automatic sleep staging network architecture involved in the present invention is as Figure 3 shown. This is a structure that stacks multiple one - dimensional convolutional neural networks (1D - CNN) and combines a channel attention mechanism (Squeeze - and - Excitation Block, abbreviated as SEBlock), including two parts: feature extraction and classification output. The basic operation of CNN is convolution, and its mathematical form is:

[0055]

[0056] where f is the input data and g is the convolution kernel. Through the convolution operation, the input data and the convolution kernel are multiplied element - by - element and summed to capture the local patterns in the input data. The SEBlock is a module used to enhance the feature representation ability of convolutional neural networks, mainly composed of three parts: Squeeze (compression), Excitation (excitation), and Reweight (re - weighting). The Squeeze operation performs global average pooling on the input feature map, compressing the two - dimensional feature map of each channel to obtain a tensor with a shape of 1×1×C, where C is the number of channels. The Excitation operation is realized through two fully - connected layers and activation functions. The first fully - connected layer reduces the dimension of the compressed feature, uses a scale factor to reduce the number of parameters, and uses the ReLU activation function to increase non - linearity. The second fully - connected layer restores the feature dimension to the original number of channels, and finally uses the Sigmoid function to normalize the output value. The Reweight operation multiplies the weights obtained from the Excitation operation with the input feature map channel - by - channel to enhance the features of important channels. The schematic diagram of the SEBlock is as Figure 4 shown.

[0057] Specifically, the feature extraction part of the network consists of 4 one-dimensional convolutional modules and 2 channel attention modules. The number of input channels of the initial convolutional layer is adjustable. When the number of channels is 1, it is single-channel input, and when the number of channels is greater than 1, it is multi-channel input. The number of output channels is 16, the convolutional kernel size is 7, followed by a batch normalization layer and a ReLU activation function to achieve coarse-grained extraction of initial features. The number of input channels of the second convolutional layer is 16, the number of output channels is 32, the convolutional kernel size is 7, followed by a Dropout layer with a dropout rate of 0.1, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 9 and a stride of 4 to extract fine-grained spatio-temporal features. The number of input channels of the third convolutional layer is 32, the number of output channels is 64, the convolutional kernel size is 5, followed by a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 7 and a stride of 3 to enhance the local feature expression ability. The number of input and output channels of the fourth convolutional layer is 64, the convolutional kernel size is 3, followed by a Dropout layer with a dropout rate of 0.1, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 5 and a stride of 3 to further reduce the dimension and suppress redundant features. The channel attention module is embedded after the second and fourth convolutional modules. It generates a channel description vector through global average pooling, compresses it to 1 / 16 of the original number of channels through two fully connected layers and then restores the original size, and generates a weight coefficient using the Sigmoid function to perform channel weighting.

[0058] The above design follows the general paradigm of feature extraction: the shallow network extracts local detailed features, and the deep network extracts global semantic features. Among them, the number of channels in the convolutional layer increases layer by layer, and the convolutional kernel size decreases layer by layer to achieve hierarchical feature extraction. While ensuring that the network can learn richer features, it avoids excessive expansion of the number of parameters; the window size of the max pooling layer decreases layer by layer to achieve progressive dimensionality reduction while retaining important features. The introduction of the channel attention module further enhances the selectivity of feature extraction.

[0059] The classification output part of the network consists of 3 fully connected layers and a Softmax module. The first fully connected layer maps the features to 128 dimensions, the second layer reduces to 64 dimensions, and the third layer outputs a 5-dimensional classification result corresponding to the probabilities of five sleep stages: W, N1, N2, N3, and REM. The first two layers are followed by a Dropout layer with a dropout rate of 0.2 and a ReLU activation function. The Softmax layer normalizes the output probabilities to generate the final classification result. The above design gradually reduces the dimension while retaining key information, effectively improving the classification performance.

[0060] Since this task is a five-classification task, the cross-entropy loss function is used as the loss function to measure the difference between the predicted probability distribution and the true distribution. The function is defined as:

[0061]

[0062] Among them, N is the number of samples, and y i,c is the true label of sample i, using one-hot encoding, is the predicted probability that sample i belongs to class c.

[0063] Before training, the original dataset is divided into a training set and a test set in a ratio of 7:3. While ensuring sufficient training data, it provides a reliable evaluation of the model performance. The training set data is divided using 10-fold cross-validation, the batch size is 128, and the total number of training epochs is 30. While ensuring that the model is fully trained, it avoids the risk of overfitting. A two-stage optimization strategy is adopted. In the initial stage of training (1 - 5 epochs), the Adam optimizer is used; when entering the fine-tuning stage (6 - 30 epochs), the SGD optimizer is switched to update the model parameters.

[0064] To prevent overfitting, multiple Dropout layers are added to the network, a weight_decay parameter is added to the classifier to limit the weight size, and an early stopping mechanism is added. When the validation set loss does not decrease for 5 consecutive epochs, the training is terminated and rolled back to the best weights.

[0065] Indicators such as accuracy (Accuracy), F1-Score, Cohen's Kappa coefficient, and confusion matrix are used to evaluate the model performance. Accuracy represents the proportion of the number of samples correctly predicted by the model to the total number of samples. The F1 score is used to comprehensively measure the classification performance of the model. Cohen's Kappa coefficient measures the consistency between the classification result and random classification. The confusion matrix intuitively shows the classification result in the form of a matrix, and the diagonal elements represent the number of samples correctly classified for each category.

[0066] The FPz-Cz channel is selected as the input, and the training results are compared with existing single-channel automatic sleep staging algorithms (DeepSleepNet, TinySleepNet). The results are as Figure 5As shown in the figure. Under the requirement of lightweight design, this method achieves performance comparable to that of existing algorithms. From the specific indicators, the accuracy of this algorithm reaches 85.6%, slightly higher than 82.0% of DeepSleepNet and 85.4% of TinySleepNet, indicating that the method in this study has an advantage in the overall classification accuracy. In terms of the F1-score index, this method reaches 78.2%, slightly lower than 80.5% of TinySleepNet but higher than 76.9% of DeepSleepNet, indicating that this method performs well in classification performance. In addition, in terms of the Cohen's kappa index, this method reaches 0.804, slightly lower than 0.809 of TinySleepNet but higher than 0.763 of DeepSleepNet, indicating that this method has an advantage in consistency.

[0067] It should be emphasized that although the model scale is greatly compressed, the performance of this algorithm does not show a significant decline. Compared with existing methods, this method abandons the long short-term memory network (LSTM) and multi-resolution input method (MRCNN) that may significantly increase the number of model parameters, and only uses the basic CNN, combined with the SEBlock module that hardly increases the number of model parameters, achieving a good balance between performance indicators and model scale.

[0068] The above methods are all single-channel inputs. To verify the gain of multi-channel and multi-modal inputs on classification performance, the input in this method is changed to 2 channels (FPz-Cz / Pz-Oz) and 3 channels (FPz-Cz / Pz-Oz / EOG), and compared with single-channel input. The results of performance indicators are as Figure 6 shown, and the results of the confusion matrix are as Figure 7 shown. In the single-channel (FPz-Cz) configuration, the accuracy is 85.6%, the F1-score is 78.2%, and the Cohen's kappa is 80.4%. When increased to 2 channels, the accuracy is improved to 87.1%, the F1-score is improved to 79.4%, and the Cohen's kappa is improved to 82.3%. When further increased to 3 channels, the accuracy reaches 0.879, the F1-score reaches 0.800, and the Cohen's kappa reaches 0.831. Through comparison, it can be found that compared with single-channel input, the results of two-channel input are improved in all indicators, and the performance improvement of three channels is the most significant, indicating that multi-channel and multi-modal inputs can provide richer classification information, effectively improve classification performance, and have advantages in practical applications.

[0069] In addition, ablation experiments were also carried out to quantify the impact of the channel attention module on performance indicators and model scale. Remove the channel attention module and compare the classification performance under different combinations. The results are asFigure 8 As shown. It can be seen that after adding the channel attention module, the model has improved in all three metrics of accuracy, F1-score, and Cohen's kappa. Specifically, the accuracy has increased from 86.7% to 87.9%, the F1-score has increased from 79.1% to 80.0%, and Cohen's kappa has increased from 0.818 to 0.831, indicating that the addition of the channel attention module has significantly improved the model performance. In addition, the scale and the number of trainable parameters of the model were calculated, and the results are as Figure 9 shown. It can be seen that the introduction of the channel attention module has very little impact on the model scale, only increasing the number of trainable parameters of the model from 191,109 to 191,749, and only increasing the estimated total size of the model from 2.43 MB to 2.44 MB, which is almost negligible. However, the introduction of the channel attention module has significantly improved the model performance, indicating that the channel attention module is a very effective lightweight module.

[0070] To implement model deployment, the trained model was exported in the.pth format, and the stored file size is only 772 KB. Moreover, this file can be converted into formats such as ONNX and is easy to be deployed on various embedded devices. Another 5 nights of sleep data (a total of 5147 epochs) were selected from the Sleep-EDF78 dataset for prediction, and the results are as Figure 10 shown, with the obtained accuracy of 80.9% and the prediction time of only about 23 seconds. In summary, this method has significant advantages for embedded applications.

[0071] References

[0072] [1] Berry R B, Brooks R, Gamaldo C E, et al. The AASM manual for the scoring of sleep and associated events[J]. Rules, Terminology and Technical Specifications, Darien, Illinois, American Academy of Sleep Medicine, 2012, 176(2012):7.

Claims

1. A lightweight automatic sleep staging method applicable to on-chip migration, characterized in that, A lightweight deep learning model is constructed by introducing a multi-layer convolutional neural network and a channel attention mechanism. Combined with an efficient training strategy, it significantly reduces the model's parameter count and inference time while ensuring accuracy, and is applicable to real-time sleep monitoring on embedded devices. The specific steps are as follows: (1) Obtain the Sleep-EDF dataset for model training; (2) Preprocess the raw EEG signals; This includes using a Butterworth filter for band-stop filtering and low-frequency filtering to remove noise, then using a moving average method to perform baseline correction on the signals to ensure that the signal quality meets the model input requirements. After that, segmentation is performed, with each segment having a data length of 30 seconds, retaining the sleep stage labels, and constructing training samples; (3) Construct the sleep staging model; Specifically, use the Pytorch framework to construct a sleep staging model that supports single-channel and multi-channel inputs. This model is divided into two parts: feature extraction and classification output. The feature extraction part includes 4 one-dimensional convolutional modules and 2 channel attention modules, and the classification output part includes 3 fully connected layers and a Softmax output layer; (4) Train and optimize the sleep staging model; Specifically, input the preprocessed EEG signals into the above sleep staging model, perform initial training using the cross-entropy loss function and the Adam optimizer, switch to the SGD optimizer for fine-tuning during the training process, and use cross-validation to evaluate the model performance; (5) Predict and deploy the sleep staging model; This includes, for the trained model, calculating the model's parameter magnitude and the single-inference operation time, and generating a deployable model file.

2. The lightweight automatic sleep staging method according to claim 1, wherein The Sleep-EDF dataset mentioned in step (1) contains polysomnogram (PSG) records from multiple healthy subjects, and is divided into the standard version Sleep-EDF20 and the extended version Sleep-EDF78 according to the number of subjects, covering 2-channel EEG, 1-channel EOG, and 30s-epoch sleep stage labels annotated according to the AASM standard.

3. The lightweight automatic sleep staging method according to claim 1, wherein The sleep staging model mentioned in step (3) is designed according to lightweight requirements, that is, the number of channels in the convolutional layer doubles layer by layer, the convolutional kernel size decreases layer by layer, and the dimension of the fully connected layer decreases in a stepped manner. Specifically: For the first convolutional module, the input channel number is adjustable. When the channel number is 1, it is single-channel input, and when the channel number is greater than 1, it is multi-channel input. The output channel number is 16, the convolutional kernel size is 7, the stride is 4, the padding is 1, followed by a batch normalization layer and a ReLU activation function; For the second convolutional module, the input channel number is 16, the output channel number is 32, the convolutional kernel size is 7, the padding is 1, followed by a Dropout layer, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 9 and a stride of 4; For the third convolutional module, the input channel number is 32, the output channel number is 64, the convolutional kernel size is 5, the padding is 1, followed by a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 7 and a stride of 3; The fourth convolutional module has 64 input and output channels, a convolutional kernel size of 3, a padding of 1, followed by a Dropout layer, a batch normalization layer, a ReLU activation function, and a max pooling layer with a kernel size of 5 and a stride of 3; Channel attention modules are embedded after the second and fourth convolutional modules. Channel description vectors are generated through global average pooling, compressed to 1 / 16 of the original number of channels after passing through two fully connected layers and then restored, and channel weight coefficients are generated using the Sigmoid function to achieve adaptive calibration of feature channels; The first layer of the fully connected layer maps the features to 128 dimensions, the second layer reduces them to 64 dimensions, and the third layer outputs a 5-dimensional classification result corresponding to the probabilities of five sleep stages, namely W, N1, N2, N3, and REM. Dropout layers and ReLU activation functions are connected after the first two layers, and the Softmax layer normalizes the output probabilities to generate the final classification result.

4. The lightweight automatic sleep staging method according to claim 3, wherein The total scale of the sleep staging model is compressed from more than 20MB to less than 2.5MB, and the number of trainable parameters is compressed from more than 2,000,000 to less than 200,000.

5. The lightweight automatic sleep staging method according to claim 1, wherein In the model training and optimization in step (4), specifically: For a five-classification task, the loss function uses the cross-entropy loss function to measure the difference between the predicted probability distribution and the true distribution. The function is defined as: where N is the number of samples, and y i,c is the true label of sample i, using one-hot encoding, is the predicted probability that sample i belongs to class c; The original dataset is divided into a training set and a test set in a ratio of 7:

3. The training set data is divided using 10-fold cross-validation, the batch size is 128, and the total number of training epochs is 30; In the initial stage of training, the Adam optimizer is used to quickly approach the local optimum using its adaptive learning rate feature; After the rapid convergence in the initial stage, it enters the fine-tuning stage, switches to the SGD optimizer with momentum, and updates the model parameters by randomly selecting small batches of data for gradient calculation; An early stopping mechanism is added during training. When the validation set loss does not decrease for 5 consecutive epochs, the training is terminated and rolled back to the best weights; A weight_decay parameter is added to the classifier to limit the weight size, and at the same time, a Dropout layer is used to prevent the model from overfitting; Accuracy, F1-Score, and Cohen's Kappa coefficient metrics are used to evaluate the model performance.

6. The lightweight automatic sleep staging method according to claim 1, characterized in that In the model deployment and prediction in step (5), specifically as follows: During training, the time.time() module is called for timing. On the Sleep-EDF20 dataset, the training time for a single epoch is <2 seconds; After training, a.pth model file is generated. The size of this file is less than 1MB and is converted to formats such as ONNX to adapt to resource-constrained devices like STM32; Five nights of sleep data that were not involved in training are selected from the Sleep-EDF78 dataset for prediction, and the required time is less than 30 seconds.

Citation Information

Cited By

  • Sleep quality monitoring method fusing multi-scale features

    CN120827347A

  • A sleep quality monitoring method fusing multi-scale features

    CN120827347B

  • Brain wave detection and classification method and device, program product and electronic equipment

    CN121891025A

  • A sleep quality monitoring method that integrates multiscale features.

    JP7913796B1