Electrocardiogram data generation method based on auxiliary classifier generative adversarial network
By introducing an auxiliary classifier to generate an adversarial network in the generation of electrocardiogram data, using self-attention and spatio-temporal feature extraction modules, the problem of insufficient quality and diversity of electrical data generation in the existing technology is solved, and the generation effect of electrocardiogram data is significantly improved , improves the performance of the ECG intelligent assisted diagnostic model.
Patent Information
- Application Number
- CN202410995674.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-12
AI Technical Summary
The existing ECG data generation methods have low quality, incomplete categories, and have failed to fully utilize the spatiotemporal characteristics of multi-lead ECG data, resulting in insufficient diversity and quantity of generated data, affecting the performance of the ECG intelligent auxiliary diagnostic model.
Using an auxiliary classifier-based generation of adversarial networks (AC-GAN), the generator and discriminator are designed by introducing self-attention mechanisms and spatiotemporal features, combining long and short-term memory networks, Transformer self-attention modules and causal convolution modules. Focus on the key spatiotemporal characteristics of the electrocardiogram and generate ECG data that meets specific conditions.
It significantly improves the quality and diversity of electrocardiogram data generation, enhances the objective and practicality of the data, and improves the performance of the intelligent auxiliary diagnostic model of electrocardiogram.
Smart Images

Figure CN118942677A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of medical data processing and artificial intelligence, and in particular to a method for generating electrocardiogram data based on auxiliary classifier generative adversarial networks (AC-GAN). Background Art
[0002] Electrocardiogram (ECG) is an important means to detect heart health and is widely used in clinical diagnosis. However, ECG data usually has the characteristics of high dimensionality, strong noise and sample imbalance, which makes machine learning models based on ECG data face challenges in the training process. In order to improve the quality and quantity of ECG data, data generation technology is widely used. Traditional strong data generation methods (such as random noise addition, translation, rotation, etc.) often lack a deep understanding of the characteristics of ECG data and cannot effectively improve model performance. Generative Adversarial Network (GAN), as a powerful data generation model, can generate high-quality synthetic data through adversarial training of generators and discriminators. However, when generating ECG data, classic GAN is prone to mode collapse and insufficient diversity. At the same time, existing methods do not fully consider the spatiotemporal characteristics of multi-lead ECG data and do not focus on the key features in multi-lead ECG data.
[0003] The invention patent with application number CN202111321899.3 and titled "Emotional EEG Data Enhancement Model and Sample Expansion Method Based on Generative Adversarial Network" discloses an electrical data enhancement model and sample expansion method, which maps the emotional EEG topology map to the latent space, inputs the latent vector into the generator, and learns the spatial distribution of the emotional EEG topology map through the latent vector. The generative adversarial network corresponding to the model has two discriminators and one generator. Both discriminators are composed of neural networks with the same structure but do not share parameters; one of the discriminators gives high score rewards to samples that conform to the distribution of real data; the other discriminator gives high score rewards to samples generated by the generator; through the game between the generator and the two discriminators, the distribution of synthetic samples generated by the generator is infinitely close to the distribution of real data. Auxiliary Classifier Generative Adversarial Network (AC-GAN) can further control the category of generated data and improve the quality and diversity of generated data by introducing auxiliary classifiers. The emotional EEG data enhancement model proposed in this invention combines variational autoencoders and generative adversarial networks to give full play to their respective advantages and generate better diversity of samples. However, this method cannot directly generate data of a specified type, and does not involve the prior knowledge of that type of data in the generation process of new data. The data quality needs to be further improved. Summary of the invention
[0004] The purpose of the present invention is to provide an ECG data generation method based on an auxiliary classifier generative adversarial network, which can solve the problems of low quality and incomplete categories of ECG data generated by existing data generation methods, effectively improve the quality of ECG data generation, and increase the diversity and quantity of ECG data sets, thereby improving the performance of ECG intelligent auxiliary diagnosis model.
[0005] The present invention adopts the following technical solutions:
[0006] A method for generating electrocardiogram data based on an auxiliary classifier generative adversarial network comprises the following steps in sequence:
[0007] A: Get different types of ECG data samples;
[0008] B: Introduce the prior knowledge of the corresponding type of ECG data into the construction of the generator based on the self-attention mechanism and the discriminator based on spatiotemporal features, focus on and highlight the key spatiotemporal features of different types of ECG data, and obtain a generative adversarial network model based on the auxiliary classifier;
[0009] C: Design the discriminator loss function and the generator loss function, and train the auxiliary classifier-based generative adversarial network model based on different types of ECG data samples to obtain the trained auxiliary classifier-based generative adversarial network model;
[0010] D: Use the trained auxiliary classifier-based generative adversarial network model to expand and process different types of ECG data samples.
[0011] In the step B, the generator based on the self-attention mechanism takes the vector A containing random noise z and the category label label as input, and generates the ECG data corresponding to the category label label, i.e., the vector Z, as output;
[0012] The generator based on the self-attention mechanism includes a long short-term memory network module, a Transformer-based self-attention module and a causal convolution module; the causal convolution module and the long short-term memory network module are used to obtain the spatial representation information of the electrocardiogram and the time information of each heartbeat sampling point respectively, and the Transformer-based self-attention module is used to assign attention weights to the acquired spatial representation information and time information representation.
[0013] The long short-term memory network module transforms the vector A into a vector X t As input, generate a vector H containing the short-term and long-term temporal dependencies of the ECG data to be generated t As output; H t =LSTM(X t ), LSTM represents the long short-term memory network module; the long short-term memory network module is used to characterize the complexity of ECG data of different leads and obtain the time information of each heartbeat sampling point of the ECG;
[0014] The Transformer-based self-attention module transforms the vector H t As input, generate a vector A containing the relationship between any time steps of the ECG data to be generated and the importance of the time steps t As output; the Transformer-based self-attention module is used to capture the long-range dependencies of ECG data with time series characteristics, and adaptively assign attention weights to the information representation of the ECG;
[0015] The causal convolution module transforms the vector A t As input, a vector Z is generated as output; the causal convolution module is used to introduce dilated convolution to expand the receptive field of the ECG data and capture the spatial representation information of the ECG.
[0016] First, the self-attention module pays attention to the vector H t Perform linear transformation to generate query vector Q, key vector K and value vector V respectively; where Q = W q H t +b q , K=W k H t +b k, V=W v H t +b v ; W q , W k and W v Respectively represent the weight matrices corresponding to the query vector Q, key vector K and value vector V; b q 、b k and b v They represent the biases corresponding to the query vector Q, key vector K, and value vector V respectively;
[0017] Then, the self-attention module calculates the attention score score(Q,K) based on the query vector Q and the key vector K. score(Q,K)=Q·K T , where T represents the transposed symbol in the matrix;
[0018] Then, the self-attention module converts the attention score score(Q,K) into an attention weight distribution through the Softmax function to obtain the query vector Q i Key vector K j The attention weight a ij , Where i represents the i-th query vector, j represents the j-th key vector, and T1 represents the total number of key vectors;
[0019] Afterwards, the self-attention module uses the attention weight a ij Perform a weighted summation on the value vector V and obtain the corresponding attention output: Where k represents the kth value vector, and T2 represents the total number of value vectors;
[0020] Finally, the self-attention module transforms the attention output linearly to obtain the output vector A of the Transformer-based self-attention module. t .
[0021] In the step B, the discriminator based on spatiotemporal features takes the ECG data G as input, and generates the probability Dreal that the input is the real ECG data and the probability Dclass that the input is the corresponding class label;
[0022] The discriminator based on spatiotemporal features includes a convolutional neural network discrimination module based on spatial features, a bidirectional long short-term memory network module based on temporal features, an ECG data authenticity discrimination module and an ECG data category discrimination module; the discriminator based on spatiotemporal features is used to simultaneously process the dynamic changes of the heartbeat in the lead and the spatial relationship between multiple leads, and to judge the authenticity of the generated ECG data and the rationality of the time series features.
[0023] The convolutional neural network discrimination module based on spatial features takes the ECG data G as input, generates a vector H containing spatial feature information representing the input ECG data as output; the convolutional neural network discrimination module based on spatial features is used to judge the accuracy and rationality of the generated ECG data spatial information representation;
[0024] The bidirectional long short-term memory network module based on time characteristics takes the vector H as input, generates a vector L containing information representing the time series characteristics of the ECG data as output; the bidirectional long short-term memory network module based on time characteristics is used to determine the accuracy and rationality of the representation of the time information of the generated ECG data;
[0025] The ECG data authenticity determination module takes the vector L as input, generates the probability Dreal that the input is the real ECG data and outputs it; the ECG data authenticity determination module is used to determine the authenticity of the generated ECG data;
[0026] The ECG data category discrimination module takes the vector L as input, generates the probability Dclass of the input corresponding to the category label as output; the ECG data category discrimination module is used to generate the probability of the input corresponding to the category label.
[0027] The design method of the discriminator loss function is as follows:
[0028] C11: Input the real ECG data R into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_real and the category probability output class_real of the real ECG data R; then input class_real and the label of the real ECG data R into the cross entropy loss function to obtain the category loss class_error_real of the real ECG data;
[0029] C12: Random sampling generates random pseudo ECG data S with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution. The corresponding category label is noise_label;
[0030] C13: Input the random fake ECG data S into the generator based on the self-attention mechanism to obtain the fake ECG data fake_data;
[0031] C14: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_fake and the category probability output class_fake of the random fake ECG data S, input the authenticity probability output class_fake and the category label noise_label into the cross entropy loss function to obtain the category loss class_error_fake of the random fake ECG data;
[0032] C15: The discriminator loss function D_loss is: D_loss = class_error_real + class_error_fake. Combined with the Adam optimizer, the gradient of the discriminator parameters is calculated according to the loss function D_loss, and the parameters are updated.
[0033] The design method of the generator loss function is as follows:
[0034] C21: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features again to obtain the authenticity probability output source and category probability output class of the new random fake ECG data S, input the category probability output class and category label noise_label into the cross entropy loss function to obtain the category loss class_error of the random fake ECG data, and calculate the mean value of the authenticity probability output source to obtain source_error;
[0035] C22: The generator loss function G_loss is: G_loss = class_error + source_error. Combined with the Adam optimizer, the gradient of the generator parameters is calculated according to the loss function G_loss, and the parameters are updated.
[0036] The step D comprises the following specific steps:
[0037] D1: Random sampling generates random pseudo ECG data T with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution, and generates the specified category label new_label;
[0038] D2: Concatenate the random fake ECG data T and the specified category label new_label to generate a vector U, input the vector U into the generator trained based on the self-attention mechanism, and output the multi-lead ECG data with the specified category label, thus completing the expansion of the ECG data samples of the specified category.
[0039] The present invention can directly generate qualified electrocardiogram data according to specific conditions (such as the types of electrocardiogram heart beats of different arrhythmias / electrocardiograms of different infarction lesion locations / electrocardiograms of different infarction onset periods) by introducing an auxiliary classifier to generate adversarial networks. The above method allows the prior knowledge in the database to participate in the generation process, and can directly generate highly relevant electrocardiogram data for specific conditions, significantly improving the target and practicality of data generation.
[0040] In the present invention, the generator used includes a long short-term memory network (LSTM) layer, a Transformer-based self-attention layer and a causal convolution layer; wherein the causal convolution layer expands the receptive field of the electrocardiogram data by introducing dilated convolution, and only uses current and past data when performing convolution operations, and does not introduce future information; the LSTM layer can capture the complexity of the electrocardiogram data and obtain the timing characteristics of the heartbeat sampling points; the Transformer-based self-attention layer highlights the key features in the electrocardiogram data through the attention mechanism, helping the model focus on information that is critical to classification or prediction, and improving the accuracy and relevance of the generated data.
[0041] The present invention adds a spatiotemporal feature extraction layer in the discriminator, which can simultaneously process the dynamic changes of the heartbeat in the lead and the spatial relationship between multiple leads, so as to accurately judge the authenticity of the generated ECG data and the rationality of the time series characteristics, and ensure the temporal continuity and logic of the generated ECG. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0043] The present invention is described in detail below with reference to the accompanying drawings and embodiments:
[0044] like Figure 1 As shown, the method for generating ECG data based on auxiliary classifier generative adversarial network of the present invention comprises the following steps in sequence:
[0045] A: Get different types of ECG data samples;
[0046] In the present invention, taking the generation of myocardial infarction ECG data as an example, the types of ECG data samples include inferior wall myocardial infarction, anterior wall myocardial infarction, anterior septal wall myocardial infarction, extensive anterior wall myocardial infarction and high lateral wall myocardial infarction, etc.; taking the generation of arrhythmia ECG data as an example, the types of ECG data samples include atrial premature beats, ventricular premature beats, atrial fibrillation, atrial flutter, sinoatrial block, atrioventricular block, left bundle branch block and right bundle branch block, etc.
[0047] B: Introduce the prior knowledge of the corresponding type of ECG data into the construction of the generator based on the self-attention mechanism and the discriminator based on spatiotemporal features, focus on and highlight the key spatiotemporal features of different types of ECG data, and construct a generative adversarial network model based on the auxiliary classifier;
[0048] In the present invention, the generator based on the self-attention mechanism takes the vector A containing random noise z and the category label label as input, and generates the electrocardiogram data corresponding to the category label label, i.e., the vector Z, as output;
[0049] Among them, the dimension of z is (points, leads, 1), the dimension of label is (points, 1, 1), the dimension of the input vector A is (points, leads+1, 1), and the dimension of the output vector Z is (points, leads, 1); points represents the number of sampling points of a single lead ECG data, which can be 1000, leads represents the number of ECG leads, which can be 12; there are c types of category labels in total, and the value of label is an element in the set {0, 1, 2, ·…·, c-1}.
[0050] In the present invention, the generator based on the self-attention mechanism includes a long short-term memory network module, a Transformer-based self-attention module and a causal convolution module; the causal convolution module and the long short-term memory network module are used to respectively obtain the spatial representation information of the electrocardiogram and the time information of each heartbeat sampling point, and the Transformer-based self-attention module is used to assign attention weights to the acquired spatial representation information and time information representation; the three modules complement each other to improve the accuracy and relevance of the generated data.
[0051] The long short-term memory network module transforms the vector A into a vector X t As input, generate a vector H containing the short-term and long-term temporal dependencies of the ECG data to be generated t As output; H t =LSTM(X t ), LSTM represents the long short-term memory network module; the hidden layer feature number hidden_size1 of the long short-term memory network module can be 100, and the input vector X t The dimension is (points, 1, leads + 1), and the output vector H t The dimension is (points, 1, hidden_size1); the long short-term memory network module can characterize the complexity of ECG data of different leads and obtain the time information of each heartbeat sampling point of the ECG.
[0052] The Transformer-based self-attention module transforms the vector H t As input, generate a vector A containing the relationship between any time steps of the ECG data to be generated and the importance of the time steps t As output; where vector A tThe dimension is (points, 1, embed_size); embed_size is 100; the number of heads of the multi-head attention mechanism is 4. The Transformer-based self-attention module can capture the long-range dependency of ECG data with time series characteristics, and can adaptively assign attention weights to the information representation of the ECG, thereby more effectively extracting important features of the ECG.
[0053] In this embodiment:
[0054] The self-attention module firstly t Perform linear transformation to generate query vector Q, key vector K and value vector V respectively;
[0055] Where Q = W q H t +b q , K=W k H t +b k , V=W v H t +b v ; W q , W k and W v Respectively represent the weight matrices corresponding to the query vector Q, key vector K and value vector V; b q 、b k and b v They represent the biases corresponding to the query vector Q, key vector K, and value vector V respectively;
[0056] Then, the self-attention module calculates the attention score score(Q,K) based on the query vector Q and the key vector K. score(Q,K)=Q·K T , where T represents the transposed symbol in the matrix.
[0057] Then, the self-attention module converts the attention score score(Q,K) into an attention weight distribution through the Softmax function to obtain the query vector Q i Key vector K j The attention weight a ij , Among them, i represents the i-th query vector, j represents the j-th key vector, and T1 represents the total number of key vectors.
[0058] Afterwards, the self-attention module uses the attention weight a ij Perform a weighted summation on the value vector V and obtain the corresponding attention output:
[0059]
[0060] Where k represents the kth value vector, T2 represents the total number of value vectors. The final attention output is the weighted sum of all value vectors.
[0061] Finally, the self-attention module transforms the attention output linearly to obtain the output vector A of the Transformer-based self-attention module. t .
[0062] The causal convolution module transforms the vector A t As input, it generates a vector Z as output; the dimension of the output vector Z is (points, leads, 1). The causal convolution module expands the receptive field of the ECG data by introducing dilated convolution. At the same time, it only uses the current and past ECG data during the convolution operation, and does not introduce future information, which can more accurately capture the spatial representation information of the ECG.
[0063] In this embodiment, the causal convolution module includes two one-dimensional dilated convolution layers, three batch normalization layers, three ReLU layers and two one-dimensional deconvolution layers.
[0064] Among them, the one-dimensional expansion convolution layer contains B convolution kernels, the size of the convolution kernel is C×1, the expansion factor is D, the first one-dimensional expansion convolution layer B value is 100, C value is 5, D value is 2; the second one-dimensional expansion convolution layer B value is 250, C value is 3, D value is 4;
[0065] The one-dimensional deconvolution layer contains E convolution kernels, and the size of the convolution kernel is F×1; the value of E in the first one-dimensional deconvolution layer is 100, and the value of F is 1; the value of E in the second one-dimensional deconvolution layer is 12, and the value of F is 1.
[0066] Vector A t The first convolution feature is obtained by sequentially passing through the first one-dimensional expansion convolution layer, the first batch normalization layer and the first Relu layer; the first convolution feature is sequentially passing through the second one-dimensional expansion convolution layer, the second batch normalization layer and the second Relu layer to obtain the second convolution feature; the second convolution feature is sequentially passing through the first one-dimensional deconvolution layer, the third batch normalization layer and the third Relu layer to obtain the first deconvolution feature; the first deconvolution feature is finally passed through the second one-dimensional deconvolution layer to obtain the output vector Z of the causal convolution module; Z = CausalConv(A t ), where CausalConv represents the causal convolution operation;
[0067] The discriminator based on spatiotemporal features takes the ECG data G as input, and generates the probability Dreal that the input is the real ECG data and the probability Dclass that the input is the corresponding class label; wherein the dimension of the ECG data G is (points, leads, 1), the dimension of the probability Dreal is (points, 1), and the dimension of the probability Dclass is (points, c);
[0068] The discriminator based on spatiotemporal features can simultaneously process the dynamic changes of heartbeats in the leads and the spatial relationship between multiple leads by adding a spatiotemporal feature extraction layer, so as to accurately judge the authenticity of the generated ECG data and the rationality of the time series features, ensuring the temporal continuity and logic of the generated ECG.
[0069] In the present invention, the discriminator based on spatiotemporal features includes a convolutional neural network discriminant module based on spatial features, a bidirectional long short-term memory network module based on temporal features, an ECG data authenticity discriminant module, and an ECG data category discriminant module;
[0070] The spatial feature-based convolutional neural network discrimination module takes the ECG data G as input, generates a vector H containing spatial feature information representing the input ECG data as output; wherein the dimension of the vector H is (points, outputs, 1), and the value of outputs is 60.
[0071] The convolutional neural network discrimination module based on spatial features is used to judge the accuracy and rationality of the spatial information representation of the generated ECG data.
[0072] In this embodiment, the convolutional neural network discrimination module based on spatial features includes four one-dimensional convolutional layers, four batch normalization layers and three ReLU layers.
[0073] Among them, the one-dimensional convolution layer contains J convolution kernels, the size of the convolution kernel is I×1, the number J of the four one-dimensional convolution layers is 100, 250, 125 and 60 respectively, and the corresponding I value is 1;
[0074] The ECG data G is sequentially processed by the first batch normalization layer, the first one-dimensional convolution layer and the first Relu layer to obtain the first one-dimensional convolution feature; the first one-dimensional convolution feature is sequentially processed by the second batch normalization layer, the second one-dimensional convolution layer and the second Relu layer to obtain the second one-dimensional convolution feature; the second one-dimensional convolution feature is sequentially processed by the third batch normalization layer, the third one-dimensional convolution layer and the third Relu layer to obtain the third one-dimensional convolution feature; the third one-dimensional convolution feature is sequentially processed by the fourth batch normalization layer and the fourth one-dimensional convolution layer to obtain the output H of the convolutional neural network discrimination module based on spatial features;
[0075] H=Conv1D(G), where Conv1D represents a convolution operation based on spatial features.
[0076] The bidirectional long short-term memory network module based on time features takes the vector H as input, generates a vector L containing information representing the temporal features of the ECG data as output; wherein the dimension of the vector L is (points, hidden_size2×2, 1); wherein hidden_size2 is the number of hidden layer features of the long short-term memory network module, and the value of hidden_size2 can be 30.
[0077] The bidirectional long short-term memory network module based on time features is used to judge the accuracy and rationality of the temporal information representation of the generated ECG data.
[0078] The ECG data authenticity determination module takes the vector L as input, generates a probability Dreal that the input is real ECG data and outputs it;
[0079] In this embodiment, the ECG data authenticity discrimination module consists of two fully connected layers, wherein the first fully connected layer contains hidden_size3 hidden nodes, and the second fully connected layer contains hidden_size4 hidden nodes. Vector L is obtained by the first fully connected layer containing hidden_size3 hidden nodes to obtain vector M, and the dimension of vector M is (points, hidden_size3); vector M is finally obtained by the second fully connected layer containing hidden_size4 hidden nodes to obtain the probability Dreal that the input is real ECG data, and it is used as the output; wherein hidden_size3 takes the value of 30, and hidden_size4 takes the value of 1.
[0080] The ECG data category discrimination module takes the vector L as input, generates the probability Dclass of the input corresponding to the category label as output;
[0081] In this embodiment, the ECG data classification module consists of a fully connected layer and a softmax layer, wherein the fully connected layer contains c hidden nodes. The vector L is passed through the fully connected layer containing c hidden nodes to obtain the vector P, and the dimension of the vector P is (points, c); the vector P is then passed through the softmax layer to obtain the probability Dclass of the corresponding category label as the input, and used as the output; the role of the softmax layer is to convert the output of the fully connected layer into the probability of the corresponding category label.
[0082] Finally, based on the specially designed generator based on the self-attention mechanism and the discriminator based on spatiotemporal features, a generative adversarial network model based on the auxiliary classifier was constructed;
[0083] C: Design the discriminator loss function and the generator loss function, and train the auxiliary classifier-based generative adversarial network model based on different types of ECG data samples to obtain the trained auxiliary classifier-based generative adversarial network model;
[0084] The design method of the discriminator loss function is as follows:
[0085] C11: Input the real ECG data R into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_real and the category probability output class_real of the real ECG data R; then input class_real and the label of the real ECG data R into the cross entropy loss function to obtain the category loss class_error_real of the real ECG data;
[0086] C12: Random sampling generates random fake ECG data S with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution. The dimension of the randomly generated fake ECG data S is (points, leads, 1), and the corresponding category label is noise_label, and the dimension of the category label is (points, 1, 1);
[0087] C13: Input the random fake ECG data S into the generator based on the self-attention mechanism to obtain the fake ECG data fake_data. The dimension of the fake ECG data fake_data is (points, leads, 1).
[0088] C14: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_fake and the category probability output class_fake of the random fake ECG data S, input the authenticity probability output class_fake and the category label noise_label into the cross entropy loss function to obtain the category loss class_error_fake of the random fake ECG data;
[0089] C15: The discriminator loss function D_loss is: D_loss = class_error_real + class_error_fake. Combined with the Adam optimizer, the gradient of the discriminator parameters is calculated according to the loss function D_loss, and the parameters are updated.
[0090] The design method of the generator loss function is as follows:
[0091] C21: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features again to obtain the authenticity probability output source and category probability output class of the new random fake ECG data S, input the category probability output class and category label noise_label into the cross entropy loss function to obtain the category loss class_error of the random fake ECG data, and calculate the mean value of the authenticity probability output source to obtain source_error;
[0092] C22: The generator loss function G_loss is: G_loss = class_error + source_error. Combined with the Adam optimizer, the gradient of the generator parameters is calculated according to the loss function G_loss, and the parameters are updated.
[0093] In step C, by alternately training the generator based on the self-attention mechanism and the discriminator based on the spatiotemporal features, the optimal auxiliary classifier-based generative adversarial network model is obtained as the trained auxiliary classifier-based generative adversarial network model.
[0094] D: Use the trained auxiliary classifier-based generative adversarial network model to expand and process different types of ECG data samples.
[0095] In the step D, the method for expanding different types of ECG data samples is as follows:
[0096] D1: Random sampling generates random pseudo ECG data T with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution. The dimension of the random pseudo ECG data T is (points, leads, 1); Generate a specified category label new_label. The dimension of the category label new_label is (points, 1, 1). All elements in new_label are of the same category, that is, they are all 0, 1, 2, ·…· or c-1;
[0097] D2: Concatenate the random fake ECG data T and the specified category label new_label to generate a vector U with a dimension of (points, leads+1, 1). Input the vector U into the generator trained based on the self-attention mechanism, and output the multi-lead ECG data with the specified category label. The dimension of the multi-lead ECG data is (points, leads, 1), and finally complete the expansion of the ECG data samples of the specified category.
[0098] The present invention, by introducing an auxiliary classifier to generate an adversarial network, can directly generate ECG data that meets the conditions according to specific conditions (such as the types of ECG heart beats of different arrhythmias / ECGs of different infarction lesion locations / ECGs of different infarction onset periods). The above method allows the prior knowledge in the database to participate in the generation process, and can directly generate highly relevant ECG data for specific conditions, significantly improving the target and practicality of data generation.
[0099] In the present invention, the generator used includes a long short-term memory network (LSTM) layer, a Transformer-based self-attention layer, and a causal convolution layer; wherein,
[0100] Causal convolution layer: The receptive field of the ECG data is expanded by introducing dilated convolution. At the same time, only current and past data are used during the convolution operation, and no future information is introduced.
[0101] LSTM layer: captures the complexity of ECG data and obtains the timing characteristics of heartbeat sampling points.
[0102] The Transformer-based self-attention layer highlights the key features in the ECG data through the attention mechanism, helping the model focus on information that is crucial for classification or prediction, and improving the accuracy and relevance of the generated data.
[0103] The present invention adds a spatiotemporal feature extraction layer to the discriminator, which can simultaneously process the dynamic changes of the heartbeat in the lead and the spatial relationship between multiple leads, so as to accurately judge the authenticity of the generated ECG data and the rationality of the time series characteristics, and ensure the temporal continuity and logic of the generated ECG.
Claims
1. A method for generating electrocardiogram data based on auxiliary classifier generative adversarial network, characterized in that: The following steps are included in sequence: A: Get different types of ECG data samples; B: Introduce the prior knowledge of the corresponding type of ECG data into the construction of the generator based on the self-attention mechanism and the discriminator based on spatiotemporal features, focus on and highlight the key spatiotemporal features of different types of ECG data, and obtain a generative adversarial network model based on the auxiliary classifier; C: Design the discriminator loss function and the generator loss function, and train the auxiliary classifier-based generative adversarial network model based on different types of ECG data samples to obtain the trained auxiliary classifier-based generative adversarial network model; D: Use the trained auxiliary classifier-based generative adversarial network model to expand and process different types of ECG data samples.
2. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 1, characterized in that: In the step B, the generator based on the self-attention mechanism takes the vector A containing random noise z and the category label label as input, and generates the ECG data corresponding to the category label label, i.e., the vector Z, as output; The generator based on the self-attention mechanism includes a long short-term memory network module, a Transformer-based self-attention module and a causal convolution module; the causal convolution module and the long short-term memory network module are used to obtain the spatial representation information of the electrocardiogram and the time information of each heartbeat sampling point respectively, and the Transformer-based self-attention module is used to assign attention weights to the acquired spatial representation information and time information representation.
3. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 2, characterized in that: The long short-term memory network module transforms the vector A into a vector X t As input, generate a vector H containing the short-term and long-term temporal dependencies of the ECG data to be generated t As output; H t =LSTM(X t ), LSTM represents the long short-term memory network module; the long short-term memory network module is used to characterize the complexity of ECG data of different leads and obtain the time information of each heartbeat sampling point of the ECG; The Transformer-based self-attention module transforms the vector H t As input, generate a vector A containing the relationship between any time steps of the ECG data to be generated and the importance of the time steps t As output; The Transformer-based self-attention module is used to capture the long-range dependencies of ECG data with time series characteristics, and adaptively assign attention weights to the information representation of the ECG; The causal convolution module transforms the vector A t As input, a vector Z is generated as output; the causal convolution module is used to introduce dilated convolution to expand the receptive field of the ECG data and capture the spatial representation information of the ECG.
4. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 3, characterized in that: First, the self-attention module pays attention to the vector H t Perform linear transformation to generate query vector Q, key vector K and value vector V respectively; where Q = W q H t +b q , K=W k H t +b k , V=W v H t +b v ; W q , W k and W v Respectively represent the weight matrices corresponding to the query vector Q, key vector K and value vector V; b q , b k and b v They represent the biases corresponding to the query vector Q, key vector K, and value vector V respectively; Then, the self-attention module calculates the attention score score(Q,K) based on the query vector Q and the key vector K. score(Q,K)=Q·K T , where T represents the transposed symbol in the matrix; Then, the self-attention module converts the attention score score(Q,K) into an attention weight distribution through the Softmax function to obtain the query vector Q i Key vector K j The attention weight a ij , Where i represents the i-th query vector, j represents the j-th key vector, and T1 represents the total number of key vectors; Afterwards, the self-attention module uses the attention weight a ij Perform a weighted summation on the value vector V and obtain the corresponding attention output: Where k represents the kth value vector, and T2 represents the total number of value vectors; Finally, the self-attention module transforms the attention output linearly to obtain the output vector A of the Transformer-based self-attention module. t .
5. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 1, characterized in that: In the step B, the discriminator based on spatiotemporal features takes the ECG data G as input and generates the probability Dreal that the input is the real ECG data and the probability Dclass that the input is the corresponding class label; The discriminator based on spatiotemporal features includes a convolutional neural network discrimination module based on spatial features, a bidirectional long short-term memory network module based on temporal features, an ECG data authenticity discrimination module and an ECG data category discrimination module; the discriminator based on spatiotemporal features is used to simultaneously process the dynamic changes of the heartbeat in the lead and the spatial relationship between multiple leads, and to judge the authenticity of the generated ECG data and the rationality of the time series features.
6. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 5, characterized in that: The convolutional neural network discrimination module based on spatial features takes the ECG data G as input, generates a vector H containing spatial feature information representing the input ECG data as output; the convolutional neural network discrimination module based on spatial features is used to judge the accuracy and rationality of the generated ECG data spatial information representation; The bidirectional long short-term memory network module based on time characteristics takes the vector H as input, generates a vector L containing information representing the time series characteristics of the ECG data as output; the bidirectional long short-term memory network module based on time characteristics is used to determine the accuracy and rationality of the representation of the time information of the generated ECG data; The ECG data authenticity determination module takes the vector L as input, generates a probability Dreal that the input is real ECG data and outputs it; The ECG data authenticity determination module is used to determine the authenticity of the generated ECG data; The ECG data category discrimination module takes the vector L as input, generates the probability Dclass of the input corresponding to the category label as output; The ECG data category discrimination module is used to generate the probability that the input is the corresponding category label.
7. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 1, characterized in that: The design method of the discriminator loss function is as follows: C11: Input the real ECG data R into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_real and the category probability output class_real of the real ECG data R; then input class_real and the label of the real ECG data R into the cross entropy loss function to obtain the category loss class_error_real of the real ECG data; C12: Random sampling generates random pseudo ECG data S with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution. The corresponding category label is noise_label; C13: Input the random fake ECG data S into the generator based on the self-attention mechanism to obtain the fake ECG data fake_data; C14: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features to obtain the authenticity probability output source_fake and the category probability output class_fake of the random fake ECG data S, input the authenticity probability output class_fake and the category label noise_label into the cross entropy loss function to obtain the category loss class_error_fake of the random fake ECG data; C15: The discriminator loss function D_loss is: D_loss = class_error_real + class_error_fake. Combined with the Adam optimizer, the gradient of the discriminator parameters is calculated according to the loss function D_loss, and the parameters are updated.
8. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 1, characterized in that: The design method of the generator loss function is as follows: C21: Input the fake ECG data fake_data into the discriminator model based on spatiotemporal features again to obtain the authenticity probability output source and category probability output class of the new random fake ECG data S, input the category probability output class and category label noise_label into the cross entropy loss function to obtain the category loss class_error of the random fake ECG data, and calculate the mean value of the authenticity probability output source to obtain source_error; C22: The generator loss function G_loss is: G_loss = class_error + source_error. Combined with the Adam optimizer, the gradient of the generator parameters is calculated according to the loss function G_loss, and the parameters are updated.
9. The method for generating ECG data based on auxiliary classifier generative adversarial network according to claim 1, characterized in that: The step D comprises the following specific steps: D1: Random sampling generates random pseudo ECG data T with a mean of 0 and a standard deviation of 1 that conforms to the Gaussian distribution, and generates the specified category label new_label; D2: Concatenate the random fake ECG data T and the specified category label new_label to generate a vector U, input the vector U into the generator trained based on the self-attention mechanism, and output the multi-lead ECG data with the specified category label, thus completing the expansion of the ECG data samples of the specified category.
Citation Information
Cited By
Unbalanced electrocardiogram data determination method and system based on adaptive generative adversarial network
CN119691691A
Deep learning model pruning method
CN119903889A
Man-machine asynchronous diagnosis method, device and equipment for mechanical ventilation patient and storage medium
CN120296528A
Electrocardiosignal noise reduction method based on deep convolution and sequential network
CN120873563A
