Automatic sleep staging method based on window attention mechanism

By using an automatic sleep staging method based on window attention mechanism, the problem of relying on manual interpretation of EEG signal sleep staging is solved, achieving efficient and accurate sleep staging results and reducing costs and time consumption.

CN116509421BActive Publication Date: 2025-11-21XIAN UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310509949.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-05-08
Publication Date
2025-11-21
Estimated Expiration
2043-05-08

AI Technical Summary

Technical Problem

Existing methods for sleep staging based on EEG signals rely on manual interpretation, which is costly and time-consuming, making it difficult to achieve automated and efficient sleep quality assessment.

Method used

An automatic sleep staging method based on window attention mechanism is adopted. By extracting low-frequency and high-frequency information of EEG signal through dual-branch design, and combining feature extraction module and time sequence capture module, deep feature extraction and accurate sleep staging are achieved.

Benefits of technology

It achieves efficient and accurate sleep staging results, reduces reliance on manual interpretation, and improves the automation and efficiency of sleep quality assessment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116509421B_ABST
    Figure CN116509421B_ABST
Patent Text Reader

Abstract

The application discloses an automatic sleep staging method based on a window attention mechanism, and a network comprises a feature extraction module, a feature extraction module, a time sequence capturing module and a classifier. First, a double-path convolutional neural network composed of different convolution kernel sizes is used to realize shallow feature extraction of high and low frequencies of original electroencephalogram signals, and deep feature extraction is realized through stacked multi-layer convolution layers. Then, a feature extraction module composed of dimension reduction and channel attention mechanism is used to reduce the number of output feature channels and retain key feature channels as much as possible. Finally, a time sequence capturing module based on a window attention mechanism is used to realize effective processing of sequence information, and the model focuses more on feature channels in the window. Meanwhile, experience knowledge of doctor interpretation is introduced in weight distribution of the window attention, so that more accurate classification results are finally realized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of physiological signal processing, and relates to an automatic sleep staging method based on a window attention mechanism. BACKGROUND

[0002] Sleep is an important physiological activity that occupies almost one-third of human life, and has an important influence on body recovery and brain function recovery and other physiological activities. Research shows that people with good sleep quality have a healthier body state than people with poor sleep quality. Insufficient sleep affects people's physical strength, mentality, and normal work and life, and even endangers human health and increases the probability of various diseases.

[0003] Sleep medicine obtains the state and changes of the human body in sleep through sleep monitoring based on physiological signals, and then evaluates sleep quality. The first task of sleep quality evaluation is to divide the collected data into sleep stages. Common physiological signals include electroencephalogram (EEG), electrocardiogram (ECG), and electromyogram (EMG), etc. Among them, the EEG records the brain neural activity of the human body in the sleep state, and shows different characteristics in different sleep states. However, the discrimination of the EEG needs a doctor with certain experience to complete, resulting in high cost and long time consumption. Therefore, it is necessary to propose an automatic sleep staging algorithm based on the EEG. SUMMARY

[0004] The purpose of the application is to provide an automatic sleep staging method based on a window attention mechanism, which combines sleep cycle characteristics and self-attention mechanisms to obtain accurate sleep staging results.

[0005] The technical solution adopted by the application is an automatic sleep staging method based on a window attention mechanism, which specifically includes the following steps:

[0006] Step 1: Obtain an EEG signal data set containing sleep staging labels, and divide the data set into a training set and a test set according to individuals;

[0007] Step 2: Preprocess the training set and the test set obtained in step 1;

[0008] Step 3: Construct an automatic sleep staging model for the EEG signal;

[0009] Step 4: Train the network model constructed in step 2 using the training set in step 1 to obtain an optimal automatic sleep staging model;

[0010] Step 5: Put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging result.

[0011] The application also has the characteristics that:

[0012] The specific process of step 2 is:

[0013] The electroencephalogram contained in the record file of all individuals in the data set is divided into frames of 30s, and a corresponding relationship is established with the label data of the label file; then a plurality of signal frames and corresponding labels are merged according to the sequence length; and finally a sequence format sample set is obtained.

[0014] In step 3, the automatic sleep staging model comprises:

[0015] The feature encoding module: adopts a double-branch design idea to extract low-frequency and high-frequency information in the signal, and realizes deep feature extraction through stacking multiple layers;

[0016] The feature extraction module: realizes the reduction of feature channels while retaining key feature information from being discarded;

[0017] The time sequence capture module: combined with the characteristics of the sleep staging task, a window attention mechanism based Transformer is used to realize the processing of sequence information in the input signal;

[0018] The classifier: maps the output features to a category distribution to realize the final sleep staging.

[0019] In step 3, the specific operation of the feature extraction module is:

[0020] Step a. The sequence signal in the training set is outputted high-frequency shallow features through a convolution layer At the same time, the low-frequency shallow features are outputted through another convolution layer

[0021] Step b. The high-frequency shallow features are inputted into a max-pooling layer to output high-frequency shallow features The low-frequency shallow features are inputted into a max-pooling layer to output low-frequency shallow features

[0022] Step c. The high-frequency shallow features are inputted into a convolution block CB1 composed of two convolution layers to output high-frequency deep features The low-frequency shallow features are inputted into a convolution block CB2 composed of two convolution layers to output low-frequency deep features

[0023] Step d. The high-frequency deep features are inputted into a max-pooling layer to output high-frequency shallow features The low-frequency shallow features are input into a max-pooling layer, and the low-frequency deep features

[0024] The high-frequency shallow features and the low-frequency deep features are connected in channels to obtain combined features O5.

[0025] In step 3, the specific operation of the feature extraction module is as follows:

[0026] Step g. The combined features O5 are input into a two-layer convolutional block CB3, and the output features O6 are output, and the activation function of the convolutional layer is ReLU;

[0027] Step h. The features O6 are input into a channel attention CA composed of an average pooling layer and two linear layers, and the activation functions of the two linear layers are ReLU and Sigmoid, respectively, and the output features O7 are output;

[0028] Step i. After the features O7 are copied according to the feature size, they are multiplied by the features O6, and the output features O8 are output;

[0029] Step j. The combined features O5 are input into a convolutional layer, and the output features O9 are output;

[0030] Step l. The features O8 and the features O9 are added, and the output features O 10 .

[0031] In step 3, the specific operation of the time sequence module is as follows:

[0032] Step m. The features O 10 are input into a layer normalization, and the output features O 11 are output;

[0033] Step n. The features O 11 are input into three different linear layers, and the output features Query, Key, and Value are output. After the feature Query is multiplied by the transposed Key feature and normalized, an attention matrix n1 is obtained;

[0034] Step o. A window mask mask is set. Different feature channels are divided into three levels. For feature channels of different importance, different weights are assigned to them to make their attention scores higher. The feature channels in the same frame correspond to the same weight. Assuming that the current frame is of order i, and the window size is set to 3, then the window range is [i-1, i, i+1]. The weight of the i-th frame is the largest, the weights of the i-1-th and i+1-th frames are the second largest, and the weights of the remaining frames are the lowest. Then, the attention matrix n1 is multiplied by the mask mask to obtain a new attention matrix n2;

[0035] Step p. Multiply the new attention matrix n2 with the feature Value, output the feature O 12 ;

[0036] Step q. Add the feature O 12 Input into the linear layer, at the same time, add the feature O 10 After downsampling, add to form a residual connection, output the feature O 13 ;

[0037] Step r. Input the feature O 13 Into the layer normalization, output the feature O 14 ;

[0038] Step s. Input the feature O 14 Into the feedforward neural network FF composed of two linear layers, at the same time, add the feature O 13 To form a residual connection, output the feature O 15 .

[0039] In step 3, the specific operation of the classifier is:

[0040] Step t. Input the feature O 15 Into the linear layer, and get the probability distribution predicted by the model through the Softmax function, and the highest value is the staging result corresponding to the sleep frame.

[0041] In step 4, the multi-class cross-entropy is used as the loss function in the training process, and the classifier converts the feature into a normalized probability distribution through the Softmax function, and the feature dimension and the number of categories are consistent, which is represented as At the same time, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, which is represented as y i , n represents the number of samples, and K represents the number of categories, which is specifically represented as:

[0042]

[0043] The automatic sleep staging method based on window attention mechanism has the advantages that: the double-path convolutional neural network composed of different convolution kernel sizes is used to realize shallow feature extraction of high and low frequencies of the original electroencephalogram signal, and deep feature extraction is realized through stacking multiple convolution layers; then, the feature extraction module composed of dimension reduction and channel attention mechanism reduces the number of output feature channels and retains the key feature channels as much as possible; finally, the time sequence capture module based on window attention mechanism is used to realize effective processing of sequence information, and the model focuses more on the feature channels in the window; meanwhile, the experience knowledge of doctor interpretation is introduced in the weight distribution of window attention, so that more accurate classification results are finally realized. BRIEF DESCRIPTION OF DRAWINGS

[0044] Figure 1 is a flowchart of the automatic sleep staging method based on window attention mechanism of the present application;

[0045] Figure 2 is a structural schematic diagram of the feature extraction module in the automatic sleep staging method based on window attention mechanism of the present application;

[0046] Figure 3 is a structural schematic diagram of the feature extraction module in the automatic sleep staging method based on window attention mechanism of the present application;

[0047] Figure 4 is a structural schematic diagram of the time sequence capture module in the automatic sleep staging method based on window attention mechanism of the present application;

[0048] Figure 5 is a schematic diagram of the window mask in the time sequence capture module in the automatic sleep staging method based on window attention mechanism of the present application. DETAILED DESCRIPTION

[0049] The present application will be described in detail below in combination with the drawings and specific embodiments.

[0050] The automatic sleep staging method based on window attention mechanism of the present application, as shown in Figure 1 , comprises the following steps:

[0051] Step 1, obtaining an EEG signal data set containing sleep staging labels, the data set including a recording file of a subject and a marking file of a doctor, dividing the data set into a training set and a test set according to individuals;

[0052] Step 2, preprocessing the training set and the test set obtained in step 1; the specific process is: dividing the electroencephalogram contained in the recording file of all individuals in the data set into frames according to 30s, and establishing a corresponding relationship with the label data of the marking file; then merging multiple signal frames and their corresponding labels according to the sequence length; finally obtaining a sample set in sequence format.

[0053] Step 3, constructing an automatic sleep staging model for EEG signals, the automatic sleep staging model comprising:

[0054] Feature encoding module: adopting a double-branch design idea, low-frequency and high-frequency information in the signal are extracted respectively, and deep feature extraction is realized through stacking multiple layers, as shown in Figure 2 ; the specific operation is as follows:

[0055] a. The sequence signal in the training set is outputted high-frequency shallow features through a convolution layer with a convolution kernel size of 50, a step of 6 and a padding of 24 Simultaneously, a convolutional layer with a kernel size of 400, a stride of 50, and padding of 200 outputs low-frequency shallow features. Convolutional layers consist of one-dimensional convolution operations, batch normalization, and the GELU activation function;

[0056]

[0057]

[0058] b. High-frequency shallow features The input is fed into a max-pooling layer with a size of 8, a stride of 2, and a padding of 4, and the output is high-frequency shallow features. Low-frequency shallow features The input is fed into a max-pooling layer with a size of 4, a stride of 2, and a padding of 2, and the output is low-frequency shallow features.

[0059]

[0060]

[0061] c. High-frequency shallow features The input is fed into a convolutional block CB1 consisting of two convolutional layers with a kernel size of 8, a stride of 1, and padding of 4, and the output is high-frequency deep features. Low-frequency shallow features The input is fed into a convolutional block CB2 consisting of two convolutional layers with a kernel size of 7, a stride of 1, and padding of 3, and the output is low-frequency deep features.

[0062]

[0063]

[0064] d. High-frequency deep features The input is fed into a max-pooling layer with a size of 4, a stride of 4, and a padding of 2, and the output is high-frequency shallow features. Low-frequency shallow features The input is fed into a max-pooling layer with a size of 2, a stride of 2, and a padding of 1, and the output is low-frequency deep features.

[0065]

[0066]

[0067] f. High-frequency shallow features and low-frequency deep features By connecting the channels, we obtain the combined feature O5;

[0068]

[0069] Feature extraction module: to reduce the feature channels while retaining key feature information from being discarded, as shown in Figure 3 ; the specific operation is as follows:

[0070] g. Input the combined feature O5 into two convolutional blocks CB3 with a convolution kernel size of 1, a step of 1, and padding of 0, output feature O6, and the activation function of the convolutional layer is ReLU;

[0071] O6 = CB3 (O5) (10) ;

[0072] h. Input the feature O6 into the channel attention CA composed of an average pooling layer and two linear layers, and the activation functions of the two linear layers are ReLU and Sigmoid respectively, output feature O7;

[0073] O7 = Sigmoid (FC2 (ReLU (FC1 (O6))) ) (11) ;

[0074] i. After duplicating the feature O7 according to the feature size, multiply it with the feature O6, output feature O8; O8 = O6 * Duplicate (O7) (12) ;

[0075] j. Input the combined feature O5 into a convolutional layer with a convolution kernel size of 1, a step of 1, and padding of 0, output feature O9;

[0076] O9 = Conv1 (O5) (13) ;

[0077] l. Add the feature O8 and the feature O9, output the feature O 10 ;

[0078] O 10 = O8 + O9 (14) ;

[0079] Timing capture module: combined with the characteristics of sleep staging tasks, the Transformer based on window attention mechanism is used to process the sequence information in the input signal, as shown in Figure 4 ; the specific operation is as follows:

[0080] m. Input the feature O 10 into the layer normalization, output the feature O 11 ;

[0081] O 11 = LayerNorm (O 10 ) (15) ;

[0082] n. Input the feature O 11Input three different linear layers, output features Query, Key, Value, multiply the features Query and transposed Key features and normalize to get the attention matrix m1;

[0083] Query = FC3 (O 11 ) (16) ;

[0084] Key = FC4 (O 11 ) (17) ;

[0085] Value = FC5 (O 11 ) (18) ;

[0086] m1 = softmax (Query * Key T ) (19) ;

[0087] o. Set the window mask mask, as shown in Figure 5 ; Different feature channels are divided into three levels, and different weights are given to different important feature channels to make their attention scores higher. The same feature channel in the same frame corresponds to the same weight; Assuming that the current frame is the sequence number i, and the window size is 3, then the window range is [i-1, i, i+1]; The weight of the i-th frame is the largest, the weights of i-1 and i+1 frames are the second, and the weights of the remaining frames are the lowest; Then, multiply the attention matrix m1 and the mask mask to get a new attention matrix m2;

[0088] m2 = m1 * mask (20) ;

[0089] p. Multiply the new attention matrix m2 and the feature Value to output the feature O 12 ;

[0090] O 12 = m2 * Value (21) ;

[0091] q. Input the feature O 12 into the linear layer, and add it to the down-sampled feature O 10 to form a residual connection, and output the feature O 13 ;

[0092] O 13 = FC6 (O 13 ) + DownSampling (O 10 ) (22) ;

[0093] r. Input the feature O 13 into the layer normalization, and output the feature O 14 ;

[0094] O14 =LayerNorm(O 13 ) (twenty three);

[0095] s. Feature O 14 The input is fed into a feedforward neural network FF consisting of two linear layers, and simultaneously added to the features. 13 Constructing residual connections, outputting feature O 15 ;

[0096] O 15 =FeedForward(O 14 )+O 13 (twenty four);

[0097] Classifier: Maps the output features to a class distribution to achieve the final sleep staging; the specific operation is as follows:

[0098] t. Feature O 15 The input is placed into the linear layer, and the probability distribution predicted by the model is obtained through the Softmax function. The highest value is the stage result of the corresponding sleep frame.

[0099] Output = Sofmax(FC7(O) 15 )) (25);

[0100] Step 4: Train the network model built in Step 2 using the training set from Step 1 to obtain the optimal automatic sleep staging model. The classifier transforms features into a normalized probability distribution using the Softmax function, and its output feature dimension maintains the same dimensionality as the number of classes, represented as... Simultaneously, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, denoted as y. i n represents the number of samples, and K represents the number of classes. Specifically, it is expressed as:

[0101]

[0102] Step 5: Input the test set from Step 2 into the automatic sleep staging model trained in Step 3, and output the sleep staging results. To illustrate the effectiveness of this invention, the publicly available dataset Sleep-EDF was used as the target dataset. The method proposed in this invention was compared with methods in currently published papers. The comparison results are shown in Table 1 below. It can be seen that this invention achieves excellent performance in all evaluation metrics.

[0103] Table 1

[0104]

[0105] Example 1

[0106] The automatic sleep staging method based on window attention mechanism specifically comprises the following steps:

[0107] Step 1, obtain an EEG signal data set containing sleep staging labels, and divide the data set into a training set and a test set according to individuals;

[0108] Step 2, pre-process the training set and the test set obtained in step 1;

[0109] Step 3, construct an automatic sleep staging model for EEG signals;

[0110] Step 4, train the network model constructed in step 2 using the training set in step 1 to obtain an optimal automatic sleep staging model;

[0111] Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging result.

[0112] Embodiment 2

[0113] On the basis of embodiment 1, the specific process of step 2 is as follows:

[0114] Divide the EEG signals contained in the record files of all individuals in the data set into frames with a length of 30s, and establish a corresponding relationship with the label data of the mark file; then merge multiple signal frames and their corresponding labels according to the sequence length; and finally obtain a sample set in sequence format.

[0115] Embodiment 3

[0116] On the basis of embodiment 2, in step 3, the automatic sleep staging model comprises:

[0117] Feature encoding module: adopts a double-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realizes deep feature extraction through stacking multiple layers;

[0118] Feature extraction module: realizes the reduction of feature channels while retaining key feature information from being discarded;

[0119] Timing capture module: combined with the characteristics of the sleep staging task, a window attention mechanism based Transformer is used to realize the processing of sequence information in the input signal;

[0120] Classifier: maps the output features to a category distribution to realize the final sleep staging.

Claims

1. An automatic sleep staging method based on window attention mechanism, characterized in that: Specifically comprising the following steps: Step 1, obtaining an EEG signal data set containing sleep staging annotations, dividing the data set into a training set and a test set according to individuals; Step 2, preprocessing the training set and the test set obtained in step 1; The specific process of step 2 is: Divide the electroencephalogram signals contained in the record files of all individuals in the data set into frames of 30s, and establish a corresponding relationship with the label data of the mark file; then merge multiple signal frames and their corresponding labels according to the sequence length; finally obtain a sample set in sequence format; Step 3, constructing an automatic sleep staging model for EEG signals; In step 3, the automatic sleep staging model includes: Feature encoding module: adopt a double-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realize deep feature extraction through stacked multiple layers; Feature extraction module: realize the reduction of feature channels while retaining key feature information from being discarded; Timing capture module: combined with the characteristics of the sleep staging task, a window attention mechanism based Transformer is used to realize the processing of sequence information in the input signal; Classifier: map the output features to a category distribution to realize the final sleep staging; In step 3, the specific operation of the feature extraction module is: step a. The sequence signal in the training set is outputted high-frequency shallow features through a convolution layer Meanwhile, low-frequency shallow features are outputted through another convolution layer ; step b. The high-frequency shallow features are inputted into a max-pooling layer to output high-frequency shallow features , and the low-frequency shallow features are inputted into a max-pooling layer to output low-frequency shallow features ; step c. The low-frequency shallow features are inputted into a convolution block composed of two convolution layers to output high-frequency deep features , and the low-frequency shallow features are inputted into a convolution block composed of two convolution layers CB 2 to output low-frequency deep features ; step d. The high-frequency deep features are inputted into a max-pooling layer to output high-frequency shallow features , and the low-frequency deep features are inputted into a max-pooling layer to output low-frequency deep features ; step f. The high-frequency shallow features and the low-frequency deep features are connected in channels to obtain combined features O5; In step 3, the specific operation of the feature extraction module is as follows: Step g. Input the combined feature O5 into the two convolutional blocks. The output feature is O6, and the activation function of the convolutional layer is ReLU; step h. Input the feature O6 into the channel attention layer, which consists of an average pooling layer and two linear layers. CA In the above steps, the activation functions of the two linear layers are ReLU and Sigmoid, respectively, and the output feature O7 is obtained. Step i. After copying feature O7 according to the feature size, it is multiplied with feature O6 to output feature O8. Step j. The combined feature O5 is input into the convolutional layer to output feature O9. Step l. Features O8 and O9 are added to output feature O. 10 ; In step 3, the specific operation of the timing module is: step m. inputting the feature O 10 In input layer normalization, output the feature O 11 ; step n. inputting the feature O 11 ; inputting three different linear layers, outputting the features Query, Key and Value, multiplying the features Query and transposed Key and normalizing to obtain an attention matrix m1; step o. setting a window mask mask; dividing different feature channels into three levels, for different important feature channels, giving different weights to make their attention scores higher, and the same feature channels in the same frame correspond to the same weight; assuming that the current frame is i, and the window size is 3, then the window range is [i-1, i, i+1]; the weight of the i-th frame is the largest, the weights of the i-1-th frame and the i+1-th frame are the second, and the weights of the remaining frames are the lowest; then, multiplying the attention matrix m1 and the mask mask to obtain a new attention matrix m2; step p. multiplying the new attention matrix m2 and the feature Value to output the feature O 12 ; step q. inputting the feature O 12 into a linear layer, and adding the features O 10 after downsampling to form a residual connection, outputting the feature O 13 ; step r. inputting the feature O 13 into an input layer normalization, outputting the feature O 14 ; step s. inputting the feature O 14 into a feedforward neural network FF composed of two linear layers, and adding the features O 13 to form a residual connection, outputting the feature O 15 ; In step 3, the specific operation of the classifier is: Step t. Feature O 15 In the input linear layer, and through the Softmax function, the probability distribution of the model prediction is obtained, and the highest value is taken as the sleep stage result corresponding to the sleep frame. Step 4, using the training set in step 1 to train the network model constructed in step 2 to obtain the optimal automatic sleep staging model; Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging result.

2. The automatic sleep staging method based on window attention mechanism according to claim 1, characterized in that: In step 4, the multi-class cross-entropy is used as the loss function in the training process, and the classifier converts the features into a normalized probability distribution through the Softmax function. The output feature dimension is consistent with the number of categories, which is represented as Meanwhile, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, which is represented as Specifically, it is represented as: (1) where n represents the number of samples, K represents the number of categories.

Citation Information

Patent Citations

  • Sleep staging method based on deep learning

    CN111783534A

  • Sleep signal automatic staging method based on improved deep learning algorithm model

    CN114366038A