A sleep stage classification method based on multi-scale feature contrast learning

The sleep stage classification method, which combines multi-scale feature contrastive learning with contrastive representation learning and pyramid temporal context learning, solves the problems of insufficient boundary transition stage identification and class imbalance in existing technologies, and achieves higher accuracy and stability in sleep stage classification.

CN120154301BActive Publication Date: 2025-11-25NORTHWESTERN POLYTECHNICAL UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510283841.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-03-11
Publication Date
2025-11-25
Estimated Expiration
2045-03-11

AI Technical Summary

Technical Problem

Existing sleep staging methods suffer from insufficient ability to identify transitional phases, severe class imbalance, high reliance on manual feature extraction, and insufficient utilization of temporal context information by deep learning models, resulting in limited classification accuracy.

Method used

A sleep stage classification method based on multi-scale feature contrastive learning is adopted, which combines contrastive representation learning, hard sample mining and multi-scale pyramid pooling strategy. The method optimizes the feature representation of EEG signals through contrastive learning, mines boundary and low classification accuracy samples, and uses the pyramid temporal context learning module to capture the dynamic changes at different time scales. Finally, the classification module performs accurate classification.

Benefits of technology

It significantly improves classification performance in minority classes and boundary transition stages, provides multi-dimensional boundary error rate metrics, and experimental results show that it performs well on multiple public datasets, especially in handling boundary ambiguity and class imbalance, thus improving classification accuracy and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120154301B_ABST
    Figure CN120154301B_ABST
Patent Text Reader

Abstract

The application discloses a sleep stage classification method based on multi-scale feature contrast learning, comprising the following steps: acquiring an electroencephalogram signal to be classified; preprocessing the electroencephalogram signal to obtain an enhanced EEG signal; inputting the EEG signal into a trained multi-scale feature contrast representation learning sleep network model, and outputting a final classification result by using the model; the multi-scale feature contrast representation learning sleep network model comprises a contrast representation learning module, a pyramid time context learning module and a classification module connected in sequence; a difficult sample mining unit is arranged in the contrast representation learning module, which is used for mining boundary samples and low classification accuracy samples from a training data set, a sample weighting mechanism is introduced in a supervised contrast loss function, the weight of the sample is set, and the range of the weight is limited through a maximum weight limiting mechanism; finally, the network parameters in the contrast representation learning module are optimized through the supervised contrast loss function.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of biomedical signal processing and deep learning, and particularly relates to a sleep stage classification method based on multi-scale feature contrast learning. BACKGROUND

[0002] Sleep is one of the most important physiological activities of human beings, and sufficient sleep not only supports the normal function of various physiological processes of the human body, but also optimizes learning, memory, attention, emotion and decision-making ability. However, sleep disorders and sleep deprivation are widespread worldwide, constituting a serious public health problem. Polysomnography (PSG) is considered the gold standard for monitoring sleep states, providing key sleep staging information by measuring multiple physiological signals, including electroencephalogram (EEG), electrooculogram (EOG), electromyogram (EMG) and electrocardiogram (ECG). Although PSG is still the gold standard in sleep staging, its manual interpretation process is time-consuming and labor-intensive, and there may be inconsistencies between different experts. In addition, the accuracy of manual classification largely depends on the training of technical personnel, which is particularly impractical in resource-limited environments.

[0003] Therefore, automatic sleep stage classification technology based on machine learning or deep learning has become an increasingly growing research focus. These methods not only greatly reduce the need for manual intervention, but also improve the efficiency and accuracy of sleep staging. Traditional machine learning-based methods usually rely on manual feature extraction, which is time-consuming and labor-intensive, and manual features often perform poorly or are unreliable when dealing with new data. To overcome this problem, deep learning-based methods have gradually replaced traditional methods, which can automatically learn effective features from data, showing stronger generalization ability and higher classification performance.

[0004] In recent years, representation learning methods for EEG have emerged, providing more effective representations of EEG data and achieving significant results in various tasks. However, existing self-supervised or unsupervised contrast learning methods fail to fully utilize the rich labeled PSG data, limiting the improvement of classification accuracy. In addition, relying solely on contrast learning makes it difficult to effectively capture the temporal context of different sleep stages. Therefore, improving sleep staging accuracy, especially in addressing the problems of ambiguous boundaries and class imbalance, remains a key task. SUMMARY

[0005] The purpose of the present application is to provide a sleep stage classification method based on multi-scale feature contrast learning, to solve the problems of existing sleep staging methods, such as insufficient recognition ability for boundary transition stages, serious class imbalance, high dependence on manual feature extraction, and insufficient utilization of temporal context information by deep learning models.

[0006] In order to achieve the above-mentioned tasks, the present application adopts the following technical solutions:

[0007] A sleep stage classification method based on multi-scale feature contrast learning, comprising:

[0008] Obtaining an electroencephalogram signal to be classified; preprocessing the electroencephalogram signal to obtain an enhanced EEG signal; inputting the EEG signal into a trained multi-scale feature contrast representation learning sleep network model, and outputting a final classification result by using the model;

[0009] The multi-scale feature contrast representation learning sleep network model comprises a contrast representation learning module, a pyramid temporal context learning module and a classification module connected in sequence, wherein:

[0010] The contrast representation learning module is used for optimizing the feature representation of the EEG signal, and the embedded features of the contrast learning are obtained by using a contrast learning strategy; the pyramid temporal context learning module is used for modeling the dynamic change relationship of the EEG signal at different time scales according to the embedded features, and the fusion features with time sequence consistency are obtained; the classification module classifies the sleep stage based on the fusion features, and finally outputs the corresponding sleep stage classification result;

[0011] A difficult sample mining unit is arranged in the contrast representation learning module, which is used for mining boundary samples and low classification accuracy samples from a training data set, introducing a sample weighting mechanism in a supervised contrast loss function, setting the weight of the sample and limiting the range of the weight by a maximum weight limiting mechanism; finally, the network parameters in the contrast representation learning module are optimized by the supervised contrast loss function.

[0012] Further, when constructing the training data set, only single-channel EEG signals are retained for the obtained electroencephalogram signals, all EEG signals are resampled to a preset frequency, and band-pass filtering is used to remove low-frequency drift and high-frequency noise in the EEG signals; a pseudo-trace removal method is used to reduce the interference of eye movement and muscle pseudo-traces on the EEG signals; according to the AASM standard, the N3 and N4 stages are merged, and the related EEG signals with incorrect labels are removed; a preset length is cut from each EEG signal as a sample, and the label of the EEG signal is the corresponding sleep stage.

[0013] Further, the contrast representation learning module comprises a data augmentation unit, a momentum encoder and a projection network.

[0014] In the data augmentation unit, the input sample is enhanced by using a data augmentation strategy to generate corresponding positive samples and negative samples; the sample and the corresponding positive sample and negative sample are collectively used as an enhanced sample.

[0015] The enhanced sample is input into a momentum encoder, and sequentially passes through a convolution layer, a batch normalization layer, an average pooling layer and an activation function to learn a complex and abstract feature representation;

[0016] The projection network is used to map the feature representation extracted by the momentum encoder to an embedding space of contrastive learning to obtain corresponding embedding features; wherein a single hidden layer multilayer perceptron (MLP) is used as the projection network.

[0017] Further, the data enhancement strategy is:

[0018] Positive sample: generate a positive sample by applying a plurality of semantic invariant data enhancement operations to the sample; the positive sample has the same label as the current sample;

[0019] Negative sample pair: randomly select a sample different from the label of the current sample from the training data set as a negative sample.

[0020] Further, the embedding feature z is represented as:

[0021]

[0022] wherein z' = P(h t ; w P ; b P ), h t is the feature representation extracted by the momentum encoder, P(·) is the projection network, w P and b P are the weights and biases of the projection network, respectively, is a real number space.

[0023] Further, the contrastive representation learning module is provided with a difficult sample mining unit for mining boundary samples and low classification accuracy samples from the training data set, specifically:

[0024] Boundary samples at sleep stage transition points are identified by the labels of the samples, thereby forming a boundary sample set, which is defined as:

[0025] B = {i | y true [i] ≠ y true [i+1]}

[0026] wherein B is a boundary sample set, y true [i] is the label of the sleep stage corresponding to the ith sample; the ith sample satisfying the condition y true [i] ≠ y true [i+1] is taken as a boundary sample.

[0027] Low classification accuracy samples of a class lower than a threshold value θ accuracy , which is defined as:

[0028] A = {i | y true [i] = c, p o,c < θ accuracy}

[0029] wherein A is a low classification accuracy sample set, c represents a sleep stage class, p o,c represents the probability that the i-th sample belongs to the class c predicted by the multi-scale feature contrast representation learning sleep network model; the sample satisfying y true [i] = c, p o,c < θ accuracy is taken as a low accuracy sample.

[0030] Further, the sample weighting mechanism is introduced in the supervised contrast loss function, the weight of the sample is set and the maximum weight limiting mechanism is used to limit the range of the weight, including:

[0031] The sample weighting mechanism is introduced in the supervised contrast loss function, and the weight w i of each sample is defined as:

[0032]

[0033] wherein the adjustable parameters λ a and λ b are set as initial values of 1;

[0034] The maximum weight limiting mechanism is introduced to limit the weight value within a reasonable range:

[0035] w′ i = min(w i , w max )

[0036] wherein w′ i represents the weight of the i-th sample after the maximum weight limiting, w max is a hyperparameter for limiting the maximum value of the weight;

[0037] The supervised contrast loss function L sc is specifically:

[0038]

[0039] wherein k and a represent the k-th and a-th samples, i≠k and i≠a, and the i-th sample and the k-th sample have the same label, z i , z k , and z a are respectively the embedding features of the i-th, k-th, and a-th samples; N bN(i) represents the number of positive / negative samples, N(i) is the index set of all positive samples of sample i, and |N(i)| is the number thereof; τ is a preset temperature parameter.

[0040] Further, the pyramid temporal context learning module includes a multi-scale pyramid pooling network and a convolutional network; the embedded features of the samples are first input into the convolutional network to obtain output features; and then the output features are input into the multi-scale pyramid pooling network, the time features output by all layers of the multi-scale pyramid pooling network are cascaded, features containing short-term, medium-term and long-term time scale information are captured respectively, and thus the fusion features with time sequence consistency are formed.

[0041] Further, the fusion features are input into a self-attention mechanism of a classification module, the output of the self-attention mechanism is input into a full connection layer, and the sleep stage classification result corresponding to the samples, i.e. the probability that the samples belong to a certain category predicted by the multi-scale feature contrast representation learning sleep network model, is obtained.

[0042] A terminal device comprises a processor, a memory and a computer program stored in the memory; when the processor executes the computer program, the sleep stage classification method based on multi-scale feature contrast learning is realized.

[0043] A computer readable storage medium, the medium stores a computer program; when the computer program is executed by a processor, the sleep stage classification method based on multi-scale feature contrast learning is realized.

[0044] Compared with the prior art, the present application has the following technical features:

[0045] The present application comprehensively captures the dynamic features of the sleep EEG signal in different time scales by combining contrast representation learning, difficult sample mining and multi-scale pyramid pooling strategy, effectively improves the classification performance of the minority class and the boundary transition stage. The newly added boundary error rate index provides a multi-dimensional evaluation framework for evaluating the prediction accuracy of the model at the stage transition point. Experimental results show that the proposed MFCR-SleepNet performs excellently on multiple public datasets, and the accuracy and robustness are better than those of existing mainstream models, especially in dealing with the boundary ambiguity and class imbalance problem, which shows a significant advantage. BRIEF DESCRIPTION OF DRAWINGS

[0046] Figure 1 It is a general architecture diagram of a multi-scale feature contrast representation learning sleep network model (MFCR-SleepNet).

[0047] Figure 2 It is a detailed structure diagram of a pyramid-based temporal context learning (PTCL) module.

[0048] Figure 3 Figure for network performance comparison of MFCR-SleepNet in an embodiment of the application on three data sets;

[0049] Figure 4 Figure for ablation experiment results of MFCR-SleepNet in an embodiment of the application on the SleepEDF-78 data set;

[0050] Figure 5 Figure for BER comparison of three data sets in an embodiment of the application. DETAILED DESCRIPTION

[0051] The application provides a sleep stage classification method based on multi-scale feature contrast learning, comprising:

[0052] Obtaining an electroencephalogram signal to be classified; preprocessing the electroencephalogram signal to obtain an enhanced EEG signal;

[0053] Inputting the EEG signal into a trained multi-scale feature contrast representation learning sleep network model, and outputting a final classification result by using the model;

[0054] The multi-scale feature contrast representation learning sleep network model comprises a contrast representation learning module, a pyramid temporal context learning module and a classification module connected in sequence, wherein:

[0055] The contrast representation learning module is used to optimize the feature representation of the EEG signal, and the model can automatically extract distinguishing features by using a contrast learning strategy to obtain a contrast learning embedding space; the pyramid temporal context learning module is used to model the dynamic change relationship of the EEG signal at different time scales according to the embedding space, improve the capture ability of the sleep stage transition, and obtain fusion features with time sequence consistency; and the classification module is used to accurately classify the sleep stage based on the fusion features, and finally output the corresponding sleep stage classification result;

[0056] A difficult sample mining unit is arranged in the contrast representation learning module, which is used to mine boundary samples and low classification accuracy samples from a training data set, introduce a sample weighting mechanism in a supervised contrast loss function, set the weight of the sample and limit the range of the weight by a maximum weight limiting mechanism; finally, the network parameters in the contrast representation learning module are optimized by using the supervised contrast loss function.

[0057] 1. Construct a training data set.

[0058] The data set construction process for training the multi-scale feature contrast representation learning sleep network model in the application is as follows:

[0059] Three public sleep datasets, SleepEDF-78, MASS and SHHS, are adopted and standardized pre-processed to ensure the consistency of the training and testing data of the model.

[0060] For the selected sleep datasets, the following standardized pre-processing is adopted:

[0061] The electroencephalogram (EEG) signals in each sleep dataset only retain single-channel EEG signals, removing redundant signals such as EOG and EMG; all EEG signals are resampled to 100Hz to maintain consistency; band-pass filtering (0.3Hz-35Hz) is used to remove low-frequency drift and high-frequency noise in the EEG signals; an artifact removal method is used to reduce the interference of eye movement and muscle artifacts on the EEG signals; according to the AASM standard, N3 and N4 stages are combined, and related EEG signals with incorrect labels are removed.

[0062] After standardized pre-processing, the training dataset is obtained, each sample in the training dataset is a 30s EEG signal, and the label of the EEG signal is the manually labeled sleep stage (W, N1, N2, N3, REM); the length of the EEG signal depends on the sampling rate of the sleep dataset, for example, SleepEDF-78 is 3000 points, MASS is 7680 points, and SHHS is 3000 points.

[0063] 2. Multi-scale feature contrastive representation learning sleep network model (MFCR-SleepNet).

[0064] Referring to the accompanying drawings Figure 1 , the multi-scale feature contrastive representation learning sleep network model provided by the application comprises a contrastive representation learning (CRL) module, a pyramid temporal context learning (PTCL) module and a classification module, wherein:

[0065] 2.1 Contrastive Representation Learning (CRL) Module.

[0066] The contrastive representation learning module is used to optimize the feature representation of the EEG signal, and the model can automatically extract discriminative features through a contrastive learning strategy to obtain sleep stage feature embedding representation.

[0067] The contrastive representation learning module comprises a data augmentation unit, a momentum encoder, a projection network and a difficult sample mining unit, wherein:

[0068] (1) Data Augmentation Unit.

[0069] In the training phase, for a sample s in the training dataset, the sample is augmented to generate a positive sample s p , and a negative sample s q is randomly selected, and the augmented sample is represented as The number of positive samples and negative samples is the same, both N b , i.e. p, q = 1, 2, …, N b .

[0070] The specific data augmentation strategy is as follows:

[0071] Positive sample: generate a positive sample by applying six semantic invariant data augmentation operations (amplitude scaling, time translation, amplitude offset, zero masking, additive Gaussian noise and band stop filtering) to the sample s; the positive sample has the same label as the current sample.

[0072] Negative sample pair: randomly select a sample different from the current sample label from the training data set as a negative sample.

[0073] (2) Momentum encoder.

[0074] The momentum encoder receives the enhanced sample and sequentially passes through a convolutional layer (Conv), a batch normalization layer (BN), an average pooling layer (Avg) and an activation function (ReLU θt ) to learn a complex and abstract feature representation h t . The role of the momentum encoder is to reduce the feature drift problem in the training process, make the feature representation more consistent and robust, and ensure the stability of the features.

[0075] The processing process of the momentum encoder is as follows:

[0076]

[0077] The activation function in the momentum encoder uses ReLU, represented as θ t The learnable parameters of the momentum encoder (including the weights and biases of the convolutional layer, the batch normalization layer and the average pooling layer) are represented as follows:

[0078] θ t+1 = αθ t + (1-α)θ′ t

[0079] θ t+1 is the parameter of the momentum encoder at the next time, θ t is the current time parameter, θ t ' is the updated parameter of the network learning, all of which are trainable parameters; α is the momentum coefficient, used to control the fusion ratio of historical parameters and new parameters, which is set to 0.9 in this embodiment.

[0080] (3) Projection network.

[0081] The projection network is used to project the feature representation ht By mapping to the embedding space of contrastive learning, the corresponding embedding features are obtained in order to calculate the supervised contrastive loss, thereby better implementing the contrastive representation learning strategy.

[0082] Using a single hidden layer dimension d z A multilayer perceptron (MLP) with a resolution of 256 is used as the projection network; the embedded feature z is represented as:

[0083]

[0084] Where z'=P(h t ;w P b P P(·) is the projection network, w P b P These are the weights and biases of the projection network, respectively. It is the space of real numbers.

[0085] The Contrastive Representation Learning (CRL) module utilizes a supervised contrastive loss function for training to optimize network parameters (weights, biases, etc. of each functional layer) in the momentum encoder and projection network. The specific design is as follows:

[0086] (4) Difficult sample mining unit.

[0087] After obtaining the embedded features from the projection network, we first mine the hard samples, and then perform weighted optimization on the hard samples. The selected hard samples mainly include two categories: boundary samples and samples with low classification accuracy.

[0088] The hard sample mining module is used to identify and optimize hard-to-classify samples, especially sleep stage boundary samples and minority class samples, to improve the model's learning ability for these categories. Its input is the embedded features output by the projection network, and its output is the weights w′ required for weighting. i The process is as follows:

[0089] By identifying boundary samples at sleep stage transition points using sample labels, a boundary sample set is constructed, defined as follows:

[0090] Β={i|y true [i]≠y true [i+1]}

[0091] Where B is the boundary sample set, y true [i] is the label of the sleep stage corresponding to the i-th sample; y true [i]≠y true The i-th sample under condition [i+1] is used as the boundary sample.

[0092] Below the threshold θ accuracyThe category of low classification accuracy samples is defined as:

[0093] A = {i|y true [i] = c, p o,c <θ accuracy}

[0094] Where A is the set of samples with low classification accuracy, c represents the category of a specific sleep stage, and p o,c θ represents the probability that the i-th sample belongs to category c, as predicted by the sleep network model after multi-scale feature comparison; in this embodiment, θ accuracy Take 0.7; this will satisfy y true [i] = c, p o,c <θ accuracy Samples with certain conditions are considered low-accuracy samples.

[0095] All samples in the low classification accuracy sample set A and the boundary sample set B are regarded as difficult samples, and the target set for mining difficult samples H = B∪A is constructed.

[0096] To enhance the model's attention to difficult samples, a sample weighting mechanism is introduced into the supervised contrastive loss function, with each sample having a weight w. i Defined as:

[0097]

[0098] Where the adjustable parameter λ a and λ b The initial value is set to 1, and it is dynamically adjusted according to the number of difficult and boundary samples as training progresses. When the contribution of difficult samples to the overall loss is small, λ... a and λ b It will gradually increase in order to enhance the model's attention to these samples.

[0099] To prevent gradient instability due to excessively large weights during model training, a maximum weight limit mechanism is introduced to restrict weight values ​​to a reasonable range.

[0100] w′ i =min(w i ,w max )

[0101] Among them, w′ i w represents the weight of sample i after applying the maximum weight constraint. max is a hyperparameter used to limit the maximum value of the weights; in this embodiment, w is... max Setting it to 3 effectively balances the impact of difficult samples on the loss with the overall training stability of the model.

[0102] (5) Supervised contrastive loss function.

[0103] The embedded features z obtained by passing the samples through a projection network are combined with the sample weights w′. i The input is fed into the supervised contrastive loss function L. sc Specifically:

[0104]

[0105] Where k and a represent the k-th and a-th samples, i ≠ k and i ≠ a, and the i-th and k-th samples have the same label, z i z k z a The embedding features of the i-th, k-th, and a-th samples are respectively; N b The number of positive / negative samples is represented by N(i), which is the set of indices of all positive samples of sample i, and |N(i)| is its number. Since the differences between sleep categories are small, the temperature parameter τ is set to 0.07 in order to enhance the effect of small differences between embedding vectors.

[0106] During network model training, the supervised contrastive loss function described above is used to optimize the network parameters in the momentum encoder and projection network. In this way, the model can focus fully on difficult samples in the early stages of training, and gradually stabilize in the later stages, avoiding over-focusing on certain samples and affecting overall performance. Furthermore, λ... a and λ b The updates were regularized to ensure smoothness during optimization, thus avoiding drastic fluctuations caused by overly rapid updates. This dynamic adjustment mechanism, combined with maximum weight constraints, significantly improves the model's adaptability at different training stages, resulting in marked improvements in classification performance for low-accuracy samples and boundary samples, while maintaining its ability to learn from mainstream samples and the stability of the training process.

[0107] 2.2 Pyramid Temporal Context Learning Module.

[0108] The PTCL module is used to model the dynamic changes of samples at different time scales, improve the ability to capture sleep stage transitions, and obtain more temporally consistent classification features.

[0109] like Figure 2 As shown, the pyramid temporal context learning module includes a multi-scale pyramid pooling network (XSPP) and a convolutional network (CNN); the embedded features z of the sample are first input into the convolutional network to obtain the output features z. out , means as follows:

[0110] z out =PReLU(w c*z+b c )

[0111] Where PReLU is the activation function of the convolutional network, enabling the network to better capture subtle differences in the data; * represents the convolution calculation, w c and b c These are the learnable weights and biases.

[0112] Then output feature z out Input into a multi-scale pyramid pooling network:

[0113] r s =XSPP(z out )

[0114] Where XSPP represents the processing procedure of the multi-scale pyramid pooling network, r s This represents the temporal features obtained after pooling at the s-th layer of the multi-scale pyramid pooling network; it represents the temporal features r1, r2, ..., r output from all layers of the multi-scale pyramid pooling network. s By cascading features to capture information at short, medium, and long time scales, a fused feature x with temporal consistency is formed. concat :

[0115] x concat =concat(r1,r2,...,r s )

[0116] Here, concat represents a cascading operation.

[0117] 2.3 Classification Module.

[0118] The fused feature x, which contains short-term, medium-term, and long-term timescale information, is obtained from the output of the pyramid temporal context learning module. concat Next, the fused feature x concat In the self-attention mechanism of the input classification module; where due to the fusion of features x concat The three types of features contained herein have inconsistent lengths, which can be made consistent by using a padding operation.

[0119] Self-attention mechanisms can compute long-range dependencies in data. By calculating attention scores across different time points, the model can highlight the most critical information and discard unimportant information. Specifically, this is implemented as follows:

[0120]

[0121] Where Q, K, and V are the fusion features x, respectively. concat Queries, keys, and values ​​generated based on three different learnable matrices; d kis the dimension of the key vector, which helps to adjust the dot product size and prevent the gradient of the softmax function from being affected by the excessively large inner product; the superscript T represents transposition.

[0122] The output A of the self-attention mechanism is input into a full connection layer to obtain the sleep stage classification result corresponding to the sample, i.e., the probability p that the sample belongs to the class c predicted by the multi-scale feature contrast representation learning sleep network model o,c .

[0123] 4. Training of the network model.

[0124] During the training of the network model, a cross-entropy loss function is used to calculate the classification accuracy to optimize the network parameters of the entire network model; the cross-entropy loss function is represented as follows:

[0125]

[0126] where C represents the number of classes of sleep stages, y o,c is a binary indicator indicating whether the sample o belongs to the class c; the network model is trained by using a gradient descent algorithm, and the trained network model is saved.

[0127] In actual application, after obtaining an unknown electroencephalogram signal, the electroencephalogram signal is preprocessed to obtain a 30s-length EEG signal, which is then input into the trained multi-scale feature contrast representation learning sleep network model, and finally the classification result of the electroencephalogram signal is output by the network model.

[0128] Embodiment:

[0129] 1. Model training

[0130] 10-fold cross-validation is adopted, the optimizer uses Adam, the initial learning rate is 0.0005, the batch size is 512, and the early stopping strategy is adopted to prevent overfitting. All training processes are carried out in a Python 3.10.2 environment using an Nvidia GeForce GTX3090 GPU.

[0131] 2. Evaluation index

[0132] including accuracy (ACC), macro-average F1 score (MF1), Cohen’s Kappa, and boundary error rate (BER). Among them, BER is a new index proposed by the present application, which is used to comprehensively evaluate the prediction accuracy of the model at the sleep stage transition point.

[0133] In the present application, several common evaluation indexes are adopted to comprehensively evaluate the performance of the model. The accuracy (ACC) is used to measure the ratio of the number of samples correctly predicted by the model to the total number of samples, and the formula is as follows:

[0134]

[0135] where TP, TN, FP, FN represent True Positive, True Negative, False Positive, False Negative, respectively, indicating the number of samples correctly or incorrectly classified during recognition.

[0136] Macro-averaged F1 score (MF1) combines precision and recall, especially suitable for multi-classification tasks in unbalanced datasets, and can comprehensively evaluate the performance of the model, whose formula is:

[0137]

[0138] where, C represents the number of sleep stage categories.

[0139] Cohen's Kappa value is used to measure the consistency between the model's prediction results and the true labels, and corrects the influence brought by random guessing. The F1 score of each category reflects the model's ability to distinguish between categories. Boundary error rate (BER) is a new evaluation index proposed for the characteristics of sleep EEG data, which is used to measure the error between the predicted sleep stage boundary (switching point) and the true label. This index consists of two parts, including the time error of the boundary (TE) and the consistency of the boundary (PC), and the formula of TE is as follows:

[0140]

[0141] where, t true,i is the position of the i-th real boundary, t pre d ,i is the position of the nearest predicted boundary to the real boundary, and N represents the total number of real boundaries. The smaller the boundary error is, the more accurate the model is in positioning the boundary. Normalize TE TE max is the maximum error observation value. The formula of PC is as follows

[0142]

[0143] where, y pred,t is the stage label predicted by the model after the boundary t, and y true,t is the real stage label after the boundary t. Then calculate the mean of PC

[0144] TE and PC avg are weighted and multiplied to get the final comprehensive index BER, and the formula of BER is:

[0145] BER = a · TE norm + b(1 - PC avg )

[0146] where a, b are the corresponding weighting factors, which are set to 0.5, 0.5, respectively. (1 - PC avg ) is the inverse indicator of stage consistency, because we hope better stage consistency can reduce the value of BER. Specifically, the lower the BER, the better the performance of the model in boundary classification.

[0147] 3. Experimental results

[0148] The experimental results show that MFCR-SleepNet outperforms the existing mainstream models on SleepEDF-78, MASS and SHHS datasets, especially in the classification accuracy of N1 stage. t-SNE visualization shows that the model can better distinguish different sleep stages in the feature space, and the boundary error rate (BER) index further verifies the high accuracy of the model at the stage transition point.

[0149] Figure 3 The classification performance of MFCR-SleepNet on SleepEDF-78, MASS, SHHS three datasets is shown, compared with existing models (DeepSleep, SeqSleepNet, XSleepNet, etc.), MFCR-SleepNet achieves the optimal results in ACC (accuracy), MF1 (macro average F1-score), Kappa score, which shows that it has stronger generalization ability. In addition, the classification performance in N1 stage is significantly improved (such as F1-score reaches 61.8% on MASS dataset), which benefits from the CRL module improving the feature discrimination ability of minority class samples, while the F1-score of REM stage is also at the leading level, indicating that the model can effectively identify the key features in the sleep stage.

[0150] Figure 4The influence of different module combinations on the performance of the model is analyzed, wherein EN+AP (using an encoding network and ordinary average pooling), EN+MSP (using an encoding network and pyramid pooling), ME+AP (using a momentum encoder and ordinary average pooling), ME+MSP (using a momentum encoder and pyramid pooling), and ME+MSP+HSM (the method of the application, combining a momentum encoder, pyramid pooling, and difficult sample mining) result in the complete MFCR-SleepNet scheme (ME+MSP+HSM) achieving the optimal ACC, MF1, and Kappa score. In particular, in the N1 stage, the F1-score is improved from 42.5% (EN+AP) to 55.1% (ME+MSP+HSM), proving that the CRL module and the PTCL module effectively improve the recognition ability of difficult classes. In addition, MSP (multi-scale pooling) enhances the classification performance of the N3 and REM stages, and HSM (difficult sample mining) optimizes the learning of boundary samples, further improving the classification stability.

[0151] Figure 5 The boundary error rate (BER) of different methods on the SleepEDF-78, MASS, and SHHS data sets is shown, and the results show that MFCR-SleepNet achieves the lowest BER on all data sets (for example, the BER is reduced to 0.1932 on the MASS data set, lower than XSleepNet, SeqSleepNet, and other methods), indicating that it has a lower misclassification rate at the transition points of sleep stages and improves the recognition ability of stage transition samples. The low BER is attributed to the CRL supervised contrastive learning, which optimizes the feature expression of boundary samples, and the PTCL time context modeling, which enhances the model's capture of long and short time dependencies, making the classification of transition regions more stable and accurate.

[0152] The characteristics and advantages of the scheme are as follows:

[0153] Higher overall classification performance: MFCR-SleepNet has better ACC, MF1, and Kappa scores on the SleepEDF-78, MASS, and SHHS data sets than existing mainstream models, proving that it has stronger generalization ability and can maintain high performance on different data sets.

[0154] Significant improvement in N1 stage classification performance: Traditional models perform poorly in the N1 stage, but the F1-score of the scheme is improved to 61.8% on the MASS data set and leads in the SleepEDF-78 and SHHS data sets. The CRL module optimizes the feature representation of minority class samples, improving the recognition ability of the N1 stage.

[0155] Lower boundary error rate (BER) and improved stage transition recognition: The experimental results show that the BER of the present scheme on all data sets is significantly lower than that of existing methods, such as the BER on the MASS data set is only 0.1932, which is significantly lower than that of XSleepNet (0.2413) and SeqSleepNet (0.2789). This is due to the fact that CRL supervised contrastive learning optimizes the feature expression of boundary samples, and PTCL time context modeling improves the stability of sleep stage transition.

[0156] Effective use of time context information and improved classification stability: The PTCL module combines convolution pyramid pooling (XSPP-CNN) and self-attention mechanism, which can capture short-term, medium-term and long-term dependencies at the same time, so that the model can more accurately distinguish adjacent sleep stages and reduce misclassification.

[0157] Suitable for single-channel EEG and enhanced wearable device applicability: The present scheme mainly uses single-channel EEG, but outperforms many multi-channel EEG methods in classification performance, indicating its strong robustness and practical application value, especially suitable for low-cost EEG acquisition scenarios such as wearable devices and mobile monitoring systems.

[0158] The present scheme combines supervised contrastive learning (CRL) and time context modeling (PTCL), and has significant advantages in overall classification performance, minority class sample recognition, stage transition point classification, time series modeling, and single-channel EEG adaptability, providing an efficient and stable deep learning solution for sleep stage classification tasks.

[0159] The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or make equivalent replacements for some technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be included in the protection scope of the present application.

Claims

1. A sleep stage classification method based on multi-scale feature contrastive learning, characterized in that, include: Acquire EEG signals to be classified; The EEG signal is preprocessed to obtain an enhanced EEG signal; The EEG signal is input into a trained multi-scale feature contrast representation learning sleep network model, and the model is used to output the final classification result. The multi-scale feature contrastive representation learning sleep network model includes a contrastive representation learning module, a pyramid temporal context learning module, and a classification module connected in sequence, wherein: The contrastive representation learning module is used to optimize the feature representation of EEG signals and obtains the contrastive learning embedding features through a contrastive learning strategy; the pyramid temporal context learning module is used to model the dynamic changes of EEG signals at different time scales based on the embedding features and obtain fusion features with temporal consistency; the classification module classifies sleep stages based on the fusion features and finally outputs the corresponding sleep stage classification results. The contrastive representation learning module includes a hard sample mining unit, which is used to mine boundary samples and low classification accuracy samples from the training dataset. A sample weighting mechanism is introduced into the supervised contrastive loss function, and the weights of the samples are set and the range of the weights is limited by a maximum weight limit mechanism. Finally, the network parameters in the contrastive representation learning module are optimized through the supervised contrastive loss function.

2. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, When constructing the training dataset, only single-channel EEG signals were retained from the acquired EEG signals. All EEG signals were resampled to a preset frequency, and bandpass filtering was used to remove low-frequency drift and high-frequency noise from the EEG signals. Artifact removal methods were used to reduce the interference of eye movement and muscle artifacts on the EEG signals. According to the AASM standard, N3 and N4 stages are merged, and related EEG signals with incorrect labels are removed; a preset length is truncated for each EEG signal as a sample, and the label of the EEG signal is the corresponding sleep stage.

3. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The contrastive representation learning module includes a data augmentation unit, a momentum encoder, and a projection network. In the data augmentation unit, the input samples are augmented using data augmentation strategies to generate corresponding positive and negative samples; The sample and its corresponding positive and negative samples are used together as the enhanced sample; The enhanced samples are input into the momentum encoder and pass through convolutional layers, batch normalization layers, average pooling layers and activation functions in sequence to learn complex and abstract feature representations; The projection network is used to map the feature representations extracted by the momentum encoder to the embedding space of the contrastive learning to obtain the corresponding embedding features; The multilayer perceptron (MLP) with a single hidden layer is used as the projection network.

4. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The embedded feature z is represented as: Where z'=P(h t ;w P b P ), h t To represent the features extracted by the momentum encoder, P(·) is the projection network, w P b P These are the weights and biases of the projection network, respectively. It is the space of real numbers.

5. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The contrastive representation learning module includes a hard sample mining unit, which is used to mine boundary samples and low classification accuracy samples from the training dataset. Specifically: By identifying boundary samples at sleep stage transition points using sample labels, a boundary sample set is constructed, defined as follows: Β={i|y true [i]≠y true [i+1]} Where B is the boundary sample set, y true [i] is the label of the sleep stage corresponding to the i-th sample; y true [i]≠y true The i-th sample under condition [i+1] is used as the boundary sample; Below the threshold θ accuracy The category of low classification accuracy samples is defined as: A={i|y true [i]=c,p o,c <θ accuracy } Where A is the set of samples with low classification accuracy, c represents the category of a sleep stage, and p o,c This represents the probability that the i-th sample belongs to category c, as predicted by the sleep network model after multi-scale feature comparison; y true [i] = c, p o,c <θ accuracy Samples with certain conditions are considered low-accuracy samples.

6. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The method of introducing a sample weighting mechanism into the supervised contrastive loss function, setting sample weights and limiting the range of weights through a maximum weight limit mechanism, includes: A sample weighting mechanism is introduced into the supervised contrastive loss function, where each sample has a weight w. i Defined as: Where the adjustable parameter λ a and λ b Set the initial value to 1; A maximum weight limit mechanism is introduced to restrict the weight values ​​to a reasonable range: In i ′=min(in i ,In max ) Among them, w i ′ represents the weight of sample i after applying the maximum weight constraint, w max It is a hyperparameter used to limit the maximum value of the weights; Supervised contrastive loss function L sc Specifically: Where k and a represent the k-th and a-th samples, i ≠ k and i ≠ a, and the i-th and k-th samples have the same label, z i z k z a The embedding features of the i-th, k-th, and a-th samples are respectively; N b The number of positive / negative samples is represented by N(i), which is the set of indices of all positive samples of sample i, and |N(i)| is its number; τ is the preset temperature parameter.

7. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The pyramid temporal context learning module includes a multi-scale pyramid pooling network and a convolutional network. The embedded features of the samples are first input into the convolutional network to obtain the output features. Then, the output features are input into the multi-scale pyramid pooling network, and the temporal features output by all layers of the multi-scale pyramid pooling network are concatenated to capture features containing short-term, medium-term and long-term temporal scale information, thereby forming a fusion feature with temporal consistency.

8. The sleep stage classification method based on multi-scale feature contrast learning according to claim 1, characterized in that, The fused features are input into the self-attention mechanism of the classification module, and the output of the self-attention mechanism is input into the fully connected layer to obtain the sleep stage classification result corresponding to the sample. That is, the probability of the sample belonging to a certain category is predicted by the sleep network model after learning the multi-scale feature contrast representation.

9. A terminal device, comprising a processor, a memory, and a computer program stored in the memory; characterized in that, When the processor executes the computer program, it implements the sleep stage classification method based on multi-scale feature contrast learning as described in any one of claims 1-8.

10. A computer-readable storage medium storing a computer program; characterized in that, When the computer program is executed by the processor, it implements the sleep stage classification method based on multi-scale feature contrast learning as described in any one of claims 1-8.

Citation Information

Patent Citations

  • Motor imagery electroencephalogram signal classification method based on frequency domain convolutional neural network

    CN113476056A

  • Automatic sleep staging method and system

    CN119312143A