Movatterモバイル変換


[0]ホーム

URL:


CN116509421A - Automatic Sleep Staging Method Based on Window Attention Mechanism - Google Patents

Automatic Sleep Staging Method Based on Window Attention Mechanism
Download PDF

Info

Publication number
CN116509421A
CN116509421ACN202310509949.3ACN202310509949ACN116509421ACN 116509421 ACN116509421 ACN 116509421ACN 202310509949 ACN202310509949 ACN 202310509949ACN 116509421 ACN116509421 ACN 116509421A
Authority
CN
China
Prior art keywords
feature
output
input
frequency
window
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310509949.3A
Other languages
Chinese (zh)
Inventor
石争浩
宋远帆
尤珍臻
任晓勇
黑新宏
刘海琴
罗靖
赵明华
冯亚宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xian University of Technology
Original Assignee
Xian University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xian University of TechnologyfiledCriticalXian University of Technology
Priority to CN202310509949.3ApriorityCriticalpatent/CN116509421A/en
Publication of CN116509421ApublicationCriticalpatent/CN116509421A/en
Pendinglegal-statusCriticalCurrent

Links

Classifications

Landscapes

Abstract

Translated fromChinese

本发明公开了一种基于窗口注意力机制的自动睡眠分期方法,网络包括特征提取模块、特征提炼模块、时序捕获模块和分类器。首先,通过不同的卷积核大小所构成的双路卷积神经网络,实现了对于原始脑电信号高低频的浅层特征提取,并通过堆叠多层卷积层实现深层特征提取;然后,通过由降维和通道注意力机制组成的特征提炼模块,降低了输出特征通道的个数,并尽可能保留了关键的特征通道;最后,通过基于窗口注意力机制实现的时序捕获模块,实现了对于序列信息的有效处理,模型更加聚焦于窗口内的特征通道;同时,在窗口注意力的权重分配中引入了医生判读的经验知识,从而最终实现了更加准确的分类结果。

The invention discloses an automatic sleep staging method based on a window attention mechanism. The network includes a feature extraction module, a feature extraction module, a timing capture module and a classifier. First, through the two-way convolutional neural network composed of different convolution kernel sizes, the shallow feature extraction of the high and low frequencies of the original EEG signal is realized, and the deep feature extraction is realized by stacking multiple convolutional layers; then, by The feature extraction module composed of dimensionality reduction and channel attention mechanism reduces the number of output feature channels and retains key feature channels as much as possible; finally, through the timing capture module based on the window attention mechanism, it realizes the sequence With the effective processing of information, the model focuses more on the feature channels in the window; at the same time, the empirical knowledge of the doctor's interpretation is introduced into the weight distribution of the window attention, thus finally achieving a more accurate classification result.

Description

Translated fromChinese
基于窗口注意力机制的自动睡眠分期方法Automatic Sleep Staging Method Based on Window Attention Mechanism

技术领域technical field

本发明属于生理信号处理技术领域,涉及一种基于窗口注意力机制的自动睡眠分期方法。The invention belongs to the technical field of physiological signal processing and relates to an automatic sleep staging method based on a window attention mechanism.

背景技术Background technique

睡眠是一项占据人类生活几乎三分之一的重要生理活动,对于机体复原和大脑机能恢复等其他生理活动具有重要的影响。研究显示,比起睡眠质量较差的人群,具有良好睡眠质量的群体拥有更加健康的身体状态。睡眠不足轻则影响人们的体力、心态等,影响正常的工作和生活;重则危害人体健康,增高各种疾病的患病概率。Sleep is an important physiological activity that occupies almost one-third of human life, and it has an important impact on other physiological activities such as body recovery and brain function recovery. Studies have shown that people with good sleep quality are healthier than those with poor sleep quality. Insufficient sleep affects people's physical strength, mentality, etc., and affects normal work and life; in severe cases, it endangers human health and increases the probability of various diseases.

睡眠医学通过基于生理信号的睡眠监测来获得人体在睡眠中的状态和变化,进而对睡眠质量进行评价。而进行睡眠质量评估的首要任务就是对采集到的数据进行睡眠阶段的划分,常用的生理信号包括脑电信号、心电信号和肌电信号等等。其中,脑电信号(EEG)对人体在睡眠状态下的大脑神经活动进行了记录,且其在不同的睡眠状态下会呈现不同的特点。但由于脑电信号的判别需要具有一定程度经验的医师完成,导致其存在成本高和耗时长等缺点。因此,提出一种基于脑电信号的自动睡眠分期算法十分有必要。Sleep medicine obtains the state and changes of the human body during sleep through sleep monitoring based on physiological signals, and then evaluates sleep quality. The primary task of sleep quality assessment is to divide the collected data into sleep stages. Commonly used physiological signals include EEG signals, ECG signals, and EMG signals. Among them, the electroencephalogram signal (EEG) records the brain nerve activity of the human body in the sleep state, and it will show different characteristics in different sleep states. However, since the identification of EEG signals needs to be completed by a physician with a certain degree of experience, it has disadvantages such as high cost and time-consuming. Therefore, it is necessary to propose an automatic sleep staging algorithm based on EEG signals.

发明内容Contents of the invention

本发明的目的是提供一种基于窗口注意力机制的自动睡眠分期方法,该方法将睡眠周期特点和自注意力机制相结合,能够获得准确的睡眠分期结果。The purpose of the present invention is to provide an automatic sleep staging method based on a window attention mechanism, which combines the sleep cycle characteristics with the self-attention mechanism, and can obtain accurate sleep staging results.

本发明所采用的技术方案是,基于窗口注意力机制的自动睡眠分期方法,具体包括如下步骤:The technical scheme adopted in the present invention is an automatic sleep staging method based on the window attention mechanism, which specifically includes the following steps:

步骤1,获取含睡眠分期标注的EEG信号数据集,将数据集按照个体划分为训练集和测试集;Step 1. Obtain the EEG signal data set marked with sleep stages, and divide the data set into training set and test set according to individuals;

步骤2,对步骤1所得的训练集和测试集进行预处理;Step 2, preprocessing the training set and test set obtained in step 1;

步骤3,构建针对EEG信号的自动睡眠分期模型;Step 3, constructing an automatic sleep staging model for EEG signals;

步骤4,采用步骤1中的训练集对步骤2中构建的网络模型进行训练,得到最优的自动睡眠分期模型;Step 4, using the training set in step 1 to train the network model constructed in step 2 to obtain the optimal automatic sleep staging model;

步骤5,将步骤2中的测试集放入步骤3训练好的自动睡眠分期模型中,输出睡眠分期结果。Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging results.

本发明的特点还在于:The present invention is also characterized in that:

步骤2的具体过程为:The specific process of step 2 is:

将数据集中所有个体的记录文件中包含的脑电信号按照30s为一帧进行划分,并与标记文件的标签数据建立对应关系;然后按照序列长度将多个信号帧及其对应标签进行合并;最终得到序列格式的样本集合。Divide the EEG signals contained in the record files of all individuals in the data set according to 30s as a frame, and establish a corresponding relationship with the label data of the label file; then merge multiple signal frames and their corresponding labels according to the sequence length; finally Get a collection of samples in sequence format.

步骤3中,自动睡眠分期模型包括:In step 3, the automatic sleep staging model includes:

特征编码模块:采用双分支设计思路,分别提取信号中的低频和高频信息,并通过堆叠多层实现深度特征提取;Feature encoding module: adopts the dual-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realize deep feature extraction by stacking multiple layers;

特征提炼模块:实现在减小特征通道的同时保留关键特征信息不被丢弃;Feature extraction module: realize that the key feature information is not discarded while reducing the feature channel;

时序捕获模块:结合睡眠分期任务的特点,采用基于窗口注意力机制的Transformer实现对于输入信号中序列信息的处理;Timing capture module: Combined with the characteristics of the sleep staging task, the Transformer based on the window attention mechanism is used to process the sequence information in the input signal;

分类器:将输出特征映射为类别分布,实现最终的睡眠分期。Classifier: Map the output features to a class distribution to achieve the final sleep stage.

步骤3中,特征提取模块的具体操作为:In step 3, the specific operation of the feature extraction module is as follows:

步骤a.将训练集中的序列信号经过一个卷积层输出高频浅层特征同时,再经过一个卷积层输出低频浅层特征/>Step a. Pass the sequence signal in the training set through a convolutional layer to output high-frequency shallow features At the same time, output low-frequency shallow features through a convolutional layer/>

步骤b.将高频浅层特征输入到最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到最大池化层,输出低频浅层特征/>Step b. Combine high-frequency shallow features Input to the maximum pooling layer, output high-frequency shallow features /> Low-frequency shallow features /> Input to the maximum pooling layer, output low-frequency shallow features/>

步骤c.将高频浅层特征输入到两层卷积层组成的卷积块CB1,输出高频深层特征/>将低频浅层特征/>输入到两层卷积层组成的卷积块CB2,输出低频深层特征Step c. Combine high-frequency shallow features Input to the convolutional block CB1 composed of two convolutional layers, and output high-frequency deep features/> Low-frequency shallow features /> Input to the convolutional block CB2 composed of two convolutional layers, and output low-frequency deep features

步骤d.将高频深层特征输入最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到最大池化层,输出低频深层特征/>Step d. Combine high-frequency deep features Input max pooling layer, output high frequency shallow features/> Low-frequency shallow features /> Input to the maximum pooling layer, output low-frequency deep features/>

步骤f.将高频浅层特征和低频深层特征/>进行通道连接得到组合特征O5Step f. Combine high-frequency shallow features and low-frequency deep features/> The channel connection is performed to obtain the combined feature O5 .

步骤3中,特征提炼模块的具体操作为:In step 3, the specific operation of the feature extraction module is as follows:

步骤g.将组合特征O5输入到两层卷积块CB3,输出特征O6,卷积层的激活函数为ReLU;Step g. Input the combined feature O5 into the two-layer convolutional block CB3 , output the feature O6 , and the activation function of the convolutional layer is ReLU;

步骤h.将特征O6输入到由平均池化层和两层线性层组成的通道注意力CA中,两层线性层的激活函数分别为ReLU和Sigmoid,输出特征O7Step h. Input the feature O6 into the channel attention CA composed of an average pooling layer and two linear layers, the activation functions of the two linear layers are respectively ReLU and Sigmoid, and output the feature O7 ;

步骤i.将特征O7按照特征尺寸复制之后与特征O6相乘,输出特征O8Step i. After copying the feature O7 according to the feature size, multiplying the feature O6 to output the feature O8 ;

步骤j.将组合特征O5输入到卷积层,输出特征O9Step j. Input the combined feature O5 into the convolutional layer, and output the feature O9 ;

步骤l.将特征O8和特征O9相加,输出特征O10Step 1. Add feature O8 and feature O9 to output feature O10 .

步骤3中,时序模块的具体操作为:In step 3, the specific operation of the timing module is as follows:

步骤m.将特征O10输入层归一化中,输出特征O11Step m. Input feature O10 into layer normalization, and output feature O11 ;

步骤n.将特征O11输入三个不同的线性层中,输出特征Query、Key、Value,将特征Query和转置后Key特征相乘并归一化后,得到注意力矩阵n1Step n. Input the feature O11 into three different linear layers, output the features Query, Key, and Value, multiply and normalize the feature Query and the transposed Key feature, and obtain the attention matrix n1 ;

步骤o.设定窗口掩码mask;将不同特征通道分为三个等级,对于不同重要程度的特征通道,通过对其赋予不同的权重而使其注意力分数更高,同一帧内的特征通道对应权重相同;假定当前帧为的序号为i,设定窗口大小为3,则其窗口范围则为[i-1,i,i+1];第i帧的权重最大,i-1帧和i+1帧的权重次之,其余帧的权重最低;然后,将注意力矩阵n1与掩码mask相乘,得到新的注意力矩阵n2Step o. Set the window mask mask; divide different feature channels into three levels, and assign different weights to the feature channels of different importance to make the attention score higher. The feature channels in the same frame The corresponding weights are the same; assuming that the serial number of the current frame is i, and the window size is set to 3, the window range is [i-1, i, i+1]; the weight of the i-th frame is the largest, and the i-1 frame and The weight of the i+1 frame is next, and the weight of the remaining frames is the lowest; then, the attention matrix n1 is multiplied by the mask mask to obtain a new attention matrix n2 ;

步骤p.将新的注意力矩阵n2与特征Value相乘,输出特征O12Step p. Multiply the new attention matrix n2 with the feature Value, and output the feature O12 ;

步骤q.将特征O12输入线性层中,同时,与特征O10下采样后相加构成残差连接,输出特征O13Step q. Input the feature O12 into the linear layer, and at the same time, add it to the feature O10 after downsampling to form a residual connection, and output the feature O13 ;

步骤r.将特征O13输入层归一化中,输出特征O14Step r. Input feature O13 into layer normalization, and output feature O14 ;

步骤s.将特征O14输入由两层线性层组成的前馈神经网络FF中,同时,与特征O13相加构成残差连接,输出特征O15Step s. Input the feature O14 into the feed-forward neural network FF composed of two linear layers, and at the same time, add it to the feature O13 to form a residual connection, and output the feature O15 .

步骤3中,分类器的具体操作为:In step 3, the specific operation of the classifier is as follows:

步骤t.将特征O15输入线性层中,并通过Softmax函数得到模型预测的概率分布,取值最高值即为对应睡眠帧的分期结果。Step t. Input the feature O15 into the linear layer, and obtain the probability distribution predicted by the model through the Softmax function, and the highest value is the staging result of the corresponding sleep frame.

步骤4中,训练过程中采用多分类交叉熵作为损失函数,分类器通过Softmax函数将特征转化为归一化的概率分布,输出特征维度与类别数保持一致,表示为同时,将标签所指定的睡眠阶段转为one-hot编码的向量以表示目标概率分布,表示为yi,n代表样本个数,K代表类别个数,具体表示为:In step 4, the multi-category cross-entropy is used as the loss function during the training process, and the classifier converts the feature into a normalized probability distribution through the Softmax function, and the output feature dimension is consistent with the number of categories, expressed as At the same time, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, expressed as yi , n represents the number of samples, and K represents the number of categories, specifically expressed as:

本发明的有益效果是,本发明提出的基于窗口注意力机制的自动睡眠分期方法,首先,通过不同的卷积核大小所构成的双路卷积神经网络,实现了对于原始脑电信号高低频的浅层特征提取,并通过堆叠多层卷积层实现深层特征提取;然后,通过由降维和通道注意力机制组成的特征提炼模块,降低了输出特征通道的个数,并尽可能保留了关键的特征通道;最后,通过基于窗口注意力机制实现的时序捕获模块,实现了对于序列信息的有效处理,模型更加聚焦于窗口内的特征通道;同时,在窗口注意力的权重分配中引入了医生判读的经验知识,从而最终实现了更加准确的分类结果。The beneficial effect of the present invention is that the automatic sleep staging method based on the window attention mechanism proposed by the present invention, first of all, through the two-way convolutional neural network composed of different convolution kernel sizes, the high and low frequency of the original EEG signal is realized. The shallow feature extraction, and achieve deep feature extraction by stacking multiple convolutional layers; then, through the feature extraction module composed of dimensionality reduction and channel attention mechanism, the number of output feature channels is reduced, and the key features are retained as much as possible. The feature channel of the window; finally, through the timing capture module based on the window attention mechanism, the effective processing of sequence information is realized, and the model focuses more on the feature channel in the window; at the same time, the doctor is introduced in the weight distribution of the window attention Interpretation of empirical knowledge, which ultimately achieves more accurate classification results.

附图说明Description of drawings

图1是本发明基于窗口注意力机制的自动睡眠分期方法的流程图;Fig. 1 is the flowchart of the automatic sleep staging method based on window attention mechanism of the present invention;

图2是本发明基于窗口注意力机制的自动睡眠分期方法中特征提取模块的结构示意图;Fig. 2 is the structural representation of feature extraction module in the automatic sleep staging method based on window attention mechanism of the present invention;

图3是本发明基于窗口注意力机制的自动睡眠分期方法中特征提炼模块的结构示意图;Fig. 3 is the structural representation of feature extraction module in the automatic sleep staging method based on window attention mechanism of the present invention;

图4是本发明基于窗口注意力机制的自动睡眠分期方法中时序捕获模块的结构示意图;Fig. 4 is the structure schematic diagram of the timing capture module in the automatic sleep staging method based on the window attention mechanism of the present invention;

图5是本发明基于窗口注意力机制的自动睡眠分期方法中时序捕获模块中窗口掩码的示意图。Fig. 5 is a schematic diagram of the window mask in the timing capture module in the automatic sleep staging method based on the window attention mechanism of the present invention.

具体实施方式Detailed ways

下面结合附图和具体实施方式对本发明进行详细说明。The present invention will be described in detail below in conjunction with the accompanying drawings and specific embodiments.

本发明基于窗口注意力机制的自动睡眠分期方法,如图1所示,包括以下步骤:The present invention is based on the automatic sleep staging method of window attention mechanism, as shown in Figure 1, comprises the following steps:

步骤1,获取含睡眠分期标注的EEG信号数据集,该数据集包括被试者的记录文件和医生的标记文件,将数据集按照个体划分为训练集和测试集;Step 1. Obtain the EEG signal data set marked with sleep stages, the data set includes the record file of the subject and the mark file of the doctor, and divide the data set into a training set and a test set according to the individual;

步骤2,对步骤1所得的训练集和测试集进行预处理;具体过程为:将数据集中所有个体的记录文件中包含的脑电信号按照30s为一帧进行划分,并与标记文件的标签数据建立对应关系;然后按照序列长度将多个信号帧及其对应标签进行合并;最终得到序列格式的样本集合。Step 2, preprocess the training set and test set obtained in step 1; the specific process is: divide the EEG signals contained in the record files of all individuals in the data set according to 30s as a frame, and combine them with the label data of the label file Establish a corresponding relationship; then combine multiple signal frames and their corresponding labels according to the sequence length; finally obtain a sample set in sequence format.

步骤3,构建针对EEG信号的自动睡眠分期模型,自动睡眠分期模型包括:Step 3, build an automatic sleep staging model for EEG signals, the automatic sleep staging model includes:

特征编码模块:采用双分支设计思路,分别提取信号中的低频和高频信息,并通过堆叠多层实现深度特征提取,如图2所示;具体操作如下:Feature encoding module: adopts the dual-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realize deep feature extraction by stacking multiple layers, as shown in Figure 2; the specific operation is as follows:

a.将训练集中的序列信号经过一个卷积核大小为50、步长为6、填充为24的卷积层输出高频浅层特征同时,经过一个卷积核大小为400、步长为50、填充为200的卷积层输出低频浅层特征/>卷积层包括一维卷积操作、批归一化和激活函数GELU;a. Pass the sequence signal in the training set through a convolution layer with a convolution kernel size of 50, a step size of 6, and a padding of 24 to output high-frequency shallow features At the same time, a convolution layer with a convolution kernel size of 400, a step size of 50, and a padding of 200 outputs low-frequency shallow features/> The convolution layer includes one-dimensional convolution operation, batch normalization and activation function GELU;

b.将高频浅层特征输入到大小为8、步长为2、填充为4的最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到大小为4、步长为2、填充为2的最大池化层,输出低频浅层特征/>b. Combine high-frequency shallow features Input to a max pooling layer of size 8, stride 2, padding 4, output high frequency shallow features/> Low-frequency shallow features /> Input to a max pooling layer of size 4, stride 2, padding 2, output low frequency shallow features/>

c.将高频浅层特征输入到卷积核大小为8、步长为1、填充为4的两层卷积层组成的卷积块CB1,输出高频深层特征/>将低频浅层特征/>输入到卷积核大小为7、步长为1、填充为3的两层卷积层组成的卷积块CB2,输出低频深层特征/>c. Combine high-frequency shallow features Input to the convolution block CB1 composed of two convolutional layers with a convolution kernel size of 8, a step size of 1, and a padding of 4, and output high-frequency deep features/> Low-frequency shallow features /> Input to the convolution block CB2 composed of two convolutional layers with a convolution kernel size of 7, a step size of 1, and a padding of 3, and output low-frequency deep features/>

d.将高频深层特征输入到大小为4、步长为4、填充为2的最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到大小为2、步长为2、填充为1的最大池化层,输出低频深层特征/>d. Combine high-frequency deep features Input to a max pooling layer of size 4, stride 4, padding 2, output high frequency shallow features/> Low-frequency shallow features /> Input to a max pooling layer of size 2, stride 2, padding 1, output low frequency deep features/>

f.将高频浅层特征和低频深层特征/>进行通道连接得到组合特征O5f. Combine high-frequency shallow features and low-frequency deep features/> Perform channel connection to obtain combined feature O5 ;

特征提炼模块:实现在减小特征通道的同时保留关键特征信息不被丢弃,如图3所示;具体操作如下:Feature extraction module: Realize that the key feature information is not discarded while reducing the feature channel, as shown in Figure 3; the specific operation is as follows:

g.将组合特征O5输入到卷积核大小为1、步长为1、填充为0的两层卷积块CB3,输出特征O6,卷积层的激活函数为ReLU;g. Input the combined feature O5 to the two-layer convolution block CB3 with a convolution kernel size of 1, a step size of 1, and a padding of 0, output feature O6 , and the activation function of the convolution layer is ReLU;

O6=CB3(O5) (10);O6 =CB3 (O5 ) (10);

h.将特征O6输入到由平均池化层和两层线性层组成的通道注意力CA中,两层线性层的激活函数分别为ReLU和Sigmoid,输出特征O7h. Input the feature O6 into the channel attention CA composed of an average pooling layer and two linear layers, the activation functions of the two linear layers are ReLU and Sigmoid respectively, and the output feature O7 ;

O7=Sigmoid(FC2(ReLU(FC1(O6)))) (11);O7 =Sigmoid(FC2 (ReLU(FC1 (O6 )))) (11);

i.将特征O7按照特征尺寸复制之后与特征O6相乘,输出特征O8;O8=O6*Duplicate(O7) (12);i. Copy the feature O7 according to the feature size and multiply it with the feature O6 to output the feature O8 ; O8 =O6 *Duplicate(O7 ) (12);

j.将组合特征O5输入到卷积核大小为1、步长为1、填充为0的卷积层,输出特征O9j. Input the combined feature O5 to the convolution layer with a convolution kernel size of 1, a step size of 1, and a padding of 0, and output feature O9 ;

O9=Conv1(O5) (13);O9 = Conv1 (O5 ) (13);

l.将特征O8和特征O9相加,输出特征O10l. Add feature O8 and feature O9 , output feature O10 ;

O10=O8+O9 (14);O10 =O8 +O9 (14);

时序捕获模块:结合睡眠分期任务的特点,采用基于窗口注意力机制的Transformer实现对于输入信号中序列信息的处理,如图4所示;具体操作如下:Timing capture module: Combined with the characteristics of the sleep staging task, the Transformer based on the window attention mechanism is used to process the sequence information in the input signal, as shown in Figure 4; the specific operations are as follows:

m.将特征O10输入层归一化中,输出特征O11m. During the normalization of the feature O10 input layer, the output feature O11 ;

O11=LayerNorm(O10) (15);O11 =LayerNorm(O10 )(15);

n.将特征O11输入三个不同的线性层中,输出特征Query、Key、Value,将特征Query和转置后Key特征相乘并归一化后,得到注意力矩阵m1n. Input the feature O11 into three different linear layers, output the features Query, Key, and Value, multiply and normalize the feature Query and the transposed Key feature, and obtain the attention matrix m1 ;

Query=FC3(O11) (16);Query = FC3 (O11 ) (16);

Key=FC4(O11) (17);Key = FC4 (011 ) (17);

Value=FC5(O11) (18);Value=FC5 (O11 ) (18);

m1=softmax(Query*KeyT) (19);m1 =softmax(Query*KeyT ) (19);

o.设定窗口掩码mask,如图5所示;将不同特征通道分为三个等级,对于不同重要程度的特征通道,通过对其赋予不同的权重而使其注意力分数更高,同一帧内的特征通道对应权重相同;假定当前帧为的序号为i,设定窗口大小为3,则其窗口范围则为[i-1,i,i+1];第i帧的权重最大,i-1帧和i+1帧的权重次之,其余帧的权重最低;然后,将注意力矩阵m1与掩码mask相乘,得到新的注意力矩阵m2o. Set the window mask mask, as shown in Figure 5; divide different feature channels into three levels, and assign different weights to the feature channels of different importance to make the attention score higher, the same The corresponding weights of the feature channels in the frame are the same; assuming that the serial number of the current frame is i, and the window size is set to 3, the window range is [i-1, i, i+1]; the i-th frame has the largest weight, The weight of i-1 frame and i+1 frame is next, and the weight of other frames is the lowest; then, the attention matrix m1 is multiplied by the mask mask to obtain a new attention matrix m2 ;

m2=m1*mask (20);m2 =m1 *mask(20);

p.将新的注意力矩阵m2与特征Value相乘,输出特征O12p. Multiply the new attention matrix m2 with the feature Value, and output the feature O12 ;

O12=m2*Value (21);O12 = m2 *Value (21);

q.将特征O12输入线性层中,同时,将其与特征O10下采样后相加构成残差连接,输出特征O13q. Input the feature O12 into the linear layer, and at the same time, add it to the feature O10 after downsampling to form a residual connection, and output the feature O13 ;

O13=FC6(O13)+DownSampling(O10) (22);O13 =FC6 (O13 )+DownSampling(O10 ) (22);

r.将特征O13输入层归一化中,输出特征O14r. In normalizing the input layer of feature O13 , output feature O14 ;

O14=LayerNorm(O13) (23);O14 =LayerNorm(O13 )(23);

s.将特征O14输入由两层线性层组成的前馈神经网络FF中,同时,将其与特征相加O13构成残差连接,输出特征O15s. Input the feature O14 into the feed-forward neural network FF composed of two linear layers, and at the same time, add it to the feature O13 to form a residual connection, and output the feature O15 ;

O15=FeedForward(O14)+O13 (24);O15 =FeedForward(O14 )+O13 (24);

分类器:将输出特征映射为类别分布,实现最终的睡眠分期;具体操作如下:Classifier: Map the output features to a category distribution to achieve the final sleep stage; the specific operations are as follows:

t.将特征O15输入线性层中,并通过Softmax函数得到模型预测的概率分布,取值最高值即为对应睡眠帧的分期结果。t. Input the feature O15 into the linear layer, and obtain the probability distribution predicted by the model through the Softmax function, and the highest value is the staging result of the corresponding sleep frame.

Output=Sofmax(FC7(O15)) (25);Output=Sofmax(FC7 (O15 )) (25);

步骤4,采用步骤1中的训练集对步骤2中构建的网络模型进行训练,得到最优的自动睡眠分期模型。分类器通过Softmax函数将特征转化为归一化的概率分布,其输出特征维度与类别数保持一致,表示为同时,将标签所指定的睡眠阶段转为one-hot编码的向量以表示目标概率分布,表示为yi。n代表样本个数,K代表类别个数。具体表示为:Step 4, using the training set in step 1 to train the network model constructed in step 2 to obtain the optimal automatic sleep staging model. The classifier transforms the feature into a normalized probability distribution through the Softmax function, and its output feature dimension is consistent with the number of categories, expressed as At the same time, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, denoted as yi . n represents the number of samples, and K represents the number of categories. Specifically expressed as:

步骤5,将步骤2中的测试集放入步骤3训练好的自动睡眠分期模型中,输出睡眠分期结果。为说明本发明设计的有效性,采用公开数据集Sleep-EDF作为目标数据集,将本发明所提出的方法与目前公开论文中的方法进行了对比,对比结果如下表1所示,可以看出本发明在各项评价指标中均取得了优异的性能表现。Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging results. In order to illustrate the effectiveness of the design of the present invention, the public data set Sleep-EDF is used as the target data set, and the method proposed in the present invention is compared with the method in the current public paper. The comparison results are shown in Table 1 below. It can be seen that The present invention has achieved excellent performance in various evaluation indexes.

表1Table 1

实施例1Example 1

基于窗口注意力机制的自动睡眠分期方法,具体包括如下步骤:The automatic sleep staging method based on the window attention mechanism specifically includes the following steps:

步骤1,获取含睡眠分期标注的EEG信号数据集,将数据集按照个体划分为训练集和测试集;Step 1. Obtain the EEG signal data set marked with sleep stages, and divide the data set into training set and test set according to individuals;

步骤2,对步骤1所得的训练集和测试集进行预处理;Step 2, preprocessing the training set and test set obtained in step 1;

步骤3,构建针对EEG信号的自动睡眠分期模型;Step 3, constructing an automatic sleep staging model for EEG signals;

步骤4,采用步骤1中的训练集对步骤2中构建的网络模型进行训练,得到最优的自动睡眠分期模型;Step 4, using the training set in step 1 to train the network model constructed in step 2 to obtain the optimal automatic sleep staging model;

步骤5,将步骤2中的测试集放入步骤3训练好的自动睡眠分期模型中,输出睡眠分期结果。Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging results.

实施例2Example 2

在实施例1的基础上,步骤2的具体过程为:On the basis of embodiment 1, the specific process of step 2 is:

将数据集中所有个体的记录文件中包含的脑电信号按照30s为一帧进行划分,并与标记文件的标签数据建立对应关系;然后按照序列长度将多个信号帧及其对应标签进行合并;最终得到序列格式的样本集合。Divide the EEG signals contained in the record files of all individuals in the data set according to 30s as a frame, and establish a corresponding relationship with the label data of the label file; then merge multiple signal frames and their corresponding labels according to the sequence length; finally Get a collection of samples in sequence format.

实施例3Example 3

在实施例2的基础上,步骤3中,自动睡眠分期模型包括:On the basis of embodiment 2, in step 3, automatic sleep staging model comprises:

特征编码模块:采用双分支设计思路,分别提取信号中的低频和高频信息,并通过堆叠多层实现深度特征提取;Feature encoding module: adopts the dual-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realize deep feature extraction by stacking multiple layers;

特征提炼模块:实现在减小特征通道的同时保留关键特征信息不被丢弃;Feature extraction module: realize that the key feature information is not discarded while reducing the feature channel;

时序捕获模块:结合睡眠分期任务的特点,采用基于窗口注意力机制的Transformer实现对于输入信号中序列信息的处理;Timing capture module: Combined with the characteristics of the sleep staging task, the Transformer based on the window attention mechanism is used to process the sequence information in the input signal;

分类器:将输出特征映射为类别分布,实现最终的睡眠分期。Classifier: Map the output features to a class distribution to achieve the final sleep stage.

Claims (8)

Translated fromChinese
1.基于窗口注意力机制的自动睡眠分期方法,其特征在于:具体包括如下步骤:1. the automatic sleep staging method based on window attention mechanism, it is characterized in that: specifically comprise the steps:步骤1,获取含睡眠分期标注的EEG信号数据集,将数据集按照个体划分为训练集和测试集;Step 1, obtain the EEG signal data set with sleep stage annotation, and divide the data set into training set and test set according to the individual;步骤2,对步骤1所得的训练集和测试集进行预处理;Step 2, preprocessing the training set and test set obtained in step 1;步骤3,构建针对EEG信号的自动睡眠分期模型;Step 3, constructing an automatic sleep staging model for EEG signals;步骤4,采用步骤1中的训练集对步骤2中构建的网络模型进行训练,得到最优的自动睡眠分期模型;Step 4, using the training set in step 1 to train the network model constructed in step 2 to obtain the optimal automatic sleep staging model;步骤5,将步骤2中的测试集放入步骤3训练好的自动睡眠分期模型中,输出睡眠分期结果。Step 5, put the test set in step 2 into the automatic sleep staging model trained in step 3, and output the sleep staging results.2.根据权利要求1所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤2的具体过程为:2. the automatic sleep staging method based on window attention mechanism according to claim 1, is characterized in that: the concrete process of described step 2 is:将数据集中所有个体的记录文件中包含的脑电信号按照30s为一帧进行划分,并与标记文件的标签数据建立对应关系;然后按照序列长度将多个信号帧及其对应标签进行合并;最终得到序列格式的样本集合。Divide the EEG signals contained in the record files of all individuals in the data set according to 30s as a frame, and establish a corresponding relationship with the label data of the label file; then merge multiple signal frames and their corresponding labels according to the sequence length; finally Get a collection of samples in sequence format.3.根据权利要求2所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤3中,自动睡眠分期模型包括:3. the automatic sleep staging method based on window attention mechanism according to claim 2, is characterized in that: in described step 3, automatic sleep staging model comprises:特征编码模块:采用双分支设计思路,分别提取信号中的低频和高频信息,并通过堆叠多层实现深度特征提取;Feature encoding module: adopts the dual-branch design idea to extract low-frequency and high-frequency information in the signal respectively, and realize deep feature extraction by stacking multiple layers;特征提炼模块:实现在减小特征通道的同时保留关键特征信息不被丢弃;Feature extraction module: realize that the key feature information is not discarded while reducing the feature channel;时序捕获模块:结合睡眠分期任务的特点,采用基于窗口注意力机制的Transformer实现对于输入信号中序列信息的处理;Timing capture module: Combined with the characteristics of the sleep staging task, the Transformer based on the window attention mechanism is used to process the sequence information in the input signal;分类器:将输出特征映射为类别分布,实现最终的睡眠分期。Classifier: Map the output features to a class distribution to achieve the final sleep stage.4.根据权利要求3所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤3中,特征提取模块的具体操作为:4. the automatic sleep staging method based on window attention mechanism according to claim 3, is characterized in that: in described step 3, the concrete operation of feature extraction module is:步骤a.将训练集中的序列信号经过一个卷积层输出高频浅层特征同时,再经过一个卷积层输出低频浅层特征/>Step a. Pass the sequence signal in the training set through a convolutional layer to output high-frequency shallow features At the same time, output low-frequency shallow features through a convolutional layer/>步骤b.将高频浅层特征输入到最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到最大池化层,输出低频浅层特征/>Step b. Combine high-frequency shallow features Input to the maximum pooling layer, output high-frequency shallow features /> Low-frequency shallow features /> Input to the maximum pooling layer, output low-frequency shallow features/>步骤c.将高频浅层特征输入到两层卷积层组成的卷积块CB1,输出高频深层特征将低频浅层特征/>输入到两层卷积层组成的卷积块CB2,输出低频深层特征/>Step c. Combine high-frequency shallow features Input to the convolutional block CB1 composed of two convolutional layers, and output high-frequency deep features Low-frequency shallow features /> Input to the convolutional block CB2 composed of two convolutional layers, and output low-frequency deep features/>步骤d.将高频深层特征输入最大池化层,输出高频浅层特征/>将低频浅层特征/>输入到最大池化层,输出低频深层特征/>Step d. Combine high-frequency deep features Input max pooling layer, output high frequency shallow features/> Low-frequency shallow features /> Input to the maximum pooling layer, output low-frequency deep features/>步骤f.将高频浅层特征和低频深层特征/>进行通道连接得到组合特征O5Step f. Combine high-frequency shallow features and low-frequency deep features/> The channel connection is performed to obtain the combined feature O5 .5.根据权利要求4所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤3中,特征提炼模块的具体操作为:5. the automatic sleep staging method based on window attention mechanism according to claim 4, is characterized in that: in described step 3, the concrete operation of feature extraction module is:步骤g.将组合特征O5输入到两层卷积块CB3,输出特征O6,卷积层的激活函数为ReLU;Step g. Input the combined feature O5 into the two-layer convolutional block CB3 , output the feature O6 , and the activation function of the convolutional layer is ReLU;步骤h.将特征O6输入到由平均池化层和两层线性层组成的通道注意力CA中,两层线性层的激活函数分别为ReLU和Sigmoid,输出特征O7Step h. Input the feature O6 into the channel attention CA composed of an average pooling layer and two linear layers, the activation functions of the two linear layers are respectively ReLU and Sigmoid, and output the feature O7 ;步骤i.将特征O7按照特征尺寸复制之后与特征O6相乘,输出特征O8Step i. After copying the feature O7 according to the feature size, multiplying the feature O6 to output the feature O8 ;步骤j.将组合特征O5输入到卷积层,输出特征O9Step j. Input the combined feature O5 into the convolutional layer, and output the feature O9 ;步骤l.将特征O8和特征O9相加,输出特征O10Step 1. Add feature O8 and feature O9 to output feature O10 .6.根据权利要求5所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤3中,时序模块的具体操作为:6. the automatic sleep staging method based on window attention mechanism according to claim 5, is characterized in that: in described step 3, the concrete operation of timing module is:步骤m.将特征O10输入层归一化中,输出特征O11Step m. Input feature O10 into layer normalization, and output feature O11 ;步骤n.将特征O11输入三个不同的线性层中,输出特征Query、Key、Value,将特征Query和转置后Key特征相乘并归一化后,得到注意力矩阵m1Step n. Input the feature O11 into three different linear layers, output the features Query, Key, and Value, multiply and normalize the feature Query and the transposed Key feature, and obtain the attention matrix m1 ;步骤o.设定窗口掩码mask;将不同特征通道分为三个等级,对于不同重要程度的特征通道,通过赋予不同的权重而使其注意力分数更高,同一帧内的特征通道对应权重相同;假定当前帧为的序号为i,设定窗口大小为3,则其窗口范围则为[i-1,i,i+1];第i帧的权重最大,i-1帧和i+1帧的权重次之,其余帧的权重最低;然后,将注意力矩阵m1与掩码mask相乘,得到新的注意力矩阵m2Step o. Set the window mask mask; Divide different feature channels into three levels. For feature channels of different importance, assign different weights to make their attention scores higher. The corresponding weights of feature channels in the same frame The same; assuming that the serial number of the current frame is i, and the window size is set to 3, the window range is [i-1, i, i+1]; the weight of the i-th frame is the largest, and the i-1 frame and i+ The weight of 1 frame is next, and the weight of other frames is the lowest; then, the attention matrix m1 is multiplied by the mask mask to obtain a new attention matrix m2 ;步骤p.将新的注意力矩阵m2与特征Value相乘,输出特征O12Step p. Multiply the new attention matrix m2 with the feature Value, and output the feature O12 ;步骤q.将特征O12输入线性层中,同时,与特征O10下采样后相加构成残差连接,输出特征O13Step q. Input the feature O12 into the linear layer, and at the same time, add it to the feature O10 after downsampling to form a residual connection, and output the feature O13 ;步骤r.将特征O13输入层归一化中,输出特征O14Step r. Input feature O13 into layer normalization, and output feature O14 ;步骤s.将特征O14输入由两层线性层组成的前馈神经网络FF中,同时,与特征O13相加构成残差连接,输出特征O15Step s. Input the feature O14 into the feed-forward neural network FF composed of two linear layers, and at the same time, add it to the feature O13 to form a residual connection, and output the feature O15 .7.根据权利要求6所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤3中,分类器的具体操作为:7. the automatic sleep staging method based on window attention mechanism according to claim 6, is characterized in that: in described step 3, the concrete operation of classifier is:步骤t.将特征O15输入线性层中,并通过Softmax函数得到模型预测的概率分布,取值最高值即为对应睡眠帧的分期结果。Step t. Input the feature O15 into the linear layer, and obtain the probability distribution predicted by the model through the Softmax function, and the highest value is the staging result of the corresponding sleep frame.8.根据权利要求7所述的基于窗口注意力机制的自动睡眠分期方法,其特征在于:所述步骤4中,训练过程中采用多分类交叉熵作为损失函数,分类器通过Softmax函数将特征转化为归一化的概率分布,输出特征维度与类别数保持一致,表示为同时,将标签所指定的睡眠阶段转为one-hot编码的向量以表示目标概率分布,表示为yi,n代表样本个数,K代表类别个数,具体表示为:8. the automatic sleep staging method based on window attention mechanism according to claim 7, is characterized in that: in described step 4, adopt multiclassification cross-entropy as loss function in training process, classifier converts feature by Softmax function For a normalized probability distribution, the output feature dimension is consistent with the number of categories, expressed as At the same time, the sleep stage specified by the label is converted into a one-hot encoded vector to represent the target probability distribution, expressed as yi , n represents the number of samples, and K represents the number of categories, specifically expressed as:
CN202310509949.3A2023-05-082023-05-08 Automatic Sleep Staging Method Based on Window Attention MechanismPendingCN116509421A (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN202310509949.3ACN116509421A (en)2023-05-082023-05-08 Automatic Sleep Staging Method Based on Window Attention Mechanism

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN202310509949.3ACN116509421A (en)2023-05-082023-05-08 Automatic Sleep Staging Method Based on Window Attention Mechanism

Publications (1)

Publication NumberPublication Date
CN116509421Atrue CN116509421A (en)2023-08-01

Family

ID=87393799

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN202310509949.3APendingCN116509421A (en)2023-05-082023-05-08 Automatic Sleep Staging Method Based on Window Attention Mechanism

Country Status (1)

CountryLink
CN (1)CN116509421A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN118568558A (en)*2024-05-172024-08-30浙江大学Sleep stage and interpretability analysis method based on deep capsule network

Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111783534A (en)*2020-05-282020-10-16东南大学 A sleep staging method based on deep learning
CN113158964A (en)*2021-05-072021-07-23北京工业大学Sleep staging method based on residual learning and multi-granularity feature fusion
CN114366038A (en)*2022-02-172022-04-19重庆邮电大学 Sleep signal automatic staging method based on improved deep learning algorithm model
CN114431878A (en)*2020-11-022022-05-06哈尔滨理工大学 An EEG sleep staging method based on multi-scale attention residual network
CN115035388A (en)*2022-07-072022-09-09北京京东尚科信息技术有限公司 Image recognition method and device, and computer storable medium
CN115530847A (en)*2022-09-302022-12-30哈尔滨理工大学Electroencephalogram signal automatic sleep staging method based on multi-scale attention

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN111783534A (en)*2020-05-282020-10-16东南大学 A sleep staging method based on deep learning
CN114431878A (en)*2020-11-022022-05-06哈尔滨理工大学 An EEG sleep staging method based on multi-scale attention residual network
CN113158964A (en)*2021-05-072021-07-23北京工业大学Sleep staging method based on residual learning and multi-granularity feature fusion
CN114366038A (en)*2022-02-172022-04-19重庆邮电大学 Sleep signal automatic staging method based on improved deep learning algorithm model
CN115035388A (en)*2022-07-072022-09-09北京京东尚科信息技术有限公司 Image recognition method and device, and computer storable medium
CN115530847A (en)*2022-09-302022-12-30哈尔滨理工大学Electroencephalogram signal automatic sleep staging method based on multi-scale attention

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
宋远帆: "面向自动睡眠分期的深度学习分类方法研究", 万方, 12 December 2023 (2023-12-12), pages 1 - 60*
张金辉等: "基于深度学习的多通道脑电信号睡眠分期方法", 中国医疗设备, vol. 37, no. 7, 27 July 2022 (2022-07-27), pages 49 - 52*

Cited By (1)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN118568558A (en)*2024-05-172024-08-30浙江大学Sleep stage and interpretability analysis method based on deep capsule network

Similar Documents

PublicationPublication DateTitle
Yang et al.Obstructive sleep apnea detection from single-lead electrocardiogram signals using one-dimensional squeeze-and-excitation residual group network
Zali-Vargahan et al.Deep time-frequency features and semi-supervised dimension reduction for subject-independent emotion recognition from multi-channel EEG signals
CN116680412B (en)Traditional Chinese medicine prescription recommendation method based on knowledge graph
CN113080864B (en)Common sleep disease detection method through automatic sleep staging results
CN114652322B (en) A method and system for classifying electrocardiogram signals based on multi-domain feature learning
He et al.Single-channel EEG sleep staging based on data augmentation and cross-subject discrepancy alleviation
CN112932501B (en)Method for automatically identifying insomnia based on one-dimensional convolutional neural network
CN108256453A (en)A kind of method based on one-dimensional ECG signal extraction two dimension CNN features
CN113128353B (en)Emotion perception method and system oriented to natural man-machine interaction
CN115530847A (en)Electroencephalogram signal automatic sleep staging method based on multi-scale attention
CN116186593B (en) An ECG signal detection method based on separable convolution and attention mechanism
CN116687422B (en) An auxiliary diagnosis system for patients with consciousness disorders based on automatic sleep staging
CN116509421A (en) Automatic Sleep Staging Method Based on Window Attention Mechanism
CN114052734B (en)Electroencephalogram emotion recognition method based on progressive graph convolution neural network
CN113554110A (en) An EEG Emotion Recognition Method Based on Binary Capsule Network
CN114300126A (en)Cancer prediction system based on early cancer screening questionnaire and feed-forward neural network
CN116931720A (en) Motor imagery EEG decoding method based on multi-view attention mechanism
CN117932306A (en)Deep learning-based cross-test driving fatigue detection system
CN116130053A (en) A rehabilitation training system
CN116127286A (en) EEG emotion recognition detection method and system based on lightweight residual convolutional capsule network
CN115345204A (en)Neonate convulsion detecting system based on improve elastic net algorithm
CN111613321A (en) A method for auxiliary diagnosis of electrocardiogram stroke based on dense convolutional neural network
CN111657860A (en)Method and system for identifying sleep stage based on counterstudy
CN109800651B (en) A multi-class EEG classification method based on dual-rule active extreme learning machine
CN114997315A (en)Error correlation potential classification method based on multichannel electroencephalogram integration

Legal Events

DateCodeTitleDescription
PB01Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination

[8]ページ先頭

©2009-2025 Movatter.jp