A flexible sleep staging method and device based on multi-channel configuration and unified processing
By constructing a deep neural network architecture based on convolutional neural networks and transformer networks, multi-channel EEG signals are processed uniformly, solving the problem of poor generalization performance of sleep staging methods across central datasets, and achieving high accuracy and flexible sleep staging results.
Patent Information
- Application Number
- CN202411673708.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-11-21
AI Technical Summary
Existing sleep staging methods have poor generalization performance on cross-center datasets and are difficult to effectively handle sleep EEG datasets with different channel configurations and numbers, resulting in insufficient accuracy and robustness.
A deep neural network architecture based on convolutional neural networks and transformer networks is adopted to construct a sleep prediction model through signal segmentation, feature extraction, fusion and prediction modules. It uniformly processes multi-channel EEG signals and processes datasets with different numbers of channels through padding and masking operations.
It improves the cross-dataset generalization of the sleep staging process, maintaining high accuracy and stable sleep staging results on different datasets, and adapting to the platform requirements of different computing resources.
Smart Images

Figure CN119498787B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of sleep monitoring, and in particular relates to a flexible sleep staging method and device based on unified processing of multi-channel configuration. Background Technology
[0002] Clinically, sleep staging using overnight sleep data (including physiological signals such as EEG, EEG, and EMG) recorded by polysomnography (PSG) is the gold standard for sleep monitoring and related disease diagnosis. Traditionally, clinicians or technicians manually staging PSG recordings according to the AASM sleep staging rules, dividing sleep into 30-second segments. The total overnight PSG recording time is approximately 7–9 hours, and doctors spend an average of 2 hours completing sleep staging. This process is not only time-consuming and inefficient but also easily influenced by the doctor's subjective experience.
[0003] Over the past few decades, numerous computer-based automatic sleep staging methods have been proposed. These methods can be divided into two categories based on the algorithms used: 1) Automatic sleep staging methods based on traditional machine learning: preprocessing EEG data to extract relevant EEG features; selecting the extracted features; and classifying the selected EEG features using models such as support vector machines, Bayesian models, and random forests.
[0004] 2) Deep learning-based automatic sleep staging method: Preprocess EEG data, train deep neural networks to model the mapping relationship between signals and sleep stages, and classify them in an end-to-end manner.
[0005] Machine learning-based sleep staging methods heavily rely on domain knowledge for feature extraction, and because features are manually designed, it's difficult to extract comprehensive sleep characteristics, resulting in poor accuracy and robustness. While deep learning-based automatic sleep staging methods have achieved accuracy comparable to human experts on large-scale datasets, their cross-center generalization performance is poor. This is because independent and identically distributed (i.i.d.) data is a prior assumption of deep learning; however, the lack of a unified standard for PSG data collection leads to significant differences in data distribution between datasets from different centers, specifically in subject population, electrode setup, number of channels, sampling rate, and signal-to-noise ratio.
[0006] Patent document CN118614893A discloses an end-to-end sleep staging monitoring method based on heart rate variability. The method includes: extracting HRV through unrestricted acquisition of BCG signals and simultaneously acquiring polysomnography (PSG) signals; training an end-to-end deep learning network for five stages; selecting the most suitable network model by comparing the performance of different networks; and using the selected network model to achieve low-cost home sleep monitoring.
[0007] Patent document CN116269212A discloses a deep learning-based multimodal sleep stage prediction method, including: Step 1: acquiring the raw PSG signal; segmenting the signal into 30s segments and preprocessing it; Step 2: using a balanced dataset to perform supervised pre-training on two CNNs of different sizes to prevent overfitting to sleep stages; Step 3: inputting the signal into two pre-trained convolutional neural networks of different sizes, one large and one small, and training the representation learning filter through four convolutions and two poolings; Step 4: fusing the features obtained from the two convolutional neural networks in Step 2 and inputting them into a residual learning network, fusing them again with the features from two bidirectional LSTM modules; Step 5: passing the output from Step 3 through a softmax layer to obtain the sleep stage predicted by the model, combining the softmax function with the cross-entropy loss as the model's loss function for training; and evaluating the model using the SleepEDF dataset. Summary of the Invention
[0008] The purpose of this invention is to provide a flexible sleep staging method and apparatus based on unified processing of multi-channel configuration, which effectively improves the generalization of sleep staging across datasets.
[0009] To achieve the first objective of this invention, the following technical solution is provided: a flexible sleep staging method based on unified processing of multi-channel configuration, comprising the following steps:
[0010] The raw data includes raw multichannel EEG signals from multiple users during sleep, and the EEG signals at unit time steps are labeled according to sleep stage. The raw multichannel EEG signals and labels are combined to form a dataset.
[0011] Construct a deep neural network, which includes a signal segmentation module, a feature extraction module, a feature fusion module, and a prediction module;
[0012] The signal segmentation module divides the original multi-channel EEG signal of each user into units of step size, with time and channel as the horizontal and vertical axes, to generate time × channel EEG images.
[0013] The feature extraction module extracts features from each EEG image of the user through a convolutional neural network encoder to construct a first feature sequence corresponding to the original multi-channel EEG signal.
[0014] The feature fusion module includes the following steps:
[0015] The obtained first feature sequence is subjected to channel encoding and temporal encoding respectively, and the encoded channel vector and temporal vector are concatenated with the first feature sequence to obtain the second feature sequence;
[0016] For the obtained second feature sequence, set the category token corresponding to the time coordinate along the time axis, and add the category token to the beginning of the second feature sequence to construct the corresponding third feature sequence;
[0017] The third feature sequence is padded and masked, and the features in the third feature sequence are extracted by the transformer network encoder to obtain the fourth feature sequence.
[0018] The prediction module makes predictions based on the obtained fourth feature sequence to output the sleep staging results of the corresponding category tokens;
[0019] The deep neural network is trained using the dataset to obtain a sleep prediction model for predicting sleep stages.
[0020] The raw multi-channel EEG signals of the user to be monitored for sleep are input into the sleep prediction model to obtain the corresponding sleep staging results.
[0021] This invention first processes raw sleep EEG data from multiple channels and multiple sleep segments into multiple data blocks of individual sleep segments in single channels. Then, it uses a convolutional neural network (CNN) encoder to extract features from these blocks to form a first feature sequence. Next, it performs vector encoding on the first feature sequence and concatenates the encoded result with the first feature sequence to obtain a second feature sequence. Then, it introduces a category token into the second feature sequence to form a third feature sequence. Finally, it performs padding and masking operations on the third feature sequence and uses a Transformer network encoder to extract features to construct a fourth feature sequence.
[0022] A deep neural network is trained on a dataset consisting of raw multichannel EEG signals and sleep stage labels to obtain a high-quality sleep prediction model.
[0023] Specifically, the sleep stages include, in sequence, the waking phase, non-rapid eye movement (NREM) stage I, NREM stage II, NREM stage III, and rapid eye movement (REM) phase.
[0024] Specifically, after obtaining the raw data, preprocessing is required, which includes data filtering and standard normalization.
[0025] Specifically, the deep neural network is constructed based on a convolutional neural network and a transformer network framework.
[0026] Specifically, the construction process of the second feature sequence is as follows:
[0027] For the first feature sequence, channel encoding and temporal encoding are performed respectively to obtain the channel vector list {ce1,ce2,…,ce|C|} and the time series vector list {te1,te2,…,te L}, where |C| represents the maximum number of channels in the original multichannel EEG signal, and L represents the maximum temporal sequence in the original multichannel EEG signal;
[0028] Each feature in the first feature sequence is concatenated with its corresponding channel vector and time sequence vector, and the concatenated structure is used to construct the corresponding second feature sequence.
[0029] Specifically, the construction process of the third feature sequence is as follows:
[0030] For the second feature sequence, L category tokens are set for the time sequence, where L represents the largest time sequence in the original multichannel EEG signal;
[0031] Add L category tokens to the beginning of the second feature sequence to construct the third feature sequence.
[0032] Specifically, the padding and masking operations are performed as follows:
[0033] For all the original multichannel EEG signals, the third feature sequence is filled with the template of the longest feature sequence.
[0034] The third feature sequence after filling is masked to generate a corresponding binary mask, which is used to mark the filling positions.
[0035] Specifically, the expression for generating the binary mask is as follows:
[0036]
[0037] Among them, M i,j =1 indicates that the j-th feature block of the i-th sequence is a padding feature, M i,j =0 indicates that the j-th feature block of the i-th sequence is a valid feature, C i Let L represent the number of channels in the i-th sequence, and L represent the maximum temporal sequence in the original multichannel EEG signal.
[0038] To achieve the second objective of this invention, the following technical solution is provided: a flexible sleep staging device for performing the steps of the above-described flexible sleep staging method based on unified processing of multi-channel configuration.
[0039] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0040] (1) Unify sleep EEG datasets with different channel configurations and number of channels into the same model framework, thereby enabling the inclusion of numerous public datasets in mixed training to improve the cross-center generalization of the final sleep prediction model.
[0041] (2) After the sleep prediction model is trained and deployed, the accuracy-rate balance can be flexibly adjusted by adjusting the number of input data channels to meet the needs of platforms with different computing resources. Attached Figure Description
[0042] Figure 1 This is a flowchart illustrating the flexible sleep staging method based on unified processing of multi-channel configuration provided in this embodiment;
[0043] Figure 2 This is a schematic diagram of the padding and masking operations for the third feature sequence provided in this embodiment;
[0044] Figure 3 The image shows the test results using different combinations of EEG channels on the HQ dataset provided in this embodiment;
[0045] Figure 4 This is the confusion matrix of sleep staging results on the HQ dataset and the SYSU central dataset provided in this embodiment;
[0046] Figure 5 This embodiment provides a sleep stage mixing matrix for different subjects on the HQ dataset;
[0047] Figure 6 This is a mixed-sleep matrix of different subjects on the SYSU dataset provided in this embodiment. Detailed Implementation
[0048] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0049] like Figure 1As shown in this embodiment, a flexible sleep staging method based on unified processing of multi-channel configurations is provided. This method is a deep neural network model based on a convolutional neural network (CNN) + transformer network (Transformer) architecture. For raw sleep EEG data with multiple channels and multiple sleep segments, it is first processed into multiple single-channel, single-sleep segment data blocks. The EEG data blocks are input into the sleep segment encoder module (CNN) to extract features of single channels and single sleep segments. Then, the obtained feature sequences are input into the sleep sequence encoder module (Transformer) to extract features between multiple channels and multiple sleep segments. In order to handle batches of data with different channel configurations, number of channels, and durations, before inputting the feature sequences into the Transformer, each feature in the sequence is first channel-encoded and temporally encoded. Then, several classification tokens are added to the beginning of the feature sequences, and padding and occlusion operations are performed to make the sequence lengths of the same batch the same. The added classification tokens are used as the final classification features after passing through the Transformer. After passing through a linear layer classifier, several sleep stages are output.
[0050] The specific steps are as follows:
[0051] The raw data includes raw multichannel EEG signals from multiple users during sleep, and the EEG signals at unit time steps are labeled according to sleep stage. The raw multichannel EEG signals and sleep stage labels constitute the dataset.
[0052] For each user's raw multichannel EEG signal, the signal is divided into units of time and channel on the x and y axes to generate time × channel EEG images. In this embodiment, it is assumed that the input raw multichannel EEG signal... It is a sleep sequence composed of L sleep segments, among which It is the number of channels C i A 30-second sleep segment, f s This represents the sampling rate. First, consider x... i Divide the data into blocks along both time and channel dimensions to obtain L×C. i A block of EEG data
[0053] Feature extraction is performed on each EEG image of the user using a convolutional neural network (CNN) encoder to construct the first feature sequence corresponding to the original multi-channel EEG signal. In this embodiment, the above block operation yields an L×C sequence. i A single-channel, single-sleep segment of EEG data block The sequence consists of data blocks. The sleep segment encoder extracts features from a single channel and a single sleep segment. Each data block in the sequence passes through the sleep segment encoder sequentially, outputting its corresponding features. The sleep segment encoder outputs a length of L×C. i The first characteristic sequence e i .
[0054] The obtained first feature sequence is subjected to channel encoding and temporal encoding respectively, and the encoded channel vector and temporal vector are concatenated with the first feature sequence to obtain the second feature sequence. In this embodiment, the above steps result in a sequence of length L×C. i The first characteristic sequence e i The key to this invention is the use of a Transformer network to process EEG data with different numbers and configurations of channels. However, because the Transformer lacks a mechanism for capturing sequence location information, when processing the first feature sequence e... i Before inputting into the Transformer, the sequence e is... i Each feature in the sequence is encoded using both channel encoding and temporal encoding. Specifically, a channel encoding list CE = {ce1, ce2, ..., ce...} is maintained. |C|} and a timing coding list TE = {te1, te2, ..., te L}, where the channel encoding vector ce c (c = 1, ..., |C|) and timing code te l The dimensions of (l=1,…,L) are d ce and d te Let |C| and L represent the maximum number of channels and the maximum time sequence in the dataset, respectively. For sequence e i Each block feature Based on its channel and temporal position, the corresponding encoding vector is retrieved from the channel encoding list and the temporal encoding list, respectively, and concatenated with the block feature to obtain the encoded block feature. This process can be represented as:
[0055]
[0056] Here, ⊕ denotes a vector concatenation operation. The channel coding list CE and the timing coding list TE are learnable parameters.
[0057] For the obtained second feature sequence, category tokens corresponding to the time coordinates are set along the time axis, and these category tokens are added to the beginning of the second feature sequence to form the third feature sequence. In this embodiment, the category tokens are generated as follows: the category tokens are randomly initialized vectors, each vector having the same dimension as each feature in the second feature sequence, and the number of categories equals the number of time points. The category tokens are part of the neural network parameters, iteratively applied during training, and fixed after training. In the second feature sequence... Add L learnable category tokens to the header, forming a structure of length L×(C). i +1) third feature sequence
[0058] The third feature sequence is then padded and masked. For example... Figure 2 As shown, the processes described above all pertain to single EEG sequence samples. In cross-dataset mixed training, the input batch data includes multiple EEG sequence samples from different datasets. These samples have different numbers of channels, and therefore different lengths of the EEG feature sequences. Due to underlying hardware limitations, computers cannot perform matrix operations on such variable-length data. To address this issue, this invention uses padding and occlusion methods. Specifically, for the same batch of data... B represents the batch size, and its corresponding feature sequence is: The length of the third feature sequence of the i-th sample is L·(C i +1), take the maximum sequence length L·(C) from the same batch of data. max +1), and padded all sequences to the maximum sequence length. After padding, we generate a binary mask. Its value is given by the following formula:
[0059]
[0060] Among them, M i,j =1 indicates that the j-th feature block of the i-th sequence is a padding feature, M i,j =0 indicates that the j-th feature block of the i-th sequence is a valid feature. This mask plays a masking role in two places during the training process: first, it is used as an attention mask and input into the Transformer along with the padded feature sequence, so that the padded feature block is ignored when calculating attention; second, when calculating the loss function, only the loss of valid data is calculated, and the loss of padded data is not calculated.
[0061] A Transformer encoder extracts fused features to generate the corresponding fourth feature sequence. In this embodiment, the sleep sequence encoder encodes the padded and occluded third feature sequence to extract features from the sleep sequence (multi-channel, multiple sleep segments). The sleep sequence encoder is based on a Transformer architecture and consists of N Transformer modules. Each Transformer module consists of a multi-head attention layer and a feedforward neural network layer, with layer normalization performed between the two layers. Assuming the input batch feature sequence is E0, the output feature sequence is E... out This process can then be represented as:
[0062]
[0063]
[0064] E out =LN(E N )
[0065] The feature sequence output by the Transformer has the same shape as the input feature sequence. The first L feature blocks (features corresponding to the category tokens) of the output feature sequence are used as the fourth feature sequence E. cls E cls =E out [1:L].
[0066] The classifier's role is to process the fourth feature sequence E output by the encoder (including the sleep segment encoder and the sleep sequence encoder). cls The system performs classification and outputs the probability of each sleep stage. The classifier consists of linear layers, with the number of output neurons equal to the number of sleep stage categories. The output of the linear layers is activated by a softmax function to obtain the category probability distribution, and then by an argmax function to obtain the classification result. Classification feature E cls The L feature blocks are passed through a classifier in sequence to obtain the L sleep segmentation results.
[0067] The deep neural network is trained using the dataset to obtain a sleep prediction model for predicting sleep stages.
[0068] The raw multi-channel EEG signals of the user to be monitored for sleep are input into the sleep prediction model to obtain the corresponding sleep staging results.
[0069] Furthermore, the aforementioned third feature sequence is input into the transformer network to extract sequence features. Features from different channels at the same time are fused into the category token corresponding to that time. This category token serves as the input feature for the classifier during the sleep phase classification, while other feature blocks besides the category token are discarded.
[0070] This embodiment also provides a flexible sleep staging device for performing the steps of the flexible sleep staging method based on multi-channel configuration unified processing provided in the above embodiment.
[0071] To better illustrate the effects of the technical solution provided by this invention, examples are given.
[0072] We collected 10 public datasets as source domains for training and tested them on 2 target center datasets. The configuration of the public datasets is shown in Table 2, and the configuration of the private datasets is shown in Table 3.
[0073] Table 2
[0074]
[0075] The APPLES (The Apnea Positive Pressure Long-term Efficacy Study) dataset is a multicenter dataset used to study the treatment effects of sleep apnea. It contains overnight PSG recordings of 1104 patients with obstructive sleep apnea syndrome (OSAS). The dataset includes 6 EEG / EOG channels and uses the R&K standard for sleep staging annotation.
[0076] Table 3
[0077]
[0078] The DCSM (Danish Center for Sleep Medicine) dataset
[32] consists of 255 PSG records randomly selected from patients with nonspecific sleep-related disorders who visited the Danish Sleep Medicine Center. The dataset contains 8 EEG / EOG channels and uses the AASM standard for sleep staging.
[0079] The DOD (Dreem Open Dataset) dataset consists of two subsets: DOD-H and DOD-O. DOD-H, from the French Armed Forces Biomedical Research Institute (IRBA), contains PSG records from 25 healthy volunteers; DOD-O, from the Stanford Sleep Medicine Center, contains PSG records from 56 patients with OSAS (Obstructive Sleep Asthenia Gravis). DOD-H and DOD-O have 12 and 8 EEG channels, respectively; we selected only 5 and 7 channels, which overlap with the target center dataset, for our experiments. Both datasets have two EOG channels, and both use the AASM standard for sleep staging.
[0080] The HMC (Haaglanden Medical Center) dataset consists of 151 PSG records from the Haaglanden Medical Center in the Netherlands. These records were randomly selected from heterogeneous patients who underwent PSG examinations for various sleep disorders in 2018. The dataset includes 6 EEG / EOG channels and uses the AASM standard for sleep staging.
[0081] The ISRUC (Institute of Systems and Robotics, University of Coimbra) dataset consists of 126 PSG records from the Sleep Medicine Center of the University Hospital of Coimbra, Portugal. It comprises three sets of data: Set 1 contains 100 PSG records from 100 patients diagnosed with sleep disorders; Set 2 contains 16 PSG records from 8 patients diagnosed with sleep disorders; and Set 3 contains 10 PSG records from 10 healthy volunteers. The dataset includes 8 EEG / EOG channels and uses the AASM standard for sleep staging.
[0082] The CAP (Cyclic Alternating Pattern) dataset comprises 108 PSG records collected from the Sleep Disorders Center of the Ospedale Maggiore of Parma, Italy. It includes participants from various populations such as healthy individuals, patients with bruxism, insomnia, narcolepsy, nocturnal frontal lobe epilepsy, periodic lower limb motor sleep apnea, REM sleep behavior disorder, and sleep-disordered breathing. The dataset contains four EEG / EOG channels and is labeled based on the R&K sleep staging criteria.
[0083] The SVUH (St. Vincent's University Hospital) dataset consists of PSG records from 25 patients suspected of having sleep-disordered breathing at St. Vincent's University Hospital in Ireland. It contains four EEG / EOG channels and uses the R&K standard for sleep staging.
[0084] The P2018 (You Snooze You Win: The PhysioNet / Computing in Cardiology Challenge 2018) dataset comes from the 2018 public challenge, provided by the Computational Clinical Neurophysiology Laboratory (CCNL) and the Clinical Data Animation Laboratory (CDAC) at Massachusetts General Hospital. The dataset consists of 994 training data points and 989 test data points, with only the training data providing sleep stage annotations. We used labeled training data containing 7 EEG / EOG channels, and used the AASM standard for sleep stage annotation.
[0085] The STAGES (Stanford Technology Analytics and Genomics in Sleep) dataset is a prospective, cross-sectional, multicenter study involving 20 data collection sites across six centers, including Stanford University. This dataset contains 1833 full-night PSG recordings from 1500 adult / adolescent patients with sleep disorders, including 8 EEG / EOG channels, and is labeled using the AASM sleep staging system.
[0086] The SHHS (Sleep Heart Health Study) dataset comes from a multicenter cohort study conducted by the National Heart, Lung, and Blood Institute (NHLBI) in the United States, which aimed to determine the cardiovascular and other consequences of sleep-disordered breathing. The dataset is divided into two subsets based on the collection time: SHHS-1, which contains 5793 PSG records from 1995 to 1998, and SHHS-2, which contains 2651 PSG records from 2001 to 2003. The SHHS dataset includes four EEG / EOG channels, labeled according to the R&K sleep staging criteria.
[0087] In summary, we collected approximately 13,000 overnight PSG recordings from publicly available datasets as training data, with a total sleep recording duration of approximately 115,000 hours. To evaluate the system in this embodiment, we used private data from two different data centers. The data from these two centers are described below:
[0088] The HQ dataset, sourced from Hangzhou Seventh People's Hospital (Affiliated Mental Health Center of Zhejiang University School of Medicine), contains PSG records from 127 subjects, including 33 healthy individuals, 51 patients with narcolepsy, and 43 patients with depression. The dataset includes 8 EEG / EOG channels at a sampling rate of 512 Hz and was annotated by physicians using the AASM sleep staging system.
[0089] The SYSU dataset, sourced from the Sleep Laboratory of Sun Yat-sen University, comprises 80 PSG records from 21 healthy volunteers and 24 PSG records from 24 patients with depression. The dataset contains 8 EEG / EOG channels, with sampling rates of 500 Hz for healthy subjects and 256 Hz for patients with depression. PSG records were scored by two well-trained sleep technicians according to the AASM criteria.
[0090] For all PSG datasets, we selected the 8 channels of EEG / EOG recommended by the AASM standard as the basis for sleep staging; other channels and other data formats in the datasets were not used. These 8 channels are F3-M2, F4-M1, C3-M2, C4-M1, O1-M2, O2-M1, E1-M2, and E2-M1.
[0091] For raw data processing, we first filtered all EEG / EOG channels using a fourth-order bandpass filter ranging from 0.3 to 35 Hz; then, we resampled the data with different sampling rates to 100 Hz; finally, we performed Z-score normalization on each channel of each PSG data example.
[0092]
[0093] Where x represents one original data point, C represents the set of channels for that data, and mean and std represent the mean and standard deviation, respectively.
[0094] For label processing, we used the current AASM sleep staging standard. For datasets using the R&K standard, we followed the conventional practice of merging stages N3 and N4 into stage N3. In addition, we removed unlabeled sleep segments, which often indicate sensor detachment, sleep interruption, or other abnormalities, and split the data into two segments at the deletion points.
[0095] To quantitatively evaluate the sleep staging performance of the system in this embodiment on target center data, accuracy, macro-F1 score, kappa coefficient, and categorical F1 score were selected as evaluation metrics. y is the predicted label of the i-th sample. i If the corresponding true label is true, then the accuracy is defined as:
[0096]
[0097] Where I(·) is the indicator function and N is the number of samples.
[0098] The F1 score is the harmonic mean of precision and recall. The macro F1 score is the average of the F1 scores for each class, defined as:
[0099]
[0100] in,
[0101]
[0102] Among them TP i FP i and FN i Let K represent the number of true positives, false positives, and false negatives for the i-th category, respectively, and K be the number of categories.
[0103] The kappa coefficient, used to compare the consistency between the model's predicted labels and the true labels, is defined as:
[0104]
[0105] Where P e This refers to the prediction accuracy in random classification scenarios. The Kappa coefficient is a value between -1 and 1; a coefficient above 0.8 is generally considered to indicate good consistency, while a coefficient below 0 means there is no consistency.
[0106] In this example, the sleep segment encoder is based on a CNN (Convolutional Neural Network) architecture and employs a two-branch design with 1D convolutional kernels of different sizes to extract features across different frequency bands. Branch 1 uses smaller convolutional kernels to extract high-frequency features, while Branch 2 uses larger convolutional kernels to extract low-frequency features. The specific parameters of the two branches are shown in Table 5, where the parameters after Conv1d represent the number, size, stride, and padding of the convolutional kernels, and the parameters after MaxPool represent the pooling kernel size, stride, and padding. The outputs of the two branches are concatenated along the feature dimension to ultimately output a 512-dimensional block feature.
[0107] The sleep sequence encoder is based on the Transformer architecture and consists of four Transformer modules. Its dimensions are d = 512 + 32 (channel encoding vectors) + 64 (temporal encoding vectors) = 608. The number of multi-head attention heads is h = 8. The hidden layer dimension of the feedforward neural network is d. fft =d=608.
[0108] The classifier consists of a linear layer and a softmax activation layer. The number of input neurons is equal to the dimension of the sleep sequence encoder output, which is 608. The number of output neurons is equal to the sleep stage category to be classified. In this embodiment, a 5-stage sleep stage classification is used. The parameter settings of the sleep segment encoder model are shown in Table 4.
[0109] Table 4
[0110]
[0111] In this example, a weighted cross-entropy function is used as the loss function during the training process, and L2 regularization is combined to prevent overfitting.
[0112] For a K-class classification problem, given a sample x i and its corresponding one-hot encoded tag in Let the model output after passing through the softmax layer be in Indicates sample x i If the probability of being predicted as class k is given, then the weighted cross-entropy loss function can be expressed as:
[0113]
[0114] Where w k This is the weight of each category. In this embodiment, the normalized value of the inverse of the number of samples in each category is used as the category weight.
[0115] L2 regularization essentially adds a penalty term based on the model parameter norm to the loss function, thereby limiting model complexity. Specifically, let the model parameters be p, then the L2 norm penalty term is...
[0116]
[0117] The overall loss function expression is as follows:
[0118]
[0119] Where λ≥0 is an adjustable hyperparameter used to control the regularization strength. In this embodiment, λ is set to 0.001.
[0120] This embodiment uses Python as the programming language, PyTorch as the deep learning framework, and MATLAB as the data processing and visualization tool. Table 5 lists the relevant software and hardware environment configurations.
[0121] Table 5
[0122] condition Related parameters operating system Ubuntu 20.04.4LTS CPU Intel(R)Xeon(R)Gold 6330CPU@2.00GHz RAM 500GB GPU 2×NVIDIA A800 80GB Graphics card driver nVidia ver.525.105.17 CUDA ver.12.0 Pytorch ver.2.0.0 MATLAB R2022b
[0123] In this embodiment, 10 publicly available datasets are combined as the source domain dataset, and the HQ and SYSU datasets are used as the target centroid datasets. The sleep staging model is trained on the source domain dataset and then tested on the target centroid dataset.
[0124] In this embodiment, the class weights of the weighted cross-entropy loss function are set to w = [0.09, 0.44, 0.06, 0.23, 0.19], which is the normalized value of the reciprocal of the class proportion in the source domain data. Furthermore, the sleep sequence length L is set to 20, i.e., the sequence duration is 10 minutes.
[0125] Furthermore, during the hybrid training process, to prevent the model from over-relying on features from certain channels or too many channels, this embodiment employs a data augmentation method that randomly discards channels: for a channel number of C... i Sample x i Each channel has a probability of p being discarded, where p is set to 0.5.
[0126] This embodiment uses AdamW as the optimizer, with an initial learning rate lr0 set to 1e-4, an L2 regularization coefficient λ set to 1e-3, and a batch size of 256. The total number of training epochs is set to 80, including a 15-epoch warm-up phase where the learning rate increases linearly from 0. After the warm-up phase, the learning rate decays according to a cosine annealing strategy, with a minimum learning rate lr0. min Let's set it to 1e-6. The learning rate for this training process is expressed as...
[0127]
[0128] Where e is the current round number.
[0129] After training, we tested the model on the HQ and SYSU target center datasets to evaluate its generalization ability. Since the model can accept EEG signal samples with any number of channels, we tested different channel combinations. Unless otherwise specified, the experimental results below use data from all eight channels, and the final results are shown in Table 1.
[0130] Table 1 presents the test results of the embodiments on two centers, HQ and SYSU. Benchmark 1 represents the results of training on one center's data and testing on the other center's data, serving as a reference value for the lower bound of the performance of this invention; Benchmark 2 represents the average result of five-fold cross-validation on the local center's data, serving as a reference value for the upper bound of the performance of this invention. The results in Table 1 show that the model and method provided by this invention, through mixed training on large-scale public datasets, achieves performance similar to that of the model trained locally on the previously unseen data (relative to benchmark 2), demonstrating good cross-center generalization performance.
[0131] Table 1
[0132]
[0133] like Figure 3As shown, the results of testing on the HQ dataset using different combinations of EEG channels are presented. The example achieves the highest accuracy when all eight sleep EEG channels are used. As the number of channels used decreases, the accuracy of the example decreases slightly, but the inference speed increases exponentially.
[0134] Figure 4 The image shows the confusion matrix of sleep staging results on the HQ and SYSU datasets in this embodiment. Figure 5 The image shows the sleep stage confusion matrix for healthy subjects, patients with depression, and patients with narcolepsy on the HQ dataset in this embodiment. Figure 6 The image shows the sleep stage confusion matrix for healthy subjects and patients with depression on the SYSU dataset in this embodiment.
[0135] in Figure 4 The confusion matrix of sleep staging results from embodiments of the present invention on the HQ and SYSU datasets is presented. The results show that the model's prediction accuracy is high on both the HQ and SYSU datasets, with significant values at the diagonal positions, indicating good model recognition performance and high classification accuracy across sleep stages. Furthermore, the confusion between different sleep stages is low. This confusion matrix verifies the generalization ability of the embodiments of the present invention on data from different data centers, demonstrating that it maintains high staging accuracy even in cross-dataset testing.
[0136] Figure 5 The confusion matrix of sleep staging results for different subject groups (healthy subjects, patients with depression, and patients with narcolepsy) on the HQ dataset is presented. It can be seen that the model's staging accuracy shows consistency across these three groups, especially in the staging of healthy and narcolepsy patients, where the classification accuracy at the diagonal positions is higher, indicating that the model can adapt to the EEG characteristics of these subjects and perform accurate staging. In the patient group with depression, although the accuracy is slightly lower, the overall performance remains relatively stable. Figure 5 The model of this invention has been verified to be highly adaptable to subjects with different sleep disorders.
[0137] Figure 6 The confusion matrix of sleep staging results for healthy subjects and patients with depression on the SYSU dataset is presented. The confusion matrix shows that the staging accuracy of healthy subjects and patients with depression is relatively similar across different sleep stages, indicating that the model can maintain high cross-population staging accuracy when dealing with subjects with different physiological characteristics. This result demonstrates that the embodiments of the present invention exhibit good generalization ability when dealing with different individual characteristics.
[0138] Table 6
[0139]
[0140] Table 6 shows a comparison of the sleep staging method provided by this invention with other state-of-the-art methods on the HQ and SYSU datasets. The biggest innovation of this invention is its ability to handle datasets with different channel configurations, a capability not found in existing methods. For comparison, in this embodiment, the existing methods are trained using the intersection of sleep EEG channels (C3-M2, E1-M2) across all datasets. In Table 6, 2C represents the two shared channels mentioned above, and 8C represents all eight channels.
[0141] The beneficial effects of this invention include two aspects:
[0142] (1) This invention breaks the limitation of channel configuration differences between different datasets in the field of sleep EEG staging, unifies sleep EEG datasets with different channel configurations and number of channels into a model framework, thereby enabling the inclusion of numerous public datasets in mixed training and improving the cross-center generalization of sleep staging methods.
[0143] (2) The model provided by this invention can flexibly adjust the accuracy-rate balance by adjusting the number of input data channels after training and deployment, so as to meet the needs of clinical platforms with different computing resources.
Claims
1. A flexible sleep staging method based on unified processing of multi-channel configuration, characterized in that, include: The raw data includes raw multichannel EEG signals from multiple users during sleep, and the EEG signals at unit time steps are labeled according to sleep stage. The raw multichannel EEG signals and labels are combined to form a dataset. Construct a deep neural network, which includes a signal segmentation module, a feature extraction module, a feature fusion module, and a prediction module; The signal segmentation module divides the original multi-channel EEG signal of each user into units of step size, with time and channel as the horizontal and vertical axes, to generate time × channel EEG images. The feature extraction module extracts features from each EEG image of the user through a convolutional neural network encoder to construct a first feature sequence corresponding to the original multi-channel EEG signal. The feature fusion module includes the following steps: The obtained first feature sequence is subjected to channel encoding and temporal encoding respectively, and the encoded channel vector and temporal vector are concatenated with the first feature sequence to obtain the second feature sequence; For the obtained second feature sequence, set the category token corresponding to the time coordinate along the time axis, and add the category token to the beginning of the second feature sequence to construct the corresponding third feature sequence; The third feature sequence is padded and masked, and the features in the third feature sequence are extracted by the transformer network encoder to obtain the fourth feature sequence. The prediction module makes predictions based on the obtained fourth feature sequence to output the sleep staging results of the corresponding category tokens; The deep neural network is trained using the dataset to obtain a sleep prediction model for predicting sleep stages. The raw multi-channel EEG signals of the user to be monitored for sleep are input into the sleep prediction model to obtain the corresponding sleep staging results.
2. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 1, characterized in that, After obtaining the raw data, preprocessing is required, which includes data filtering and standard normalization.
3. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 1, characterized in that, The deep neural network is constructed based on a convolutional neural network and a transformer network framework.
4. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 1, characterized in that, The construction process of the second feature sequence is as follows: For the first feature sequence, channel encoding and temporal encoding are performed respectively to obtain the channel vector list {ce1,ce2,…,ce |C| } and the time series vector list {te1,te2,…,te L }, where |C| represents the maximum number of channels in the original multichannel EEG signal, and L represents the maximum temporal sequence in the original multichannel EEG signal; Each feature in the first feature sequence is concatenated with its corresponding channel vector and time sequence vector, and the concatenated structure is used to construct the corresponding second feature sequence.
5. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 1, characterized in that, The construction process of the third feature sequence is as follows: For the second feature sequence, L category tokens are set for the time sequence, where L represents the largest time sequence in the original multichannel EEG signal; Add L category tokens to the beginning of the second feature sequence to construct the third feature sequence.
6. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 1, characterized in that, The padding and masking operations are performed as follows: For all the original multichannel EEG signals, the third feature sequence is filled with the template of the longest feature sequence. The third feature sequence after filling is masked to generate a corresponding binary mask, which is used to mark the filling positions.
7. The flexible sleep staging method based on unified processing of multi-channel configuration according to claim 6, characterized in that, The expression generated by the binary mask is as follows: Among them, M i,j =1 indicates that the j-th feature of the i-th sequence is a padding feature, M i,j =0 indicates that the j-th feature of the i-th sequence is a valid feature, C i Let L represent the number of channels in the i-th sequence, and L represent the maximum temporal sequence in the original multichannel EEG signal.
8. A flexible sleep staging device, characterized in that, The steps are for performing the flexible sleep staging method based on unified processing of multi-channel configuration as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-modal sleep stage prediction method based on deep learning
CN116269212A
Heart rate variability-based end-to-end sleep staging monitoring method
CN118614893A
Emotion recognition method and device based on electroencephalogram signals, electronic equipment and medium
CN116671918A
Mechanical equipment fault diagnosis method based on signal self-decomposition and deep learning
CN118690176A