Electrocardiosignal enhancement and classification method based on gating circulation diffusion model

Through the combination of the gated cyclic diffusion model and the CNN-GRU model, the problems of data imbalance and insufficient time series feature capture in the ECG signal classification are solved, the recognition accuracy and classification performance of abnormal ECG signals are improved, and the model training is simplified process.

CN119179929AActive Publication Date: 2024-12-24NANJING UNIV

Patent Information

Application Number
CN202411264777.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-10
Publication Date
2024-12-24
Estimated Expiration
2044-09-10

AI Technical Summary

Technical Problem

The existing ECG signal classification model has insufficient recognition capabilities when dealing with small-scale anomaly data and high data imbalance, limited time series feature capture, and strong preprocessing dependence, resulting in low classification accuracy and complex training.

Method used

The electrocardiogram signal enhancement and classification method based on the gated cyclic diffusion model is adopted to supplement the data set through the diffusion model, and combined with the CNN-GRU model to extrude excitation block enhance feature learning, improving data balance and time series feature capture capabilities.

Benefits of technology

It effectively solves the problems of data imbalance and insufficient time series feature capture, improves the recognition accuracy and classification performance of abnormal ECG signals, and reduces the complexity of model training and the risk of gradient explosion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119179929A_ABST
    Figure CN119179929A_ABST
Patent Text Reader

Abstract

The invention provides an electrocardiosignal enhancement and classification method based on a gating circulation diffusion model. The electrocardiosignal enhancement and classification method comprises the steps that 1, an electrocardiosignal data set is obtained; 2, setting parameters and hyper-parameters of the diffusion model; step 3, establishing a neural network structure of the diffusion model; 4, a diffusion model is trained, and the electrocardiosignal data set is supplemented through the trained diffusion model; 5, setting hyper-parameters of the classification model; step 6, establishing a classification model; and 7, training a classification model by adopting the electrocardiosignal data set obtained in the step 4, and using the trained classification model for electrocardiosignal classification. According to the method, a gating circulation diffusion model is introduced to supplement data, and compared with a traditional generative model, the time sequence information of electrocardiosignals can be better captured, so that the heart rate characteristics are simulated.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an electrocardiogram signal enhancement and classification method based on a gated cyclic diffusion model. Background Art

[0002] Electrocardiogram (ECG), as an important physiological signal reflecting cardiac electrical activity, has been widely used in the diagnosis, monitoring and management of cardiovascular diseases. Accurate analysis and classification of ECG signals is of great clinical significance for the early detection and diagnosis of cardiac abnormalities such as arrhythmia and myocardial ischemia. Automatic classification methods of ECG signals can help medical professionals quickly and accurately identify abnormal ECG signals, improve diagnostic efficiency, reduce workload, and reduce human errors to a certain extent. With the development of artificial intelligence technology, ECG signal classification methods are mainly divided into two categories: machine learning-based methods and deep learning-based methods. Machine learning-based ECG signal classification methods usually rely on feature engineering, including manual feature extraction (such as time domain features, frequency domain features, etc.) and feature selection, and then use classifiers (such as support vector machines, random forests, etc.) for classification. Deep learning-based methods mainly use the architecture of convolutional neural networks (CNNs), recurrent neural networks (RNNs), and hybrid models (such as CNN-RNNs). These methods can automatically extract features from raw signals and show strong classification capabilities on large-scale data sets. However, these deep learning models usually require a large amount of labeled data for training, and they are highly dependent on data. Although these methods can improve the classification performance of ECG signals to a certain extent, there are still many challenges in dealing with small-scale abnormal data and high data imbalance.

[0003] Traditional ECG signal classification models usually face the following major problems: 1. Data imbalance: In ECG signal data sets, the amount of normal signal data is much larger than the amount of abnormal signal data, which causes the model to be more inclined to learn the features of normal signals during training. This will result in poor recognition of abnormal ECG signals (such as VEB, VFW, APB, etc.) in clinical applications, which may lead to misdiagnosis or missed diagnosis. 2. Insufficient capture of time series features: Traditional deep learning models have limited ability to process time series features, especially for complex and dynamically changing data such as ECG signals. Although recurrent neural networks (RNN) and long short-term memory networks (LSTM) can capture time dependencies, they are still insufficient when processing long time series data. The lack of effective learning of abnormal waveform features may lead to low accuracy in identifying abnormal ECG signals. 3. Strong preprocessing dependence: Many models rely on complex preprocessing steps such as denoising, baseline drift correction, and feature extraction before signal classification. This dependence makes the model training and inference process complex and time-consuming, and may lose important features in some signals, affecting the classification effect. Summary of the invention

[0004] Purpose of the invention: The technical problem to be solved by the present invention is to provide an electrocardiogram signal enhancement and classification method based on a gated cyclic diffusion model in view of the shortcomings of the prior art, comprising the following steps:

[0005] Step 1, obtain the ECG signal data set;

[0006] Step 2, setting the parameters and hyperparameters of the diffusion model;

[0007] Step 3, establishing the neural network structure of the diffusion model;

[0008] Step 4: training the diffusion model and supplementing the ECG signal dataset with the trained diffusion model;

[0009] Step 5, set the hyperparameters of the classification model;

[0010] Step 6, establishing a classification model;

[0011] Step 7: Use the ECG signal data set obtained in step 4 to train a classification model, and use the trained classification model for ECG signal classification.

[0012] In step 3, the diffusion model is a gated recurrent diffusion model, including an initial layer, a time embedding layer, four downsampling layers, an intermediate layer, four upsampling layers and an output layer;

[0013] The initial layer includes only one one-dimensional convolution layer, the convolution kernel size is 7, the input channel is 1, and the output channel is 32.

[0014] In step 3, the time embedding layer accepts a single integer representing a timestamp as input, and the time embedding layer includes a sinusoidal position encoding, a first fully connected layer, a Gaussian Error Linear Units (GeLU) activation function, and a second fully connected layer;

[0015] The sinusoidal position encoding is performed as follows: a vector γ is generated, the i-th element γ of the vector γ i = is an integer set, exp is the natural exponential function, θ is a settable parameter, and l is the vector length; multiply the input timestamp by the vector γ to get the vector σ, and find the sine and cosine values ​​of each element in the vector σ to get the vectors α and β, that is, α i = sinσ i ,β i =cosσ i , α i is the i-th element of the vector α, β i is the i-th element of vector β. Connecting vectors α and β gives a vector λ of length 32, where λ is the output of sinusoidal position encoding;

[0016] In the temporal embedding layer, the number of input channels of the first fully connected layer is 32, and the number of output channels is 128. The number of input and output channels of the second fully connected layer are both 128;

[0017] The Gaussian error linear unit activation function is represented by GeLU(x G ): where x G A single number representing the input Gaussian error linear unit activation function;

[0018] The time vector output by the temporal embedding layer will be input into all residual blocks.

[0019] In step 3, the downsampling layer includes two residual blocks, an attention part and a downsampling part. The data in the downsampling layer will be used as input to the upsampling layer. A stack data structure is set. After the first residual block and attention part of each downsampling layer, the current data is saved and stored in the stack.

[0020] The residual block includes an initial convolution part, a time embedding part, an intermediate convolution part and a residual convolution part; in the downsampling layer, all residual blocks do not change the data shape, the input channel is equal to the output channel, and the number of channels is the same as the number of input data channels of the corresponding downsampling layer;

[0021] In the residual block of the downsampling layer, the convolution kernel size of the initial convolution part and the intermediate convolution part is 3, and the convolution kernel size of the residual convolution part is 1;

[0022] In the residual block of the downsampling layer, the initial convolution part includes the convolution layer and the root mean square normalization (Root Mean Square Layer Normalization, RMS Norm) layer. The formula for root mean square normalization is:

[0023]

[0024] The root mean square function represents RMS normalization, g and d represent stretching parameters, e represents offset parameter, ⊙ represents multiplication by position, x R represents the input vector, x Rj For x R Elements in

[0025] In the residual block of the downsampling layer, the temporal embedding part includes the Sigmoid-weighed Linear Units (SiLU) activation function and the fully connected layer. The formula of the Silu activation function SiLU(x) is: SiLU(x) = x*Sigmoid(x), where x represents a single number input to the Silu activation function; the input channel of the fully connected layer is 128, and the output channel is twice the size of the input feature vector of the residual block; the output of the temporal embedding part is divided into two parts of equal length, which are respectively used as the scaling vector and the displacement scaling vector. The scaling vector is first multiplied one by one with the corresponding elements of the output vector of the initial convolution part to obtain a new vector, and then the new vector is added to the displacement scaling vector, and the result is input to the intermediate convolution part;

[0026] In the residual block of the downsampling layer, the intermediate convolution part includes the S-type rectifier unit activation function, the random inactivation (Dropout) layer, the convolution layer and the RMS normalization layer;

[0027] In the residual block of the downsampling layer, the residual convolution part includes the S-type rectifier unit activation function, the random dropout layer and the convolution layer; when the input and output channels of the residual block are the same, the input data of the convolution layer is retained and added to the output result of the convolution layer as the final output of the residual block;

[0028] The attention part of the downsampling layer includes pre-RMS normalization and linear multi-head attention mechanism;

[0029] In the attention part of the downsampling layer, the data is first processed by RMS normalization, and the input feature vector first enters the convolution layer. The input dimension of the convolution layer is the same as the input feature vector size, and the convolution kernel size is 1; in the gated recurrent diffusion model, the number of multi-head attention mechanism heads is 4, and the dimension of a single head is 32, that is, the shape of the query, key, and value tensors is (batch size (batch size),4,32,feature vector size); the output channel of the convolution layer is 4×32×3=384; the output of the convolution layer is divided into three parts, as the query (Query, Q), key (Key, K), and value (Value, V) of the attention mechanism, which are used to calculate the attention weight and generate the final output; first, the query and key are respectively passed through the normalized exponential function (Softmax) layer, and then each element in the query is multiplied by -16; the key and value that have passed the normalized exponential function layer are matrix multiplied in the last two dimensions, and the obtained content is matrix multiplied with the scaled query in the last two dimensions, and the result is merged with the middle two dimensions, that is, from (batch size, 4,32, feature vector size) to (batch size, 128, feature vector size) and then enters the convolution layer, the convolution kernel size is 1, the input channel is 128, and the output channel is the same as the input feature vector size; after convolution, the output vector is root mean square normalized; finally, the output vector is added to the output result of the second residual block to obtain the final output of the multi-head attention mechanism;

[0030] The downsampling layer part of the downsampling layer contains only one convolution layer with a convolution kernel size of 4 and a stride of 2; the number of input channels of the four downsampling layers in the gated recurrent diffusion model are 32, 64, 128, and 256 respectively; the residual block and attention mechanism in the downsampling layer do not change the data shape, while the downsampling part doubles the number of channels and halves the data size; in the downsampling part of the fourth downsampling layer, the convolution layer stride is 1, the convolution kernel size is 3, and the data size remains unchanged; the convolution layer output of the downsampling part is the output of the downsampling layer.

[0031] In step 3, the intermediate layer includes an initial residual block, a gated recurrent unit array, a multi-head attention mechanism and a final residual block;

[0032] The initial residual block and the final residual block of the intermediate layer have the same structure as the residual block in the downsampling layer, and the number of input and output channels is 256;

[0033] The gated recurrent unit array of the middle layer includes a total of 16 layers of gated recurrent units connected in series. The gated recurrent unit includes a reset gate, an update gate and a hidden state, and the formula is expressed as follows:

[0034] z t =Sigmoid(W z ·[h t-1 ,x t]),

[0035] r t =Sigmoid(W r ·[g t-1 ,x t ]),

[0036]

[0037] where r t represents the reset gate, z t represents the update gate, h t is the hidden state, W z , W r , W h is the weight, represents the candidate hidden state, h t-1 represents the hidden state at the previous moment, x t is the input at the current moment, and x0 is the input at the initial moment; data is sequentially input into the gated recurrent unit starting from x0, and the initial hidden state h0 of the gated recurrent unit is a zero vector; the new hidden state is calculated according to the formula, and after all the data are input, the output is the combination of the hidden states of each step, and the output vector of the initial residual block is used as the input vector of the first layer of gated recurrent unit, and the output vector of the first layer of gated recurrent unit is used as the input vector of the second layer of gated recurrent unit, and so on;

[0038] The multi-head attention mechanism of the intermediate layer includes: the feature vector is first subjected to pre-root mean square normalization, and then enters the convolution layer to be divided into query, key, and value; the number of heads of the multi-head attention mechanism is 4, and the dimension of a single head is 32, that is, the shape of the query, key, and value tensors is (batch size, 4, 32, feature vector size); first, the query is multiplied by -16 to change the scale, and matrix multiplication is performed with the key on the last two dimensions. The result passes through the normalized exponential function layer, and then matrix multiplication is performed with the value on the last two dimensions, and the middle two dimensions are merged, that is, from (batch size, 4, 32, feature vector size) to (batch size, 128, feature vector size) and then enters the convolution layer, and the convolution layer output is added to the feature vector before the pre-root mean square normalization to obtain the final output of the multi-head attention mechanism.

[0039] In step 3, the upsampling layer includes two residual blocks, an attention part and an upsampling part;

[0040] The residual block structure of the upsampling layer is the same as the residual block in the downsampling layer, but the number of output channels of each residual block is different from the number of input channels, so the output of the convolution layer in the residual convolution part is not added to the original data; the input data of the residual block includes the data extracted from the downsampled data stack in addition to the original input data, and the original input data and the data extracted from the downsampled data stack are connected as the input of the residual block;

[0041] The attention part of the upsampling layer is the same as the attention part of the downsampling layer;

[0042] The upsampling part of the upsampling layer includes an upsampling function and a convolution layer. The upsampling function uses a neighbor algorithm to double the data size. Suppose the original vector is represents a natural number, n represents the length of the original vector, x0,x1,…,x n-1 represents the n elements in the original vector; then (x0, x1, …, x n )The output of the upsampling function is (x0,x0,x1,x1,…,x n ,x n ); the convolution kernel size of the convolution layer is 3;

[0043] The input channel numbers of the four upsampling layers in the gated recurrent diffusion model are 256, 128, 64, and 32 respectively; the upsampling part reduces the number of channels by half and doubles the data size; in the upsampling part of the fourth upsampling layer, there is only a convolutional layer without an upsampling function, and the number of channels and data size remain unchanged; the output of the convolutional layer of the upsampling part is the output of the upsampling layer.

[0044] In step 3, the output layer includes a residual block and a convolution layer; the structure of the residual block is the same as the residual block in the downsampling layer, and the number of input and output channels is 32; the number of input and output channels of the convolution layer is 32, and the convolution kernel size is 1.

[0045] Step 4 includes:

[0046] Step 4-1, divide the ECG signal dataset into X1 batches according to the batch size, and randomly select a batch;

[0047] Step 4-2, randomly generate a timestamp t;

[0048] Step 4-3: Calculate the noisy data x after each data x0 in the current batch is iterated t times t :

[0049]

[0050] where β t represents the noise ratio parameter after iteration t times, α t =1-β t , α t represents the signal ratio parameter after iteration t times, α s represents the signal ratio parameter after s iterations, represents the cumulative signal ratio parameter after iteration t times, q(xt |x0) indicates the noisy data x when the known data x0 is present t The probability distribution of , N represents the normal distribution, and I represents the identity matrix;

[0051] Step 4-4, the noisy data x t Input the diffusion model with timestamp t to get the output and calculate the loss Loss = ||∈-∈ θ (x t ,t)|| 2 , perform gradient descent to modify the parameters of the diffusion model; where ∈ θ (x t ,t) represents the prediction result of the diffusion model, ∈ represents the random noise that obeys the standard normal distribution;

[0052] Step 4-5, repeat step 4-1 to step 4-4 process X2 times;

[0053] Step 4-6: After the diffusion model is trained, the ECG signal data set is randomly divided into a test set and a training set in proportion;

[0054] Step 4-7, sampling according to the trained diffusion model to generate new data, includes the following steps:

[0055] Step 4-7-1, generate random noise that obeys the standard normal distribution and set the timestamp t;

[0056] Step 4-7-2, random noise is used as an input signal and input into the diffusion model together with the timestamp t;

[0057] Step 4-7-3, add the output result of the diffusion model to the input signal as a new input signal, and decrement the timestamp once;

[0058] Step 4-7-4, repeat X3 steps until the timestamp is decremented to 0, and the output signal at this time is the new data generated by the diffusion model;

[0059] Steps 4-8: Add the generated new data to the training set of the corresponding category.

[0060] Step 6 includes: the classification model includes four layers, the first layer includes 4 convolution blocks and a maximum pooling layer; the second layer includes a fully connected layer, a random dropout layer, a batch normalization layer and a linear rectifier unit (Rectified Linear Units, ReLU) activation function; the third layer is a gated recurrent unit layer; the fourth layer includes a fully connected layer and a normalized exponential function layer;

[0061] In the first layer, a convolution block contains two sub-blocks and a squeeze-and-excitation block (SE-Block); the input channel numbers of the four convolution blocks are 1, 64, 128, and 256, respectively, and the output channel numbers are 64, 128, 256, and 512, respectively;

[0062] The sub-blocks in the convolution block include a one-dimensional convolution layer, a batch normalization layer, and a linear rectifier unit activation function; in the sub-block, the convolution kernel size of each one-dimensional convolution layer is 3, the step size is 1, and the padding is 1; the formula for each sub-block is: in represents the convolution operator, W conv represents the weight of the convolution kernel, b conv is the bias vector, x i-1 With x i Represent the input vector and output vector respectively, BN represents batch normalization; the number of input channels and output channels of the one-dimensional convolution layer of the first sub-block are equal to the number of input channels and output channels set by the convolution block, and the number of input channels and output channels of the convolution layer of the second sub-block are equal to the number of output channels set by the convolution block;

[0063] The squeeze-excitation block in the convolution block includes a global maximum pooling layer, a first fully connected layer, a linear rectifier unit activation function, a second fully connected layer, and an S-type activation function (Sigmoid activation function); the global maximum pooling is expressed as:

[0064]

[0065] where y mp represents the global maximum pooling value, x mpk Represents the input signal x mp The kth value in L is the input signal x mp length; after the data passes through the first fully connected layer, the number of channels becomes the original Then it passes through the linear rectifier unit activation function, expressed as:

[0066] x s =ReLU(W1x s-1 +b1),

[0067] Where W1 represents the weight of the fully connected layer, b1 is the bias vector, and x s-1 With x s Represent the input vector and output vector respectively; after the data passes through the second fully connected layer, the original number of channels is restored and then passes through the S-type activation function, which is expressed as: x e =Sigmoid(W2x e-1 +b2), where W2 represents the weight of the fully connected layer, b2 is the bias vector, and xe-1 With x e Represent the input vector and output vector respectively; finally, the result is used as the weight to multiply the original data before entering the squeeze excitation block to obtain the final result;

[0068] In the first layer, the one-dimensional maximum pooling is expressed as: where y i Represents the pooling range R i The maximum pooling output value within, x p Represents R i The element at position p in

[0069] Between the first and second layers, the dimension of the data is reduced, and the shape changes from (batch size, number of feature maps, data size) to (batch size, number of feature maps * data size);

[0070] In the second layer, the number of input channels of the fully connected layer is the number of feature maps * data size;

[0071] In the third layer, the gated recurrent unit input size is equal to the number of output channels in the second layer;

[0072] In the fourth layer, the number of input channels of the fully connected layer is equal to the number of hidden layers of the gated recurrent unit, and the number of output channels is the number of classifications; the formula of the normalized exponential function layer is:

[0073]

[0074] Where p(y c ) is the probability output of the neuron after the normalized exponential function, y c is the output value of the cth neuron in the previous fully connected layer, and m is the number of target categories.

[0075] The present invention also provides an electronic device, comprising a processor and a memory, wherein the memory stores program code, and when the program code is executed by the processor, the processor executes the steps of the described method.

[0076] The method of the present invention enhances the data set by introducing a gated cyclic diffusion model, especially the data enhancement of abnormal ECG signals, effectively solving the problems of data imbalance and difficulty in obtaining abnormal data. At the same time, the CNN-GRU model embedded with the squeeze excitation block can better capture the local and global features in the ECG signal, improve the learning ability of time series features, and enhance the recognition accuracy of abnormal ECG signals, thereby comprehensively improving the performance and robustness of ECG signal classification.

[0077] Beneficial effects: (1) The method of the present invention introduces a gated recurrent diffusion model to supplement data. Compared with the traditional generative model, it can better capture the timing information of the ECG signal, thereby simulating the characteristics of the heart rate. In addition, compared with the common U-Net diffusion model, the gated recurrent diffusion model has fewer parameters and is faster to train. Moreover, due to the introduction of GRU, it can effectively prevent the gradient explosion problem.

[0078] (2) The present invention proposes a classification model of CNN and GRU embedded with a squeeze excitation block. The classification model of CNN and GRU embedded with a squeeze excitation block can better capture features in the classification of ECG signals and improve the ability to recognize abnormal waveforms, thereby effectively improving the performance of the classification model. The squeeze excitation block allows the network to automatically learn to allocate different degrees of attention to different types of ECG signals, so that the network can pay more attention to the features that play a decisive role in classification. For example, for an abnormal waveform such as early ventricular beat (PVC), it usually has the characteristics of a sudden wide QRS wave and no P wave, while early atrial beat (APB) has an abnormal P wave. By introducing the squeeze excitation block, the CNN and GRU networks can better capture these local features and pay more attention to these key features during the classification process, thereby improving the recognition accuracy of abnormal waveforms. The convolutional layer of CNN can capture the local features in the ECG signal, while the GRU can better capture the dynamic features of the time series. Combining the two, the CNN and GRU networks can more comprehensively consider the spatial and temporal features of the entire ECG signal, thereby further improving the performance of the classification model. For example, for an abnormal waveform such as VFW (narrow QRS wave, wide T wave), which usually has the characteristics of a narrow QRS wave and a wide T wave, the combined model of CNN and GRU can better capture this complex feature and improve its classification accuracy. BRIEF DESCRIPTION OF THE DRAWINGS

[0079] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments, and the above and / or other advantages of the present invention will become more clear.

[0080] Figure 1 It is a schematic diagram of the system architecture of an embodiment of the present application.

[0081] Figure 2 It is a structural diagram of the diffusion model.

[0082] Figure 3 It is the residual block structure diagram.

[0083] Figure 4 It is a schematic diagram of the linear multi-head attention mechanism.

[0084] Figure 5 It is a schematic diagram of the multi-head attention mechanism.

[0085] Figure 6 It is a schematic diagram of the sampling process of the diffusion model.

[0086] Figure 7 It is a schematic diagram of the classification model structure.

[0087] Figure 8 This is a schematic diagram of the ECG signal generated by the traditional generative model.

[0088] Fig. 9 This is a schematic diagram of the ECG signal generated by the gated circular diffusion model.

[0089] Fig.10 This is a schematic diagram of the gradient explosion produced by the traditional diffusion model.

[0090] Fig.11 This is a schematic diagram showing that the gated recurrent model can be trained stably.

[0091] Fig.12 It is a schematic diagram of the performance of the embodiment of the present application on the MIT-BIH database. DETAILED DESCRIPTION

[0092] The present invention provides an electrocardiogram signal enhancement and classification method based on a gated cyclic diffusion model, comprising:

[0093] The diffusion model is used to train the categories with small data volume in the dataset separately, and the trained parameters are used to generate new corresponding category data.

[0094] After dividing the data set into training set and test set, the data generated by the diffusion model are added to the training set.

[0095] The training set is used to train the classification model composed of CNN and GRU, and the classification model is used for ECG signal classification.

[0096] like Figure 1 As shown, the system architecture of the embodiment of the present application includes a data set, a diffusion model and a classification model. Among them, the data set can come from the MIT-BIH arrhythmia database, the AHA arrhythmia ECG database, etc. The diffusion model is a generation model that gradually reduces the noise of Gaussian noise to generate a target signal. The classification model consists of a convolutional neural network (CNN) and a gated recurrent unit (GRU), and an attention mechanism is introduced.

[0097] Take eight types of ECG signals, APB, LBB, NOR, PAB, PVC, RBB, VEB, and VFW, from the MIT-BIH database to construct the data set in the embodiment of this application, and use the diffusion model to generate three types of data, APB, VEB, and VFW. In practical applications, there is no restriction on the source of the data set and the type of data generated by the diffusion model. Specifically, the following steps are included:

[0098] 1. Obtain all APB markers in samples 209, 220, 222, 223, and 232 in the MIT-BIH database.

[0099] 2. Remove the first 20 markers and the last 20 markers of each sample.

[0100] 3. For each remaining marked point, take the first 600 points and the last 599 points, and save the total 1200 points as a segment of ECG signal as one-dimensional data. The one-dimensional data can be a .txt file, .json file, .npy file, etc., and the specific form is not limited. If the sample has two or more channels, save the data of all channels separately. Due to the different sampling rates of the database, the number of points taken may be different, and the obtained ECG signal can have three or more QRS waves.

[0101] 4. Obtain all LBB markers in samples 109, 111, 207, and 213 in the MIT-BIH database, all NOR markers in samples 100, 101, 103, 105, 108, 112, 113, 114, 115, 117, 121, 122, 123, 202, 205, 219, 230, and 234, all PAB markers in samples 102, 104, 107, and 217, all PVC markers in samples 106, 116, 119, 200, 201, 203, 208, 210, 213, 215, 221, 228, and 233, all RBB markers in samples 118, 124, 212, and 231, all VEB markers in sample 207, and all VFW markers in sample 207.

[0102] 5. Repeat steps 2 and 3 for each type of marking point. After the process is completed, a total of 4192 data items of APB type, 11980 data items of LBB type, 73776 data items of NOR type, 13768 data items of PAB type, 11192 data items of PVC type, 13284 data items of RBB type, 102 data items of VEB type, and 938 data items of VFW type are obtained.

[0103] 6. Set the parameters and hyperparameters of the diffusion model. Set the time step to 500. Take 500 numbers evenly between -6 and 6, and make these 500 numbers pass through the S-type activation function. The result is used as the noise ratio parameter, where the tth number is written as β tThere are no restrictions on batch size, epochs, and learning rate. In this example, the batch size for VEB is 10, the batch size for other classes is 100, the epochs are 500, the learning rate is 0.001, and no learning rate decay is set.

[0104] 7. Set the neural network structure of the diffusion model. Figure 2 As shown, the gated cyclic diffusion model structure designed for the embodiment of the present application includes:

[0105] a-1) The gated recurrent diffusion model consists of an initial layer, a time embedding layer, four downsampling layers, an intermediate layer, four upsampling layers, and an output layer;

[0106] a-2) The initial layer only includes one 1D convolutional layer. The convolution kernel size is 7, the input channel is 1, and the output channel is 32. (In the gated recurrent diffusion model, if not mentioned, the stride of the convolutional layer is 1)

[0107] a-3) The time embedding layer accepts a single integer representing the timestamp as input. It consists of: sinusoidal position encoding, the first fully connected layer, Gaussian error linear unit activation function and the second fully connected layer.

[0108] a-4) The sinusoidal position encoding calculation method in the temporal embedding layer is as follows: First, a vector γ is generated, whose i-th element θ is a configurable parameter, which is 10000 in the embodiment of the present application. Multiply the input timestamp by γ to obtain a vector σ. Calculate the sine and cosine values ​​of each element in σ to obtain vectors α and β, that is, α i = sinσ i ,β i =cosσ i ,i∈[0,15], Connecting vectors α and β obtains a vector ∈ of length 32, where ∈ is the output of the sinusoidal position encoding.

[0109] a-5) In the time embedding layer, the number of input channels of the first fully connected layer is 32, and the number of output channels is 128. The number of input and output channels of the second fully connected layer is 128. The Gaussian error linear unit activation function can be expressed as: The time vector output by the temporal embedding layer will be input into all residual blocks.

[0110] a-6) The downsampling layer consists of two residual blocks, an attention part, and a downsampling part. Since the data in the downsampling layer will be used as input to the upsampling layer, a stack data structure is set. After the first residual block and attention part of each downsampling layer, the current data is saved and stored in the stack.

[0111] a-7) If Figure 3 As shown in the figure, the residual block structure in the downsampling layer can be divided into: initial convolution part, time embedding part, intermediate convolution part and residual convolution part. In the downsampling layer, all residual blocks do not change the data shape, the input channel is equal to the output channel, and the number of channels is the same as the number of input data channels of the corresponding downsampling layer.

[0112] a-8) In the residual block of the downsampling layer, the convolution kernel size of the initial convolution part and the intermediate convolution part is 3, and the convolution kernel size of the residual convolution part is 1.

[0113] a-9) In the residual block of the downsampling layer, the initial convolution part includes the convolution layer and the root mean square normalization layer (RMSNormalization). The formula for root mean square normalization is: in

[0114]

[0115] a-10) In the residual block of the downsampling layer, the time embedding part includes the S-type rectifier unit activation function and the fully connected layer. The formula of the S-type rectifier unit is: SiLU(x) = x*Sigmoid(x). The input channel of the fully connected layer is 128, and the output channel is twice the size of the input feature vector of the residual block. The output of the time embedding part is divided into two parts of equal length, which serve as the scaling scale vector and the displacement scale vector respectively. First, multiply the scaling scale vector and the corresponding elements of the output vector of the initial convolution part one by one to obtain a new vector, then add the new vector to the displacement scale vector, and input the result into the intermediate convolution part.

[0116] a-11) In the residual block of the downsampling layer, the intermediate convolution part includes the S-type rectifier unit activation function, random dropout layer, convolution layer and RMS normalization layer. Random dropout is a means of randomly discarding neurons in the fully connected layer during each training to avoid overfitting. In the gated recurrent diffusion model, the probability of random dropout is 0.25.

[0117] a-12) In the residual block of the downsampling layer, the residual convolution part includes the S-type rectifier unit activation function, the random dropout layer and the convolution layer. When the input and output channels of the residual block are the same, the input data of the convolution layer is retained and added to the output result of the convolution layer as the final output of the residual block.

[0118] a-13) The attention part of the downsampling layer includes pre-RMS normalization and linear multi-head attention mechanism.

[0119] a-14) In the attention part of the downsampling layer, the data is firstly processed by RMS normalization. Figure 4 As shown in the figure, the algorithm of the linear multi-head attention mechanism in the gated recurrent diffusion model is shown. The input feature vector first enters the convolutional layer, whose input dimension is the same as the input feature vector size, and the convolution kernel size is 1. In the gated recurrent diffusion model, the number of heads of the multi-head attention mechanism is 4, and the dimension of a single head is 32, that is, the shape of the query, key, and value tensors is (batch size, 4, 32, feature vector size). The output channels of the convolutional layer are 4×32×3=384. The output of the convolutional layer is divided into three parts as the query, key, and value of the attention mechanism. First, the query and key are passed through the normalized exponential function layer respectively, and then each element in the query is multiplied by -16. The key and value that have passed through the normalized exponential function layer are matrix multiplied in the last two dimensions, and the obtained content is matrix multiplied with the scaled query in the last two dimensions. The result is merged with the middle two dimensions (i.e., from (batch size, 4, 32, feature vector size) to (batch size, 128, feature vector size)) and then enters the convolution layer, with a kernel size of 1, an input channel of 128, and an output channel of the same size as the input feature vector. After convolution, the output vector is RMS normalized. Finally, the output vector is added to the output result of the second residual block to obtain the final output of the multi-head attention mechanism.

[0120] a-15) The downsampling layer part of the downsampling layer contains only one convolution layer, with a convolution kernel size of 4 and a stride of 2. The input channels of the four downsampling layers in the gated recurrent diffusion model are 32, 64, 128, and 256, respectively. The residual block and attention mechanism in the downsampling layer do not change the data shape, while the downsampling part doubles the number of channels and halves the data size. However, in the downsampling part of the fourth downsampling layer, the convolution layer stride is 1, the convolution kernel size is 3, and the data size remains unchanged. The convolution layer output of the downsampling part is the output of the downsampling layer.

[0121] a-16) The middle layer consists of an initial residual block, a gated recurrent unit array, a multi-head attention mechanism, and a final residual block.

[0122] a-17) The initial residual block and the final residual block of the middle layer have the same structure as the residual block in the downsampling layer, and the number of input and output channels is 256.

[0123] a-18) The gated recurrent unit array in the middle layer contains a total of 16 layers of gated recurrent units (GRU) connected in series. The gated recurrent unit includes a reset gate, an update gate, and a hidden state. Its formula can be expressed as:

[0124] zt =Sigmoid(W z ·[h t-1 ,x t ]),

[0125] r t =Sigmoid(W r ·[h t-1 ,x t ]),

[0126]

[0127] where r t represents the reset gate, z t represents the update gate, h t is the hidden state. Data is input into the gated recurrent unit in order starting from x0. The initial hidden state h0 of the gated recurrent unit is a zero vector. The new hidden state is calculated according to the formula. After all data are input, the output is the combination of the hidden states of each step. The output vector of the initial residual block is used as the input vector of the first layer of gated recurrent unit, and the output vector of the first layer of gated recurrent unit is used as the input vector of the second layer of gated recurrent unit, and so on.

[0128] a-19) Figure 5 As shown in the figure, it is the algorithm of the multi-head attention mechanism in the middle layer. Like the linear multi-head attention mechanism in the downsampling layer, the feature vector is first RMS normalized and then enters the convolutional layer (with the same parameters) to be split into query, key, and value. The difference is that in the multi-head attention mechanism in the middle layer, the query is first multiplied by -16 to change its scale, and matrix multiplication is performed with the key in the last two dimensions. The result passes through the normalized exponential function layer, and then matrix multiplication is performed with the value in the last two dimensions. The result is merged with the middle two dimensions and then enters the convolutional layer. The output of the convolutional layer is added to the feature vector before the previous RMS normalization to obtain the final output of the multi-head attention mechanism.

[0129] a-20) The upsampling layer consists of two residual blocks, an attention part and an upsampling part.

[0130] a-21) The residual block structure of the upsampling layer is the same as that of the residual block in the downsampling layer, but the number of output channels of each residual block is different from the number of input channels, so the output of the convolution layer in the residual convolution part is not added to the original data. The reason for the different number of channels is that the input data of the residual block includes not only the original input data, but also the data extracted from the downsampled data stack. The two are concatenated as the input of the residual block. Taking the first upsampling layer as an example, its first residual block receives the output vector of the last residual block of the intermediate layer (size is (batch size, 256, 150)) and the output of the attention part of the last downsampling layer taken out of the stack (size is (batch size, 128, 150)) as input. The size of the concatenated two is (batch size, 384, 150). The output channels are the same as the number of channels of the original input data. For example, the output channels of the residual block in the first upsampling layer are all 256 (the number of output channels of the last downsampling layer).

[0131] a-22) The attention part of the upsampling layer is the same as the attention part of the downsampling layer.

[0132] a-23) The upsampling part of the upsampling layer includes the upsampling function (Up Sample) and the convolution layer. The upsampling function uses the neighboring algorithm to double the data size. Let the original vector be Then the output of the vector after the upsampling function is (x0,x0,x1,x1,…,x n ,x n ). The convolution kernel size of the convolution layer is 3. The input channels of the four upsampling layers in the gated recurrent diffusion model are 256, 128, 64, and 32 respectively. The upsampling part halves the number of channels and doubles the data size. However, in the upsampling part of the fourth upsampling layer, there is only a convolution layer without an upsampling function, and the number of channels and data size remain unchanged. The output of the convolution layer of the upsampling part is the output of the downsampling layer.

[0133] a-24) The output layer consists of a residual block and a convolutional layer. The residual block structure is the same as the residual block in the downsampling layer, and the number of input and output channels is 32. The number of input and output channels of the convolutional layer is 32, and the convolution kernel size is 1.

[0134] 8. Start model training. Take the APB type as an example. Divide 4192 into 42 batches with a batch size of 100, and randomly select a batch.

[0135] 9. Randomly generate a timestamp t between 0 and 499 (i.e., the time step minus one).

[0136] 10. Calculate the noisy data x after each data x0 in the current batch is iterated t times t :

[0137]

[0138] where α t =1-β t ,

[0139] 11. The noisy data x t Input the diffusion model with timestamp t to get the output and calculate the loss Loss = ||∈-∈ θ (x t ,t)|| 2 , perform gradient descent to modify the parameters of the diffusion model. Where ∈ θ (x t ,t) represents the prediction result of the diffusion model, and ∈ represents the random noise that obeys the standard normal distribution.

[0140] 12. Repeat steps 8 to 11 500 times (500 is the number of iterations set in advance).

[0141] 13. Imitate the 8-12 step process to train the diffusion model parameters of VEB and VFW.

[0142] 14. After the diffusion model is trained, the original data set is randomly divided into a test set and a training set in a ratio of 1:4.

[0143] 15. Sampling is performed according to the trained diffusion model to generate new data. Figure 6 The figure shows the sampling process of the diffusion model. The sampling process is as follows:

[0144] b-1) Generate random noise that obeys the standard normal distribution, and set the timestamp t=499.

[0145] b-2) The random noise is used as an input signal and input into the diffusion model together with the timestamp t.

[0146] b-3) Add the output result to the input signal as the new input signal, and decrement the timestamp once.

[0147] b-4) Repeat step 18 until the timestamp is decremented to 0. The output signal at this time is the new data generated by the diffusion model.

[0148] 16. Add the generated new data to the training set of the corresponding category. Repeat the sampling process until the total number of training set data for APB, VEB, and VFW categories reaches 10,000.

[0149] 17. Set the hyperparameters of the classification model. There is no limit on the specific hyperparameters. In this example, the batch size is 100, the number of epochs is 500, the learning rate is 0.001, and the decay rate is 0.95.

[0150] 18. Set the neural network structure of the classification model. Figure 7 The following is a schematic diagram of the classification model structure of the embodiment of the present application. The structure is as follows:

[0151] c-1) The classification model consists of four layers. The first layer includes a combination of 4 convolution blocks and a maximum pooling layer. The second layer includes a fully connected layer, a random dropout layer, a batch normalization layer, and a linear rectifier unit activation function. The third layer is a gated recurrent unit layer. The fourth layer includes a fully connected layer and a normalized exponential function layer.

[0152] c-2) In the first layer, a convolution block contains two sub-blocks and a squeeze-excitation block, which can be controlled by two parameters: the number of input channels and the number of output channels. The number of input channels of the four convolution blocks are 1, 64, 128, 256, and the number of output channels are 64, 128, 256, and 512 respectively.

[0153] c-3) The sub-blocks in the convolution block are composed of a 1D-Convolution Layer, a Batch-Normalization Layer, and a linear rectifier unit activation function. In each sub-block, the kernel size of each 1D convolution layer is 3, the stride is 1, and the padding is 1. The formula for each sub-block can be expressed as: in represents the convolution operator, W conv represents the weight of the convolution kernel, b conv is the bias vector, x i-1 With x i Represent the input and output vectors respectively. The number of input channels and output channels of the one-dimensional convolution layer of the first sub-block is equal to the number of input channels and output channels set by the convolution block, and the number of input channels and output channels of the convolution layer of the second sub-block are both equal to the number of output channels set by the convolution block.

[0154] c-4) The squeeze-excitation block in the convolution block consists of a global max pooling layer, a first fully connected layer, a linear rectifier unit activation function, a second fully connected layer, and a sigmoid activation function. Global max pooling can be expressed as:

[0155] where y mp represents the global maximum pooling value, x mpk Represents the input signal x mp The kth value in L is the input signal x mp Length;

[0156] After the data passes through the first fully connected layer, the number of channels becomes the original Then it passes through the linear rectifier unit activation function,

[0157] It can be expressed as:

[0158] where y mp represents the global maximum pooling value, x mpk Represents the input signal x mp The kth value in L is the input signal x mp length; after the data passes through the first fully connected layer, the number of channels becomes the original Then it passes through the linear rectifier unit activation function, expressed as:

[0159] x s =ReLU(W1x s-1 +b1),

[0160] Where W1 represents the weight of the fully connected layer, b1 is the bias vector, and x s-1 With x s Represent the input and output vectors respectively. After the data passes through the second fully connected layer, the original number of channels is restored and then passes through the S-type activation function, which can be expressed as: e =Sigmoid(W2x e-1 +b2), where W2 represents the weight of the fully connected layer, b2 is the bias vector, and x e-1 With x e Represent the input and output vectors respectively. Finally, the result is used as the weight to multiply the original data before entering the squeeze excitation block to obtain the final result.

[0161] c-5) In the first layer, the one-dimensional maximum pooling can be expressed as: where y i Represents the pooling range R i The maximum pooling output value within, x p Represents R i The element at position p in .

[0162] c-6) Between the first and second layers, the dimension of the data is reduced, and its shape changes from (512, 75) to 38400.

[0163] c-7) In the second layer, the number of input channels of the fully connected layer is 38400 and the number of output channels is 4096. The dropout probability of the random dropout layer in the classification model is 0.5.

[0164] c-8) In the third layer, the gated recurrent unit input size is 4096 and the hidden layer size is 256.

[0165] c-9) In the fourth layer, the number of input channels of the fully connected layer is 256 and the number of output channels is 8. (8 is the number of categories) The formula of the normalized exponential function layer can be expressed as:

[0166] Where p(y c ) is the probability output of the neuron after the normalized exponential function, y c is the output value of the cth neuron in the previous fully connected layer, and m is the number of target categories. In the embodiment of the present application, the normalized exponential function is calculated row by row.

[0167] 19. Use the dataset with diffusion model supplementary data to train the classification model. After training, the classification model can be used in actual application scenarios.

[0168] In the embodiment of the present application, the diffusion model reduces the imbalance of the data set, and combines CNN and GRU, so the comprehensive index of model classification is improved, and the model is more sensitive to abnormal heart rate, thus better meeting clinical requirements. Figure 8 , Fig. 9 As shown in the figure, the ventricular escape ECG signals are generated by the traditional generative model and the gated cyclic diffusion model designed in the embodiment of the present application. Compared with the traditional generative model, the gated cyclic diffusion model designed in the embodiment of the present application can better capture the timing information of the ECG signal, thereby simulating the characteristics of the heart rate. In addition, compared with the common U-Net diffusion model, the gated cyclic diffusion model has fewer parameters and is faster to train. Fig.10 , Fig.11 As shown, the loss function value records of the training process of the traditional generative model and the gated cyclic diffusion model designed in the embodiment of the present application are respectively. The gated cyclic diffusion model designed in the embodiment of the present application can effectively prevent the gradient explosion problem due to the introduction of GRU.

[0169] The present invention introduces a scheme for enhancing the classification of ECG signals by combining a gated recurrent diffusion model, a convolutional neural network (CNN) and a gated recurrent unit (GRU). The gated recurrent diffusion model can generate high-quality abnormal heart rate data, thereby enhancing the model's ability to identify abnormal heart rates. CNN is good at capturing local features of ECG signals, while GRU is better at processing long-term dependencies of time series, and its complexity is lower than LSTM. The combination of the two can better classify ECG signals. Fig.12 , which is a schematic diagram of the performance of the embodiment of the present application on the MIT-BIH database.

[0170] The present invention provides an ECG signal enhancement and classification method based on a gated cyclic diffusion model. There are many methods and approaches to implement the technical solution. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the protection scope of the present invention. All components not specified in this embodiment can be implemented by existing technologies.

Claims

1. A method for enhancing and classifying electrocardiogram signals based on a gated cyclic diffusion model, characterized in that: The following steps are involved: Step 1, obtain the ECG signal data set; Step 2, setting the parameters and hyperparameters of the diffusion model; Step 3, establishing the neural network structure of the diffusion model; Step 4: training the diffusion model and supplementing the ECG signal dataset with the trained diffusion model; Step 5, set the hyperparameters of the classification model; Step 6, establishing a classification model; Step 7: Use the ECG signal data set obtained in step 4 to train a classification model, and use the trained classification model for ECG signal classification.

2. The method according to claim 1, characterized in that In step 3, the diffusion model is a gated recurrent diffusion model, including an initial layer, a time embedding layer, four downsampling layers, an intermediate layer, four upsampling layers and an output layer; The initial layer only includes one one-dimensional convolutional layer.

3. The method according to claim 2, characterized in that In step 3, the time embedding layer accepts a single integer representing a timestamp as input, and the time embedding layer includes a sinusoidal position encoding, a first fully connected layer, a Gaussian error linear unit activation function, and a second fully connected layer; The sinusoidal position encoding is performed as follows: a vector γ is generated, the i-th element of the vector γ is an integer set, exp is the natural exponential function, θ is a settable parameter, and l is the vector length; multiply the input timestamp by the vector γ to get the vector σ, and find the sine and cosine values ​​of each element in the vector σ to get the vectors α and β, that is, α i = sinσ i ,β i =cosσ i , α i is the i-th element of the vector α, β i is the i-th element of vector β. Connecting vectors α and β gives vector λ, where λ is the output of sinusoidal position encoding; The Gaussian error linear unit activation function is represented by GeLU(x G ): where x G A single number representing the input Gaussian error linear unit activation function; The time vector output by the temporal embedding layer will be input into all residual blocks.

4. The method according to claim 3, characterized in that In step 3, the downsampling layer includes two residual blocks, an attention part and a downsampling part. The data in the downsampling layer will be used as input to the upsampling layer. A stack data structure is set. After the first residual block and attention part of each downsampling layer, the current data is saved and stored in the stack. The residual block includes an initial convolution part, a time embedding part, an intermediate convolution part and a residual convolution part; in the downsampling layer, all residual blocks do not change the data shape, the input channel is equal to the output channel, and the number of channels is the same as the number of input data channels of the corresponding downsampling layer; In the residual block of the downsampling layer, the initial convolution part includes the convolution layer and the root mean square normalization layer. The formula for root mean square normalization is: The root mean square function RMSNorm(x R ) represents RMS normalization, g and d represent stretching parameters, e represents offset parameters, ⊙ represents multiplication by position, x R represents the input vector, x Rj For x R Elements in In the residual block of the downsampling layer, the temporal embedding part includes the S-type rectifier unit activation function and the fully connected layer. The formula of the S-type rectifier unit activation function SiLU(x) is: SiLU(x) = x*Sigmoid(x), where x represents a single number input to the S-type rectifier unit activation function; the output channel of the fully connected layer is twice the size of the input feature vector of the residual block; the output of the temporal embedding part is divided into two parts of equal length, which are respectively used as the scaling scale vector and the displacement scale vector. The scaling scale vector is first multiplied one by one with the corresponding elements of the output vector of the initial convolution part to obtain a new vector, and then the new vector is added to the displacement scale vector, and the result is input to the intermediate convolution part; In the residual block of the downsampling layer, the intermediate convolution part includes the S-type rectifier unit activation function, random dropout layer, convolution layer and RMS normalization layer; In the residual block of the downsampling layer, the residual convolution part includes the S-type rectifier unit activation function, the random dropout layer and the convolution layer; when the input and output channels of the residual block are the same, the input data of the convolution layer is retained and added to the output result of the convolution layer as the final output of the residual block; The attention part of the downsampling layer includes pre-RMS normalization and linear multi-head attention mechanism; In the attention part of the downsampling layer, the data is first processed by RMS normalization, and the input feature vector first enters the convolution layer, and the input dimension of the convolution layer is kept the same as the input feature vector size; in the gated recurrent diffusion model, the number of multi-head attention mechanism heads is 4, and the dimension of a single head is 32, that is, the shape of the query, key, and value tensors is (batch size, 4, 32, feature vector size); the output channel of the convolution layer is 4×32×3=384; the output of the convolution layer is divided into three parts, as the query Q, key K, and value V of the attention mechanism, which are used to calculate the attention weight and generate the final output; first, the query and key are normalized and The exponential function layer is used to multiply each element in the query by -16. The key and value after the normalized exponential function layer are matrix multiplied in the last two dimensions, and the obtained content is matrix multiplied with the scaled query in the last two dimensions. The result is merged with the middle two dimensions, that is, (batch size, 4, 32, feature vector size) is changed to (batch size, 128, feature vector size) and then enters the convolution layer. The input channel is 128, and the output channel is the same as the input feature vector size. After convolution, the output vector is root mean square normalized. Finally, the output vector is added to the output result of the second residual block to obtain the final output of the multi-head attention mechanism. The downsampling layer part of the downsampling layer contains only one convolutional layer; The number of input channels of the four downsampling layers in the gated recurrent diffusion model are 32, 64, 128, and 256 respectively; the residual block and attention mechanism in the downsampling layer do not change the data shape, and the downsampling part doubles the number of channels and halves the data size; in the downsampling part of the fourth downsampling layer, the data size remains unchanged; the convolutional layer output of the downsampling part is the output of the downsampling layer.

5. The method according to claim 4, characterized in that In step 3, the intermediate layer includes an initial residual block, a gated recurrent unit array, a multi-head attention mechanism and a final residual block; The initial residual block and the final residual block of the intermediate layer have the same structure as the residual block in the downsampling layer; The gated recurrent unit array of the middle layer includes a total of 16 layers of gated recurrent units connected in series. The gated recurrent unit includes a reset gate, an update gate and a hidden state, and the formula is expressed as follows: z t =Sigmoid(W z ·[h t-1 ,x t ]), r t =Sigmoid(W r ·[h t-1 ,x t ]), where r t represents the reset gate, z t represents the update gate, h t is the hidden state, W z , W r , W h is the weight, represents the candidate hidden state, h t-1 represents the hidden state at the previous moment, x t is the input at the current moment, and x0 is the input at the initial moment; data is sequentially input into the gated recurrent unit starting from x0, and the initial hidden state h0 of the gated recurrent unit is a zero vector; the new hidden state is calculated according to the formula, and after all the data are input, the output is the combination of the hidden states of each step, and the output vector of the initial residual block is used as the input vector of the first layer of gated recurrent unit, and the output vector of the first layer of gated recurrent unit is used as the input vector of the second layer of gated recurrent unit; The multi-head attention mechanism of the intermediate layer includes: the feature vector is firstly subjected to pre-root mean square normalization, and then enters the convolutional layer to be divided into query, key, and value; The number of heads of the multi-head attention mechanism is 4, and the dimension of a single head is 32, that is, the shape of the query, key, and value tensors is (batch size, 4, 32, feature vector size); first, the query is multiplied by -16 to change the scale, and matrix multiplication is performed with the key on the last two dimensions. The result passes through the normalized exponential function layer, and then matrix multiplication is performed with the value on the last two dimensions, and the middle two dimensions are merged, that is, from (batch size, 4, 32, feature vector size) to (batch size, 128, feature vector size) and then enters the convolution layer. The output of the convolution layer is added to the feature vector before the pre-root mean square normalization to obtain the final output of the multi-head attention mechanism.

6. The method according to claim 5, characterized in that In step 3, the upsampling layer includes two residual blocks, an attention part and an upsampling part; The residual block structure of the upsampling layer is the same as the residual block in the downsampling layer, but the number of output channels of each residual block is different from the number of input channels, so the output of the convolution layer in the residual convolution part is not added to the original data; the input data of the residual block includes the data extracted from the downsampled data stack in addition to the original input data, and the original input data and the data extracted from the downsampled data stack are connected as the input of the residual block; The attention part of the upsampling layer is the same as the attention part of the downsampling layer; The upsampling part of the upsampling layer includes an upsampling function and a convolution layer. The upsampling function uses a neighbor algorithm to double the data size. Suppose the original vector is represents a natural number, n represents the length of the original vector, x0,x1,…,x n-1 represents the n elements in the original vector; then (x0, x1, …, x n )The output of the upsampling function is (x0,x0,x1,x1,…,x n ,x n ); The input channel numbers of the four upsampling layers in the gated recurrent diffusion model are 256, 128, 64, and 32 respectively; the upsampling part reduces the number of channels by half and doubles the data size; in the upsampling part of the fourth upsampling layer, there is only a convolutional layer without an upsampling function, and the number of channels and data size remain unchanged; the output of the convolutional layer of the upsampling part is the output of the upsampling layer.

7. The method according to claim 6, characterized in that In step 3, the output layer includes a residual block and a convolutional layer; the structure of the residual block is the same as the residual block in the downsampling layer.

8. The method according to claim 7, characterized in that Step 4 includes: Step 4-1, divide the ECG signal dataset into X1 batches according to the batch size, and randomly select a batch; Step 4-2, randomly generate a timestamp t; Step 4-3: Calculate the noisy data x after each data x0 in the current batch is iterated t times t : where β t represents the noise ratio parameter after iteration t times, α t =1-β t , α t represents the signal ratio parameter after t iterations, represents the cumulative signal ratio parameter after iteration t times, q(x t |x0) indicates the noisy data x when the known data x0 is present t The probability distribution of represents normal distribution, I represents the identity matrix; Step 4-4, the noisy data x t Input the diffusion model with timestamp t to get the output and calculate the loss Loss = ||∈-∈ θ (x t ,t)|| 2 , perform gradient descent to modify the parameters of the diffusion model; where ∈ θ (x t ,t) represents the prediction result of the diffusion model, ∈ represents the random noise that obeys the standard normal distribution; Step 4-5, repeat step 4-1 to step 4-4 process X2 times; Step 4-6: After the diffusion model is trained, the ECG signal dataset is randomly divided into a test set and a training set in proportion; Step 4-7, sampling according to the trained diffusion model to generate new data, includes the following steps: Step 4-7-1, generate random noise that obeys the standard normal distribution and set the timestamp t; Step 4-7-2, random noise is used as an input signal and input into the diffusion model together with the timestamp t; Step 4-7-3, add the output result of the diffusion model to the input signal as a new input signal, and decrement the timestamp once; Step 4-7-4, repeat X3 steps until the timestamp is decremented to 0, and the output signal at this time is the new data generated by the diffusion model; Steps 4-8: Add the generated new data to the training set of the corresponding category.

9. The method according to claim 8, characterized in that Step 6 includes: the classification model includes four layers, the first layer includes 4 convolution blocks and a maximum pooling layer; the second layer includes a fully connected layer, a random dropout layer, a batch normalization layer and a linear rectifier unit activation function; the third layer is a gated recurrent unit layer; the fourth layer includes a fully connected layer and a normalized exponential function layer; In the first layer, a convolutional block contains two sub-blocks and a squeeze-and-excite block; The sub-blocks in the convolution block include a one-dimensional convolution layer, a batch normalization layer, and a linear rectifier unit activation function; the formula for each sub-block is expressed as: in represents the convolution operator, W conv represents the weight of the convolution kernel, b conv is the bias vector, x i-1 With x i Represent the input vector and output vector respectively, BN represents batch normalization; the number of input channels and output channels of the one-dimensional convolution layer of the first sub-block are equal to the number of input channels and output channels set by the convolution block, and the number of input channels and output channels of the convolution layer of the second sub-block are equal to the number of output channels set by the convolution block; The squeeze-excitation block in the convolution block includes a global maximum pooling layer, a first fully connected layer, a linear rectifier unit activation function, a second fully connected layer, and a sigmoid activation function; the global maximum pooling is expressed as: where y mp represents the global maximum pooling value, x mpk Represents the input signal x mp The kth value in L is the input signal x mp length; after the data passes through the first fully connected layer, the number of channels becomes the original Then it passes through the linear rectifier unit activation function, expressed as: x s =ReLU(W1x s-1 +b1), Where W1 represents the weight of the fully connected layer, b1 is the bias vector, and x s-1 With x s Represent the input vector and output vector respectively; after the data passes through the second fully connected layer, the original number of channels is restored and then passes through the S-type activation function, which is expressed as: x e =Sigmoid(W2x e-1 +b2), where W2 represents the weight of the fully connected layer, b2 is the bias vector, and x e-1 With x e Represent the input vector and output vector respectively; finally, the result is used as the weight to multiply the original data before entering the squeeze excitation block to obtain the final result; In the first layer, the one-dimensional maximum pooling is expressed as: where y i Represents the pooling range R i The maximum pooling output value within, x p Represents R i The element at position p in Between the first and second layers, the dimension of the data is reduced, and the shape changes from (batch size, number of feature maps, data size) to (batch size, number of feature maps * data size); In the second layer, the number of input channels of the fully connected layer is the number of feature maps * data size; In the third layer, the gated recurrent unit input size is equal to the number of output channels in the second layer; In the fourth layer, the number of input channels of the fully connected layer is equal to the number of hidden layers of the gated recurrent unit, and the number of output channels is the number of classifications; the formula of the normalized exponential function layer is: Where p(y c ) is the probability output of the neuron after the normalized exponential function, y c is the output value of the cth neuron in the previous fully connected layer, and m is the number of target categories.

10. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores program codes, and when the program codes are executed by the processor, the processor executes the steps of the method according to any one of claims 1 to 9.

Citation Information

Patent Citations

  • Arrhythmia classification method based on convolutional neural network and gating circulation unit

    CN113768514A

  • Pulse signal recognition method and device based on recurrent neural network and storage medium

    CN115067894A

  • Electromagnetic signal modulation classification method and device based on diffusion model

    CN118296302A

Cited By

  • Arrhythmia classification method and device based on multi-mode diffusion model, and medium

    CN120067836A