Heartbeat classification method, system, apparatus, and storage medium
By training a heartbeat classification model using electrocardiogram data from multiple heart rate databases and employing a combination of embedding layers and multi-head attention layers, the problem of insufficient accuracy and high power consumption in heartbeat arrhythmia detection of wearable devices is solved, achieving high efficiency, accuracy, and low power consumption in heartbeat classification.
Patent Information
- Application Number
- CN202310820844.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-05
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2043-07-05
AI Technical Summary
Existing wearable ECG monitoring devices have low accuracy in detecting arrhythmias, mainly due to insufficient model accuracy caused by imbalanced training data. Furthermore, the high power consumption of GPUs and FPGAs in existing technologies makes them unsuitable for wearable devices.
By fusing electrocardiogram data from several heart rate databases, a heartbeat classification model is trained. A combined model consisting of an embedding layer, a position encoding module, a fully connected encoder, a fully connected decoder, a first classifier, and a second classifier is used, along with a bidirectional GRU layer and a multi-head attention layer, to improve the accuracy of heartbeat classification.
It effectively improves the accuracy of the heart rate classification model, solves the data imbalance problem, and reduces power consumption, making it suitable for wearable devices.
Smart Images

Figure CN116982990B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electrocardiogram data processing technology, and in particular to a method, system, device, and storage medium for classifying heartbeats. Background Technology
[0002] In related technologies, heart disease accounts for a large proportion of disease-related deaths worldwide. Among these, cardiovascular disease is a leading cause of death globally, and arrhythmia is the most significant cardiovascular disease. Electrocardiography (ECG), which records the electrical signals of cardiac activity, is the most effective method for detecting arrhythmias. Currently, bulky ECG equipment is used in hospitals to collect ECGs for a short period (e.g., 2-3 minutes), which are then visually diagnosed by cardiologists. However, arrhythmias are difficult to detect in such a short time because they occur intermittently, especially in the early stages of heart disease. Therefore, continuous and long-term ECG monitoring with arrhythmia detection capabilities is of great interest. To simplify ECG detection equipment, wearable smart ECG monitoring devices for long-term ECG monitoring have been proposed. These wearable devices integrate intelligent ECG classification to perform ECG monitoring and abnormal heartbeat detection. The raw ECG signal is preprocessed and segmented into heartbeats, and then each heartbeat is sent to the intelligent ECG classifier for arrhythmia detection. However, existing wearable devices directly send the raw signals to the neural network for classification, which is quite complex in terms of the number of parameters and the number of operations required.
[0003] To accelerate neural network computation, Graphics Processing Units (GPUs) and Field Variable Gate Arrays (FPGAs) are widely used. By leveraging the parallel processing capabilities of GPUs and FPGAs, computation time can be significantly reduced. However, GPUs and FPGAs consume a lot of power, making them unsuitable for wearable ECG monitoring devices. To address this issue, application-specific integrated circuits (ASICs) have been developed specifically for wearable smart ECG monitoring. By mapping ECG processing algorithms to these custom ASICs, real-time, low-power, and low-cost processing can be achieved. However, since most network training is performed on the MIT-BIHArrhythmia Database, which is severely imbalanced, the accuracy of the trained network model is low, thus failing to improve the accuracy of ECG beat type classification. Summary of the Invention
[0004] This invention aims to at least solve one of the technical problems existing in the prior art. To this end, this invention proposes a heartbeat classification method, system, device, and storage medium, which can effectively improve the accuracy of heartbeat classification results.
[0005] On one hand, embodiments of the present invention provide a heart rate classification method, including the following steps:
[0006] Obtain electrocardiogram data from several heart rate databases;
[0007] The electrocardiogram data from the aforementioned databases are fused to obtain the dataset to be used;
[0008] The heart rate classification model is trained using the dataset to be applied.
[0009] The trained heartbeat classification model is used to analyze the heartbeat type in the current electrocardiogram.
[0010] The heartbeat classification model includes an embedding layer, a position encoding module, a fully connected layer encoder, a fully connected layer decoder, a first classifier, a second classifier, and an output module.
[0011] The embedding layer is used to extract spatial and temporal features from the electrocardiogram data in the dataset to be applied;
[0012] The output terminal of the sum of the output signal of the embedded layer and the output signal of the position encoding module is connected to the input terminal of the fully connected layer encoder and the first input terminal of the fully connected layer decoder, respectively; the first output terminal of the fully connected layer encoder is connected to the second input terminal of the fully connected layer decoder; the second output terminal of the fully connected layer encoder is connected to the input terminal of the first classifier; the output terminal of the fully connected layer decoder is connected to the input terminal of the second classifier; the output terminals of the first classifier and the second classifier are both connected to the input terminal of the output module, and the output terminal of the output module is used to output the heart rate classification result.
[0013] In some embodiments, the embedding layer includes:
[0014] Input layer;
[0015] Four downsampling layers, the four downsampling layers including a first downsampling layer, a second downsampling layer, a third downsampling layer and a fourth downsampling layer;
[0016] Four upsampling layers, the four upsampling layers including a first upsampling layer, a second upsampling layer, a third upsampling layer and a fourth upsampling layer;
[0017] The system comprises two first convolutional layers, a left first convolutional layer and a right first convolutional layer. The input of the left first convolutional layer is connected to the input layer, the first output of the left first convolutional layer is connected to the first input of the first upsampling layer, the second output of the left first convolutional layer is connected to the input of the first downsampling layer, and the input of the right first convolutional layer is connected to the output of the first upsampling layer. The output of the right first convolutional layer serves as the output of the embedding layer.
[0018] The system comprises two second convolutional layers, a left second convolutional layer and a right second convolutional layer. The input of the left second convolutional layer is connected to the output of the first downsampling layer, the first output of the left second convolutional layer is connected to the first input of the second upsampling layer, the second output of the left second convolutional layer is connected to the input of the second downsampling layer, the input of the right second convolutional layer is connected to the output of the second upsampling layer, and the output of the right second convolutional layer is connected to the second input of the first upsampling layer.
[0019] Two third convolutional layers, including a left third convolutional layer and a right third convolutional layer, wherein the input of the left third convolutional layer is connected to the output of the second downsampling layer, the first output of the left third convolutional layer is connected to the first input of the third upsampling layer, the second output of the left third convolutional layer is connected to the input of the third downsampling layer, the input of the right third convolutional layer is connected to the output of the third upsampling layer, and the output of the right second convolutional layer is connected to the second input of the second upsampling layer.
[0020] Two fourth convolutional layers, including a left fourth convolutional layer and a right fourth convolutional layer, wherein the input of the left fourth convolutional layer is connected to the output of the third downsampling layer, the first output of the left fourth convolutional layer is connected to the first input of the fourth upsampling layer, the second output of the left fourth convolutional layer is connected to the input of the fourth downsampling layer, the input of the right fourth convolutional layer is connected to the output of the fourth upsampling layer, and the output of the right fourth convolutional layer is connected to the second input of the third upsampling layer;
[0021] The fifth convolutional layer, the input of which is connected to the output of the fourth downsampling layer;
[0022] A bidirectional GRU layer, the input of which is connected to the output of the fifth convolutional layer, and the output of which is connected to the second input of the fourth upsampling layer.
[0023] In some embodiments, before the output signals of the five convolutional layers are input into the bidirectional GRU layer, the last two dimensions of the output signals of the five convolutional layers are swapped; before the output signals of the bidirectional GRU layer are input into the fourth upsampling layer, the last two dimensions of the output signals of the bidirectional GRU layer are swapped.
[0024] In some embodiments, the location encoding module is used to perform location encoding on the electrocardiogram data in the dataset to be applied, wherein the size of the location encoding is the same as the size of the output signal of the embedding layer.
[0025] In some embodiments, the fully connected layer encoder includes at least three coding layers, which are cascaded together; each coding layer includes:
[0026] The first normalization layer is connected to the output of the sum of the output signal of the embedding layer and the output signal of the position encoding module.
[0027] A multi-head attention layer, wherein the input of the multi-head attention layer is connected to the first output of the first normalization layer;
[0028] A feedforward network, wherein the first input of the feedforward network is connected to the output of the multi-head attention layer, and the second input of the feedforward network is connected to the second output of the first normalization layer;
[0029] A channel attention layer, wherein the input of the channel attention layer is connected to the first output of the feedforward network;
[0030] The second normalization layer has its first input connected to the output of the channel attention layer, and its second input connected to the second output of the feedforward network.
[0031] In some embodiments, the first classifier is used to classify heart rate data in the dataset to be applied based on the output information of the fully connected layer encoder.
[0032] In some embodiments, when the classification result output by the first classifier is a first type, the first connection channel and the second connection channel of the fully connected layer decoder are both connected. The first connection channel is the connection channel between the fully connected layer decoder and the fully connected layer encoder, and the second connection channel is the connection channel between the fully connected layer decoder and the output terminal of the embedded layer output signal and the position encoding module output signal.
[0033] On the other hand, embodiments of the present invention provide a heart rate classification system, including:
[0034] The first module is used to acquire electrocardiogram data from several heart rate databases;
[0035] The second module is used to fuse the electrocardiogram data in the several databases to obtain the dataset to be applied;
[0036] The third module is used to train the heart rate classification model using the dataset to be applied;
[0037] The fourth module is used to analyze the type of heartbeat in the current electrocardiogram using the trained heartbeat classification model;
[0038] The heartbeat classification model includes an embedding layer, a position encoding module, a fully connected layer encoder, a fully connected layer decoder, a first classifier, a second classifier, and an output module.
[0039] The embedding layer is used to extract spatial and temporal features from the electrocardiogram data in the dataset to be applied;
[0040] The output terminal of the sum of the output signal of the embedded layer and the output signal of the position encoding module is connected to the input terminal of the fully connected layer encoder and the first input terminal of the fully connected layer decoder, respectively; the first output terminal of the fully connected layer encoder is connected to the second input terminal of the fully connected layer decoder; the second output terminal of the fully connected layer encoder is connected to the input terminal of the first classifier; the output terminal of the fully connected layer decoder is connected to the input terminal of the second classifier; the output terminals of the first classifier and the second classifier are both connected to the input terminal of the output module, and the output terminal of the output module is used to output the heart rate classification result.
[0041] On the other hand, embodiments of the present invention provide a heart rate classification device, comprising:
[0042] At least one memory for storing programs;
[0043] At least one processor is used to load the program to execute the heartbeat classification method.
[0044] On the other hand, embodiments of the present invention provide a computer storage medium storing a computer-executable program, which, when executed by a processor, is used to implement the aforementioned heart rate classification method.
[0045] The heart rate classification method provided in this invention has the following beneficial effects:
[0046] This embodiment solves the problem of data imbalance affecting model training by fusing electrocardiogram data from several heart rate databases. After data fusion, the heartbeat classification model is trained using this data on the dataset to be applied, thereby effectively improving the accuracy of the heartbeat classification model. Furthermore, by setting two classifiers in the heartbeat classification model, the accuracy of the heartbeat classification results can be further improved.
[0047] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0048] The present invention will be further described below with reference to the accompanying drawings and embodiments, wherein:
[0049] Figure 1 This is a flowchart of a heart rate classification method according to an embodiment of the present invention;
[0050] Figure 2 This is a schematic diagram of a file structure according to an embodiment of the present invention;
[0051] Figure 3 This is a schematic diagram illustrating a dataset processing method according to an embodiment of the present invention;
[0052] Figure 4 This is a schematic diagram of the structure of a heart rate classification model according to an embodiment of the present invention;
[0053] Figure 5 This is a schematic diagram of an embedding layer according to an embodiment of the present invention;
[0054] Figure 6 This is a schematic diagram of the structure of a fully connected layer encoder according to an embodiment of the present invention;
[0055] Figure 7 This is a schematic diagram of the structure of an encoding layer according to an embodiment of the present invention. Detailed Implementation
[0056] Embodiments of the present invention are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0057] In the description of this invention, it should be understood that the orientation descriptions, such as up, down, front, back, left, right, etc., are based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limiting this invention.
[0058] In the description of this invention, "several" means one or more, "multiple" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.
[0059] In the description of this invention, unless otherwise explicitly defined, terms such as "setting," "installing," and "connecting" should be interpreted broadly, and those skilled in the art can reasonably determine the specific meaning of the above terms in this invention in conjunction with the specific content of the technical solution.
[0060] In the description of this invention, the terms "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0061] Reference Figure 1 This invention provides a method for classifying heartbeats. This method can be applied to the backend processor, server, or cloud of a heartbeat classification platform. In application, the method includes, but is not limited to, the following steps:
[0062] Step S110: Obtain electrocardiogram data from several heart rate databases;
[0063] Step S120: Merge the electrocardiogram data from several databases to obtain the dataset to be used;
[0064] Step S130: Train the heart rate classification model using the dataset to be applied;
[0065] Step S140: Analyze the heartbeat type in the current electrocardiogram using the trained heartbeat classification model.
[0066] In this embodiment, several heart rate databases may include, but are not limited to, the MIT-BIH Arrhythmia Database, the MIT-BIH ST Change Database, the European ST-T Database, and the Sudden Cardiac Death Holter Database. The data sampling in the MIT-BIH Arrhythmia Database and the MIT-BIH ST Change Database is 360Hz, while the data sampling in the European ST-T Database and the Sudden Cardiac Death Holter Database is 250Hz. Therefore, the data in the European ST-T Database and the Sudden Cardiac Death Holter Database needs to be resampled to 360Hz. In this embodiment, for the sampled data, according to the position of the R-front in the ATR standard file, 159 points are taken forward and 200 points are taken backward, and then... Figure 2 The structure shown is organized into a document.
[0067] It is understood that the heartbeat type in this embodiment may include, but is not limited to, the following types:
[0068] N (Normal): A normal electrocardiogram;
[0069] S (Supraventricular) class: includes various atrial and atrioventricular arrhythmias;
[0070] Class V (Ventricular): Ventricular arrhythmias;
[0071] Class F (Fusion): Includes fusion of cardiac rhythm and pacemaker rhythm;
[0072] Q (Unclassifiable): Electrocardiogram that cannot be classified.
[0073] In this embodiment, the collected dataset can be divided into a training set, a validation set, and a test set. For the data within this dataset, such as... Figure 3As shown, the data in the five CSV files for each lead type are normalized separately, with x = (x – mean) / std. The five CSV files for each lead type are then merged into test.csv, validation.csv, and test.csv files. These files are then normalized again, with x = (x – mean) / std. SMOTEENN is then applied to test.csv, validation, and test.csv files respectively. SMOTEENN includes Combine over, under-sampling using SMOTE, and Edited Nearest Neighbors.
[0074] In this embodiment, as Figure 4 As shown, the heartbeat classification model includes an embedding layer, a location encoding module, a fully connected encoder, a fully connected decoder, a first classifier, a second classifier, and an output module. The embedding layer is used to extract spatial and temporal features from the electrocardiogram data in the dataset to be applied. The output of the embedding layer and the output of the location encoding module are added together and then connected to the input of the fully connected encoder and the first input of the fully connected decoder, respectively. The first output of the fully connected encoder is connected to the second input of the fully connected decoder. The second output of the fully connected encoder is connected to the input of the first classifier. The output of the fully connected decoder is connected to the input of the second classifier. The outputs of both the first and second classifiers are connected to the input of the output module, which outputs the heartbeat classification results.
[0075] In this embodiment, since ECG is a 1D voltage signal, the Transformer architecture requires multi-dimensional features at each time point, which are then projected using an EmbeddingLayer. Therefore, this embodiment proposes an Embedding layer for UNet based on 1D timing and embedded bidirectional GRU. Specifically, the input input_size = (batch_size, 1, 360) is processed through BGUE2, resulting in input_size = (batch_size, 64, 360), and the 1st and 2nd axes are swapped to obtain the input input_size = (batch_size, 360, 64).
[0076] It is understandable that, such as Figure 5As shown, the embedding layer includes an input layer, four downsampling layers, four upsampling layers, two first convolutional layers, two second convolutional layers, two third convolutional layers, two fourth convolutional layers, a fifth convolutional layer, and a bidirectional GRU layer. Specifically, the four downsampling layers include a first downsampling layer, a second downsampling layer, a third downsampling layer, and a fourth downsampling layer; the four upsampling layers include a first upsampling layer, a second upsampling layer, a third upsampling layer, and a fourth upsampling layer; the two first convolutional layers include a left first convolutional layer and a right first convolutional layer. The input of the left first convolutional layer is connected to the input layer, the first output of the left first convolutional layer is connected to the first input of the first upsampling layer, the second output of the left first convolutional layer is connected to the input of the first downsampling layer, the input of the right first convolutional layer is connected to the output of the first upsampling layer, and the output of the right first convolutional layer serves as the output of the embedding layer.
[0077] The two second convolutional layers include a left second convolutional layer and a right second convolutional layer. The input of the left second convolutional layer is connected to the output of the first downsampling layer. The first output of the left second convolutional layer is connected to the first input of the second upsampling layer. The second output of the left second convolutional layer is connected to the input of the second downsampling layer. The input of the right second convolutional layer is connected to the output of the second upsampling layer. The output of the right second convolutional layer is connected to the second input of the first upsampling layer.
[0078] The two third convolutional layers include a left third convolutional layer and a right third convolutional layer. The input of the left third convolutional layer is connected to the output of the second downsampling layer. The first output of the left third convolutional layer is connected to the first input of the third upsampling layer. The second output of the left third convolutional layer is connected to the input of the third downsampling layer. The input of the right third convolutional layer is connected to the output of the third upsampling layer. The output of the right second convolutional layer is connected to the second input of the second upsampling layer.
[0079] The two fourth convolutional layers include a left fourth convolutional layer and a right fourth convolutional layer. The input of the left fourth convolutional layer is connected to the output of the third downsampling layer. The first output of the left fourth convolutional layer is connected to the first input of the fourth upsampling layer. The second output of the left fourth convolutional layer is connected to the input of the fourth downsampling layer. The input of the right fourth convolutional layer is connected to the output of the fourth upsampling layer. The output of the right fourth convolutional layer is connected to the second input of the third upsampling layer.
[0080] The input of the fifth convolutional layer is connected to the output of the fourth downsampling layer; the input of the bidirectional GRU layer is connected to the output of the fifth convolutional layer, and the output of the bidirectional GRU layer is connected to the second input of the fourth upsampling layer.
[0081] based on Figure 5 The embedded layer structure shown in this embodiment works as follows:
[0082] The network input, input_size = [batch_size, 1, 360], passes through a layerNormal layer, input_size = [batch_size, 1, 360]. Then it passes through the first convolutional layer in the first convolutional layer on the left, with 64 kernels, kernel_size = 11, strid = 1, padding = 'same', and bias = False. After passing through a batchNormal layer, the ReLU activation function input becomes [batch_size, 64, 360]. Finally, it is fed into the second convolutional layer in the first convolutional layer on the left, with 64 kernels, kernel_size = 11, strid = 1, padding = 'same', and bias = False. After passing through a batchNormal layer, the ReLU activation function input becomes [batch_size, 64, 360]. After passing through the MaxPooling layer, with strid=2 and kernel_size=2, downsampling is performed. Input_size=[batch_size,64,180].
[0083] The first convolutional layer, the second convolutional layer from the left, has 128 kernels, a kernel size of 9, a stride of 1, padding of 'same', and a bias of False. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 128, 180]. Then, it's fed into the second convolutional layer, also with 128 kernels, a kernel size of 1, a stride of 1, padding of 'same', and a bias of False. After passing through another BatchNormal layer, the ReLU activation function input becomes [batch_size, 128, 180]. Finally, it passes through a MaxPooling layer with a stride of 2 and a kernel size of 2 for downsampling. The input size is now [batch_size, 128, 90].
[0084] The first convolutional layer, the third convolutional layer from the left, has 256 kernels, a kernel size of 7, a stride of 1, padding of 'same', and a bias of False. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 256, 90]. Next, it's fed into the second convolutional layer, also with 256 kernels, a kernel size of 7, a stride of 1, padding of 'same', and a bias of False. After passing through another BatchNormal layer, the ReLU activation function input becomes [batch_size, 256, 90]. Finally, it passes through a MaxPooling layer with a stride of 2 and a kernel size of 2 for downsampling. The input size is now [batch_size, 256, 45].
[0085] The first convolutional layer, the fourth convolutional layer from the left, has 512 kernels, a kernel size of 5, a stride of 1, padding of 'same', and a bias of False. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 512, 45]. Next, it's fed into the second convolutional layer, also with 512 kernels, a kernel size of 5, a stride of 1, padding of 'same', and a bias of False. After passing through another BatchNormal layer, the ReLU activation function input becomes [batch_size, 512, 45]. Finally, it passes through a MaxPooling layer with a stride of 2 and a kernel size of 2 for downsampling. The input size becomes [batch_size, 512, 22].
[0086] The first convolutional layer, the fifth convolutional layer on the left, has 1024 kernels, a kernel size of 3, a stride of 1, padding of 'same', and bias of False. After passing through one BatchNormal layer, the ReLU activation function input becomes [batch_size, 1024, 22]. Then, it's fed into the second convolutional layer (the first layer), with 1024 kernels, a kernel size of 3, a stride of 1, padding of 'same', and bias of False. After passing through one BatchNormal layer, the ReLU activation function input becomes [batch_size, 1024, 22].
[0087] At this point, the input needs to be fed into the bidirectional GRU layer. Due to the temporal nature of GRU, the input needs to be transformed before feeding it in, swapping the last two dimensions: [batch_size, 1024, 22] -> [batch_size, 22, 1024]. The GRU's input_size = 1024 and hidden_size = 512. This embodiment only needs the GRU's output and does not require the hidden state of the last layer. Input_siez[batch_size, 22, 1024]. In this embodiment, to accommodate the convolutional layer, the last two dimensions are swapped: [batch_size, 1024, 22].
[0088] The input_size is obtained by GRU as [batch_size, 1024, 22], and then upsampling is performed using transpose convolution (ConvTranspose).
[0089] The fifth layer has 1024 input channels (in_channels=1024), 512 output channels (out_channels=512), a kernel size of 2, a stride of 2, and an output shape of [batch_size, 512, 44]. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 512, 44].
[0090] In the fourth convolutional layer on the right, the upsampled output of the fifth layer (i.e., the output of the fourth downsampled layer) needs to be combined with the output of the fourth layer on the left as input. Since the shape of the fourth layer on the left ([batch_size, 512, 45]) does not match the shape of the upsampled output of the fifth layer ([batch_size, 512, 44]), the upsampled output of the fifth layer needs to be padded to [batch_size, 512, 45]. The padding formula is as follows: diff = x2 – x1 (x2 is the size of the last dimension of the left concatenation, 45; x1 is the size of the last dimension of the upsampled layer output, 44). Since ECG is a 1D signal, only one dimension needs to be expanded: diff / / 2 on the left and diff – diff / / 2 on the right. After expansion, it can be concatenated with the output of the fourth layer on the left in the first dimension, resulting in an output shape of [batch_size, 1024, 45]. After passing through the first convolutional layer of the fourth convolutional layer on the right, with 512 kernels, a kernel size of 11, a stride of 1, padding of 'same', and bias of False, and after one BatchNormal layer, the ReLU activation function input becomes [batch_size, 512, 45]. Then, it is fed into the second convolutional layer of the fourth convolutional layer on the right, with 512 kernels, a kernel size of 11, a stride of 1, padding of 'same', and bias of False, and after one BatchNormal layer, the ReLU activation function input becomes [batch_size, 512, 45]. Upsampling is performed using transposed convolution (ConvTranspose). The input channels in the 4th layer on the right are in_channels=512, the output channels out_channels=256, the kernel_size=2, the stride=2, and the output shape is [batch_size,256,90]. After passing through a BatchNormal layer, the ReLU activation function input shape becomes [batch_size,256,90].
[0091] In the third convolutional layer on the right, the upsampled output of the fourth layer on the right (i.e., the output of the third upsampled layer) is combined with the output of the third convolutional layer on the left as input. Since the shape of the third convolutional layer on the left matches the shape of the upsampled output of the fourth layer [batch_size, 256, 90], the upsampled output of the fourth layer on the right can be concatenated with the output of the third layer on the left in the first dimension, resulting in an output shape of [batch_size, 512, 90]. After passing through the first convolutional layer of the third convolutional layer on the right, with 256 kernels, a kernel size of 9, a stride of 1, padding of 'same', and bias of False, and after passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 256, 90]. The data is fed into the second convolutional layer of the third convolutional layer on the right. The number of kernels is 512, the kernel size is 9, the stride is 1, the padding is 'same', and the bias is False. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 256, 90]. Upsampling is then performed using a transposed convolution (ConvTranspose). The upsampled input channels of the third layer on the right are in_channels=256, the output channels are out_channels=128, the kernel size is 2, the stride is 2, and the output shape is [batch_size, 128, 180]. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 128, 180].
[0092] In the second convolutional layer on the right, the upsampled output of the third layer on the right (i.e., the output of the second upsampled layer) is combined with the output of the second layer on the left as input. Since the shape of the second layer on the left is [batch_size, 128, 180] and the shape of the upsampled output of the third layer on the right is [batch_size, 128, 180], the upsampled output of the third layer on the right can be concatenated with the output of the second layer on the left in the first dimension, resulting in an output shape of [batch_size, 256, 180]. After passing through the first convolutional layer of the second convolutional layer on the right, with 128 kernels, kernel_size = 7, strid = 1, padding = 'same', and bias = False, and after passing through a BatchNormal layer, the shape of the ReLU activation function input becomes [batch_size, 128, 180]. The input is fed into the second convolutional layer of the second convolutional layer on the right. It has 128 kernels, a kernel size of 7, a stride of 1, padding of 'same', and a bias of False. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 128, 180]. Then, it is upsampled using a transposed convolution (ConvTranspose). The upsampled input of the second layer on the right has 128 input channels (in_channels), 64 output channels (out_channels), a kernel size of 2, a stride of 2, and an output shape of [batch_size, 64, 360]. After passing through a BatchNormal layer, the ReLU activation function input becomes [batch_size, 64, 360].
[0093] In the first convolutional layer on the right, the upsampled output of the second layer on the right (i.e., the output of the first upsampled layer) is combined with the output of the first layer on the left as input. Since the shape of the first layer on the left matches the shape of the upsampled output of the second layer [batch_size, 64, 360], the upsampled output of the second layer on the right can be concatenated with the output of the first layer on the left in the first dimension, resulting in an output shape of [batch_size, 128, 360]. After passing through the first convolutional layer of the first convolutional layer on the right, with 64 kernels, kernel_size = 5, strid = 1, padding = 'same', and bias = False, and after passing through a BatchNormal layer, the shape of the ReLU activation function input becomes [batch_size, 64, 360]. The input is fed into the second convolutional layer of the first convolutional layer on the right. The number of convolutional kernels is 64, the kernel size is kernel_size=5, the strid is strid=1, the padding is 'same', and the bias is False. After passing through a BatchNormal layer, the shape of the ReLU activation function input becomes [batch_size,64,360].
[0094] As can be seen from the above, this embodiment needs to pass the output of BGUE2 to the transformer's encoder, which requires swapping the last two dimensions: [batch_size, 64, 360] --> [batch_size, 360, 64]. This completes the ECG signal embedding operation.
[0095] The benefits of using BGUE2: U-Net is a typical convolutional neural network (CNN) with wide applications in fields such as medical image analysis. The U-Net structure in this embodiment includes one input layer, four downsampling layers, one GRU layer, and four upsampling layers. U-Net is used to extract spatial features, finding spatial features in the ECG signal, while the GRU layer processes sequence data and extracts temporal features. This consideration of both spatial and temporal information allows for spatiotemporal feature extraction, which is beneficial for more accurate ECG heart rate classification. Based on this, the BGUE2 embedding layer in this embodiment mainly has three functions:
[0096] First, filtering. Since the input is raw, unprocessed data, the network needs to automatically learn how to filter, thus achieving automatic filtering.
[0097] Secondly, feature extraction is crucial. Traditional machine learning requires extensive manual feature finding in the early stages, which is time-consuming and labor-intensive. This embodiment uses BGUE2 self-learning to find ECG features. This eliminates the tedious preliminary work of manually finding features and avoids the problem of inability to classify correctly when the ECG database is changed. This embodiment only requires retraining on a small batch with a new ECG database and transfer learning to achieve good results on the new dataset.
[0098] Third, word embedding is performed. Since the Transformer is used for natural language processing, its input is usually a batch of sentences for training. Sentences are composed of words, and words are composed of one-hot codes. The one-hot codes of words are passed through the word embedding layer to obtain the embedding vector. However, the ECG in this embodiment obviously does not have this characteristic. Because there is only one voltage value at a given time point, the meaning of a single time point is definite. Therefore, the BGUE2 layer can project the voltage value at a single time point into a 64-dimensional space to obtain more feature information (spatial information and temporal information), which is then fed into the Transformer.
[0099] In this embodiment, the position encoding module is used to perform position encoding on the electrocardiogram (ECG) data within the dataset to be applied, wherein the size of the position encoding is the same as the size of the output signal of the embedding layer. It is understood that this embodiment can use sine and cosine position encoding. Specifically, this embodiment adds "position encoding" to the word embeddings of the encoder and decoder (the ECG signal after BGUE2 embedding). The position encodings have the same size d_mode = 64 as the embeddings, allowing the two to be added together. This embodiment uses sine and cosine functions of different frequencies:
[0100]
[0101]
[0102] Where pos is the position, i.e., the temporal sequence, and i is the dimension, which is one of the 64 dimensions of the d_model feature. In other words, each dimension of the positional encoding corresponds to a sine curve. The wavelength ranges from 2π to 10000·2π. This embodiment chooses this function because it is assumed that it allows the model to easily learn to focus on relative positions, since for any fixed offset k, PEpos+k can be represented as a linear representation of PEpos.
[0103] Furthermore, this embodiment applies dropout to the sum of word embeddings and positional encodings in the encoder and decoder stacks, with the dropout probability set to 0.2. Absolute positional encoding can better remember the characteristics of the ECG signal between each time sequence. In this embodiment, the obtained unetembeding and positional embedding are added together and fed into the Transfer encoder.
[0104] In the embodiments of this application, such as Figure 6 As shown, a fully connected layer encoder includes at least three coding layers, which are cascaded together. Specifically, as... Figure 7 As shown, each encoding layer includes a first normalization layer, a multi-head attention layer, a position-wise feed-forward network, a channel attention layer, and a second normalization layer. Specifically, the input of the first normalization layer is connected to the output of the sum of the output signals of the embedding layer and the position encoding module; the input of the multi-head attention layer is connected to the first output of the first normalization layer; the first input of the feed-forward network is connected to the output of the multi-head attention layer, and the second input of the feed-forward network is connected to the second output of the first normalization layer; the input of the channel attention layer is connected to the first output of the feed-forward network; the first input of the second normalization layer is connected to the output of the channel attention layer, and the second input of the second normalization layer is connected to the second output of the feed-forward network.
[0105] Based on the above structure, this embodiment obtains an output shape [batch_size, 360, 64] by adding the BGUE2 embedding layer and position encoding, and then transmits it to the Layer_Normal layer to obtain the output [batch_size, 360, 64]. This output is then fed into the multi-head attention layer and input to the feedforward network. The feedforward network first raises [batch_size, 360, 64] to [batch_size, 360, 512] through a linear layer (the input dimension of the linear layer is 64, and the output dimension is 512), and then reduces the dimension back to the original dimension [batch_size, 360, 64] through a second linear layer (the input dimension of the linear layer is 512, and the output dimension is 64). Finally, a residual connection is performed with the output of the Layer_Normal layer. The output is passed to the channel attention layer. Since the input requirement of the channel attention mechanism layer is [batch_size, 64, 360], the last two layers need to be swapped to get [batch_size, 64, 360]. This is then passed to the channel attention layer, and then to the adaptive average pooling layer and the max pooling layer, with dimensions [batch_size, 64, 1]. The adaptive max pooling layer and the adaptive average pooling layer are then passed to two convolutional layers. The first convolutional layer has in_channel = 64, out_channel = 16, and kernel = 1. The input is [batch_size, 16, 1], which is then passed to the ReLU layer and then to the second convolutional layer with in_channel = 16, out_channel = 64, and kernel = 1, resulting in the output [batch_size, 64, 1]. The two sums are fed into the output of the sigmoid activation layer to obtain [batch_size, 64, 1]. This is multiplied by the previous input [batch_size, 64, 360], and broadcast to obtain [batch_size, 64, 360]. The last two dimensions are swapped to obtain [batch_size, 360, 64], which is then fed into the Layer_normal layer. The final Layer_normal layer is residually linked to the previous feedforward network.
[0106] The attention function (Self_attention) in the multi-head attention mechanism involved in this embodiment can be described as mapping a query and a set of key-value pairs to an output, where the query, key, value, and output are all vectors. The output is computed as a weighted sum of values, where the weight assigned to each value is calculated by a compatibility function between the query and the corresponding keyword. Specifically, the multi-head attention mechanism builds upon self-attention by using Q, K, and V generated from various transformations for computation, and then combining their conclusions on relevance to further enhance the effect of self-attention. Multi-head attention is a widely used technique in natural language processing, especially in Transformer models. Its basic idea is to divide the input into multiple "heads," each with its own attention weights, allowing the model to learn different representations of the input in parallel, thereby capturing multiple aspects of the input.
[0107] For an input set of query (Q) keys (K) and values (V), the formula for the multi-head attention mechanism is as follows:
[0108] For each head i, there are weight matrices Wq_i, Wk_i, and Wv_i, which are learned during model training.
[0109] For each head i, first calculate the transformed query, key, and value:
[0110] Q_i=Q*Wq_i
[0111] K_i=K*Wk_i
[0112] V_i=V*Wv_i
[0113] For each head i, calculate the attention score (by the dot product of the query and the key, then scaling, and finally obtaining it through the softmax function):
[0114] Attention(Q_i,K_i,V_i)=softmax((Q_i*K_i.T) / sqrt(d_k))*V_i
[0115] Here, d_k is the dimension of the key and query, and the scaling operation of sqrt(d_k) is to prevent the dot product value from becoming too large.
[0116] Finally, the outputs of all the heads are concatenated and then subjected to a linear transformation:
[0117] MultiHead(Q,K,V)=Concat(head_1,...,head_h)*Wo
[0118] Here, Wo is a weight matrix, which is also learned during the model training process.
[0119] This embodiment uses an 8-head attention mechanism, which divides the 64 dimensions into 8 groups, where dmodel = 64, h = 8, dk = dv = 8. The ECG signal is a 1D temporal signal, and after embedding through BGUE2, the dimensions change from [batch_size, 1, 360] to [batch_size, 360, 64]. The multi-head attention mechanism allows for the learning of more internal correlations, contributing to more accurate ECG classification. The advantage of the multi-head attention mechanism is that each head can learn and focus on different parts of the input, enabling the model to better understand and represent the input.
[0120] Layer normalization is a widely used normalization technique in neural networks. Its main idea is to normalize along the feature dimension, that is, to normalize all features for each sample. This differs from batch normalization, which normalizes along the sample dimension, that is, to normalize all samples for each feature.
[0121] The formula for layer normalization is as follows:
[0122] For input x, calculate its mean and variance:
[0123] mean=mean(x,axis=-1,keepdims=True)
[0124] var=var(x,axis=-1,keepdims=True)
[0125] Normalize the input using the mean and variance:
[0126] x_norm=(x-mean) / sqrt(var+epsilon)
[0127] Finally, the normalized input is scaled and translated:
[0128] y = gamma * x_norm + beta
[0129] Here, gamma and beta are learnable parameters, and epsilon is a small constant used to prevent division by zero. Note that the mean and variance are calculated along the feature dimension, that is, over all features for each sample.
[0130] The benefits of layer normalization include:
[0131] Batch size independent: Unlike batch normalization, layer normalization is computationally independent of batch size. This makes it stable when the batch size changes, especially for small or dynamically changing batch sizes.
[0132] No need to maintain runtime statistics: Batch normalization behaves differently during training and inference because it requires maintaining runtime mean and variance statistics during training. In contrast, layer normalization behaves identically during training and inference.
[0133] Suitable for recurrent networks: Since layer normalization depends on only a single sample, it can be directly applied to recurrent neural networks (RNNs) without modifying the RNN structure or using sequence batch normalization.
[0134] Potentially helpful in mitigating the vanishing / exploding gradient problem: Normalization techniques, including layer normalization, have been shown to mitigate the vanishing and exploding gradient problems in certain situations, thus aiding model training.
[0135] The feedforward network is a key component of the Transformer model, also known as a positionally fully connected network or fully connected layer. It consists of two linear transformations with a ReLU activation function in between, as shown in the following formula:
[0136] FFN(x) = max(0, x*W1+b1)*W2+b2
[0137] Where x is the input, and W1, W2, b1, and b2 are learnable parameters.
[0138] The input size in this embodiment is 64, which becomes 512 after passing through an intermediate layer, and then decreases back to 64.
[0139] In the Transformer model, a positionally fully connected network is applied to the input at each position independently. That is, although this network is applied to each element of the sequence, it does not change the position of the element, which is why it is called a "positionally fully connected network".
[0140] For ECG signal classification, location-fully connected networks have the following advantages:
[0141] Increase the expressive power of the model: By adding non-linear, fully connected networks to the model, it can help the model learn more complex features and representations.
[0142] Preserving sequence order: Because the position-fully connected network processes the input at each position independently, it does not change the sequence order. This is crucial for ECG signal classification, as the sequence and timing information of ECG signals are critical.
[0143] Parallelization: Since the location fully connected network processes the input independently at each location, it can be easily parallelized, thereby improving computational efficiency and making it easier to train and deploy.
[0144] Channel attention is a technique used in neural networks that allows the model to assign different weights to different channels. The main idea behind this mechanism is that different channels may contain different information and may have varying degrees of importance for a specific task. Channel attention enables the model to automatically learn these importances and adjust the contribution of each channel accordingly.
[0145] Channel attention can be implemented in several ways. One common approach is to use global average pooling and global max pooling to calculate the statistics for each channel, and then use a fully connected layer and a sigmoid activation function to calculate the attention weights for each channel. The specific formula is as follows:
[0146] For input x, first calculate the global average pooling (avg_pool) and the global max pooling (max_pool):
[0147] avg_pool=mean(x,axis=(2,3))
[0148] max_pool=max(x,axis=(2,3))
[0149] Then, the attention weights are calculated using a fully connected layer and a sigmoid activation function:
[0150] avg_weight=sigmoid(W2(ReLU(W1(avg_pool))))
[0151] max_weight=sigmoid(W2(ReLU(W1(max_pool))))
[0152] W1 and W2 are the weights of the fully connected layer, and ReLU and sigmoid are the activation functions.
[0153] Finally, the attention weights from average pooling and max pooling are combined and used to adjust the input channels:
[0154] out=avg_weight*x+max_weight*x
[0155] For ECG signal processing, the channel attention mechanism has the following advantages:
[0156] Adaptively prioritizing different channels: Self-attention mechanisms focus on temporal signals, while channel attention mechanisms focus on channel information, automatically learning the importance of these signals and adjusting their contributions accordingly, thereby improving classification accuracy.
[0157] Enhancing model interpretability: Channel attention weights can be used to understand the model's decision-making process. For example, we can analyze the weights to understand which channels are more important for a specific task.
[0158] Improving model performance: By adaptively adjusting the contribution of channels, the channel attention mechanism can help the model better utilize the input signal, thereby improving the model's performance.
[0159] In this embodiment, the first classifier is used to classify heart rate data in the dataset to be applied based on the output information of the fully connected layer encoder. It is understood that the first classifier receives the encoder's output, performs classification, and obtains a binary classification result: normal N(0) and other classes (1). The encoder's output is [batch_size, 360, 64], and the first classifier consists of an adaptive max-pooling layer and point convolutions.
[0160] The encoder's output is [batch_size, 360, 64]. After an adaptive max-pooling layer, it becomes [batch_size, 360, 1]. Then, it passes through a ReLU6 activation function to get the output [batch_size, 360, 1]. This output is then fed into a point convolutional layer with in_channel = 360, out_channel = 2, and kernel = 1. The resulting output is [batch_size, 2, 1]. Finally, the last dimension is compressed to get [batch_size, 2]. If the final classification is 0, it is directly connected to the output of class 0 (normal class). The classification result controls whether encoder_input and encoder transmit data to decoder. If it is class 0, no data is transmitted. If it is class 1, the decoder and a second classifier need to perform further classification.
[0161] This fully connected layer decoder consists of a layer normalization layer, a multi-head attention layer, a feedforward network layer, and a masked multi-head attention layer. Multiple decoding layers constitute the decoder. This embodiment uses only one decoding layer, which is also the decoder. In this embodiment, the encoder output is passed to the multi-head attention layer, and the encoder_input is passed to the masked multi-head attention layer. These two channels are connected when the result of the first classifier is 1. Specifically, the encoder_input is first input to the masked multi-head attention layer. Next, it is transmitted to the first layer normalization layer, and the encoder_input and the first layer normalization layer are residually connected. The output of the first normalization layer is transmitted to the multi-head attention layer, and also to the second layer normalization layer for residual connection. After the multi-head attention layer transmits to the second layer normalization layer, it is transmitted to the feedforward network layer, and also branches to the third layer normalization layer for residual connection. The feedforward network transmits to the third layer normalization layer, and then to the second classifier.
[0162] The second classifier further classifies the abnormal classes from the first classifier to determine which of the four classes (S, F, V, Q). The decoder output [batch_size, 360, 64] is input to the classifier. The classifier consists of an adaptive max-pooling layer and a fully connected layer. [batch_size, 360, 64] enters the adaptive max-pooling layer to obtain [batch_size, 360, 1], performs ReLU6 activation to compress the last dimension to obtain [batch_size, 360], adds a dropout layer with probability p = 0.2, and feeds it into a linear layer to obtain [360, 4]. The output is [batch_size, 4], and the result is finally output.
[0163] In this embodiment, 5-fold cross-validation is used during model training, with each run lasting 100 epochs. Binary Cross Entropy Loss is used for Class 1, and Cross Entropy Loss is used for Class 2. The two losses are then summed to obtain the total homeotropic loss: 0.4 * loss1 + 0.6 * loss2. The AamaW optimizer is used, with weight decay of 1e-3 to prevent overfitting, and a learning rate of 0.001. The batch size is 1024. Early stopping and self-learning rate reduction are implemented during training. Early stopping stops training if the loss does not decrease for 11 consecutive epochs. Self-learning rate reduction multiplies the learning rate by 0.6 after each instance where the loss fails to decrease.
[0164] In summary, this embodiment addresses the common problem of database imbalance by using multi-database hybrid sampling and averaging. Since existing Transformers input sentences composed of words, this embodiment transforms these words into a multi-dimensional vector through an embedding layer. However, ECG is a 1D signal, with only one voltage signal per time step, thus it doesn't allow for word embedding. To solve this problem, this embodiment proposes the BGUE2 embedding layer, enabling the ECG signal to be suitable for the transformer.
[0165] Furthermore, due to the imbalance in ECG data, the proportion of N samples is much larger than that of other samples, causing the network prediction to be more biased towards predicting N samples, resulting in low accuracy for other samples. Therefore, this embodiment uses sensitive cost learning + auxiliary classifier + BGUE2Tnet, and averages lead signals by sampling from multiple databases. Traditional network training performs well on the training set, but its performance deteriorates significantly when placed on new samples. Current practices involve taking a small subset of new samples and training the network in mini-batch before inference. The data preprocessing method and new network proposed in this embodiment can achieve good results directly on new samples without mini-batch retraining.
[0166] This invention provides a heart rate classification system, comprising:
[0167] The first module is used to acquire electrocardiogram data from several heart rate databases;
[0168] The second module is used to fuse the electrocardiogram data in the several databases to obtain the dataset to be applied;
[0169] The third module is used to train the heart rate classification model using the dataset to be applied;
[0170] The fourth module is used to analyze the type of heartbeat in the current electrocardiogram using the trained heartbeat classification model;
[0171] The heartbeat classification model includes an embedding layer, a position encoding module, a fully connected layer encoder, a fully connected layer decoder, a first classifier, a second classifier, and an output module.
[0172] The embedding layer is used to extract spatial and temporal features from the electrocardiogram data in the dataset to be applied;
[0173] The output terminal of the sum of the output signal of the embedded layer and the output signal of the position encoding module is connected to the input terminal of the fully connected layer encoder and the first input terminal of the fully connected layer decoder, respectively; the first output terminal of the fully connected layer encoder is connected to the second input terminal of the fully connected layer decoder; the second output terminal of the fully connected layer encoder is connected to the input terminal of the first classifier; the output terminal of the fully connected layer decoder is connected to the input terminal of the second classifier; the output terminals of the first classifier and the second classifier are both connected to the input terminal of the output module, and the output terminal of the output module is used to output the heart rate classification result.
[0174] The content of the method embodiments of the present invention is applicable to the system embodiments. The specific functions implemented in the system embodiments are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above methods.
[0175] This invention provides a heart rate classification device, comprising:
[0176] At least one memory for storing programs;
[0177] At least one processor is used to load the program for execution. Figure 1 The heartbeat classification method shown.
[0178] The content of the method embodiments of the present invention is applicable to the device embodiments. The specific functions implemented by the device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above methods.
[0179] This invention provides a computer storage medium storing a computer-executable program, which, when executed by a processor, is used to implement... Figure 1 The heartbeat classification method shown.
[0180] The content of the method embodiments of the present invention is applicable to the storage medium embodiments. The specific functions implemented by the storage medium embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above methods.
[0181] Furthermore, embodiments of the present invention also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform... Figure 1 The heartbeat classification method shown.
[0182] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited to the above embodiments, and various changes can be made within the scope of knowledge possessed by those skilled in the art without departing from the spirit of the present invention. Furthermore, the embodiments of the present invention and the features thereof can be combined with each other unless otherwise specified.
Claims
1. A method for classifying heartbeats, characterized in that, Includes the following steps: Obtain electrocardiogram data from several heart rate databases; The electrocardiogram data from the aforementioned databases are fused to obtain the dataset to be used; The heart rate classification model is trained using the dataset to be applied. The trained heartbeat classification model is used to analyze the heartbeat type in the current electrocardiogram. The heart rate classification model includes an embedding layer, a position encoding module, a fully connected encoder, a fully connected decoder, a first classifier, a second classifier, and an output module. The embedding layer is an embedding layer of UNet based on a 1D temporal sequence and a bidirectional GRU. The position encoding module uses sine and cosine position encoding to encode the position of the ECG data in the dataset to be applied; the size of the position encoding is the same as the size of the output signal of the embedding layer. The fully connected encoder includes at least three encoding layers, which are cascaded, and each encoding layer includes a first normalization layer. The fully connected layer decoder comprises a multi-head attention layer, a feedforward network, a channel attention layer, and a second normalization layer; the first classifier consists of an adaptive max-pooling layer and point convolutions, used to classify heartbeats in the ECG data of the dataset to be applied based on the output information of the fully connected layer encoder; the second classifier, composed of an adaptive max-pooling layer and a fully connected layer, further classifies abnormal classes in the first classifier; the embedding layer is used to extract spatial and temporal features from the ECG data of the dataset to be applied. The output terminal of the sum of the output signal of the embedded layer and the output signal of the position encoding module is connected to the input terminal of the fully connected layer encoder and the first input terminal of the fully connected layer decoder, respectively; the first output terminal of the fully connected layer encoder is connected to the second input terminal of the fully connected layer decoder; the second output terminal of the fully connected layer encoder is connected to the input terminal of the first classifier; the output terminal of the fully connected layer decoder is connected to the input terminal of the second classifier; the output terminals of the first classifier and the second classifier are both connected to the input terminal of the output module, and the output terminal of the output module is used to output the heart rate classification result.
2. The heart rate classification method according to claim 1, characterized in that, The embedding layer includes: Input layer; Four downsampling layers, the four downsampling layers including a first downsampling layer, a second downsampling layer, a third downsampling layer and a fourth downsampling layer; Four upsampling layers, the four upsampling layers including a first upsampling layer, a second upsampling layer, a third upsampling layer and a fourth upsampling layer; The system comprises two first convolutional layers, a left first convolutional layer and a right first convolutional layer. The input of the left first convolutional layer is connected to the input layer, the first output of the left first convolutional layer is connected to the first input of the first upsampling layer, the second output of the left first convolutional layer is connected to the input of the first downsampling layer, and the input of the right first convolutional layer is connected to the output of the first upsampling layer. The output of the right first convolutional layer serves as the output of the embedding layer. The system comprises two second convolutional layers, a left second convolutional layer and a right second convolutional layer. The input of the left second convolutional layer is connected to the output of the first downsampling layer, the first output of the left second convolutional layer is connected to the first input of the second upsampling layer, the second output of the left second convolutional layer is connected to the input of the second downsampling layer, the input of the right second convolutional layer is connected to the output of the second upsampling layer, and the output of the right second convolutional layer is connected to the second input of the first upsampling layer. Two third convolutional layers, including a left third convolutional layer and a right third convolutional layer, wherein the input of the left third convolutional layer is connected to the output of the second downsampling layer, the first output of the left third convolutional layer is connected to the first input of the third upsampling layer, the second output of the left third convolutional layer is connected to the input of the third downsampling layer, the input of the right third convolutional layer is connected to the output of the third upsampling layer, and the output of the right second convolutional layer is connected to the second input of the second upsampling layer. Two fourth convolutional layers, including a left fourth convolutional layer and a right fourth convolutional layer, wherein the input of the left fourth convolutional layer is connected to the output of the third downsampling layer, the first output of the left fourth convolutional layer is connected to the first input of the fourth upsampling layer, the second output of the left fourth convolutional layer is connected to the input of the fourth downsampling layer, the input of the right fourth convolutional layer is connected to the output of the fourth upsampling layer, and the output of the right fourth convolutional layer is connected to the second input of the third upsampling layer; The fifth convolutional layer, the input of which is connected to the output of the fourth downsampling layer; A bidirectional GRU layer, the input of which is connected to the output of the fifth convolutional layer, and the output of which is connected to the second input of the fourth upsampling layer.
3. The heart rate classification method according to claim 2, characterized in that, Before the output signals of the five convolutional layers are input into the bidirectional GRU layer, the last two dimensions of the output signals of the five convolutional layers are swapped; before the output signals of the bidirectional GRU layer are input into the fourth upsampling layer, the last two dimensions of the output signals of the bidirectional GRU layer are swapped.
4. The heart rate classification method according to claim 1, characterized in that, The input of the first normalization layer is connected to the output of the sum of the output signal of the embedding layer and the output signal of the position encoding module; The input of the multi-head attention layer is connected to the first output of the first normalization layer; The first input of the feedforward network is connected to the output of the multi-head attention layer, and the second input of the feedforward network is connected to the second output of the first normalization layer. The input of the channel attention layer is connected to the first output of the feedforward network; The first input of the second normalization layer is connected to the output of the channel attention layer, and the second input of the second normalization layer is connected to the second output of the feedforward network.
5. The heart rate classification method according to claim 1, characterized in that, When the classification result output by the first classifier is of the first type, the first connection channel and the second connection channel of the fully connected layer decoder are both connected. The first connection channel is the connection channel between the fully connected layer decoder and the fully connected layer encoder, and the second connection channel is the connection channel between the output signal of the fully connected layer decoder and the output signal of the embedded layer and the output signal of the position encoding module.
6. A heart rate classification system, characterized in that, include: The first module is used to acquire electrocardiogram data from several heart rate databases; The second module is used to fuse the electrocardiogram data in the several databases to obtain the dataset to be applied; The third module is used to train the heart rate classification model using the dataset to be applied; The fourth module is used to analyze the type of heartbeat in the current electrocardiogram using the trained heartbeat classification model; The heartbeat classification model includes an embedding layer, a position encoding module, a fully connected encoder, a fully connected decoder, a first classifier, a second classifier, and an output module. The embedding layer is an embedding layer of UNet based on 1D temporal embedding with a bidirectional GRU. The position encoding module uses sine and cosine position encoding to encode the position of ECG data in the dataset to be applied; the size of the position encoding is the same as the size of the output signal of the embedding layer. The fully connected encoder includes at least three encoding layers connected in series; each encoding layer includes a first normalization layer, a multi-head attention layer, a feedforward network, a channel attention layer, and a second normalization layer. The fully connected decoder includes a layer normalization layer, a multi-head attention layer, a feedforward network layer, and a masked multi-head attention layer. The first classifier consists of an adaptive max-pooling layer and point convolutions, used to classify heartbeats in the ECG data in the dataset to be applied based on the output information of the fully connected encoder. The second classifier further refines the abnormal classes in the first classifier and consists of an adaptive max-pooling layer and a fully connected layer. The embedding layer is used to extract spatial and temporal features from the electrocardiogram data in the dataset to be applied; The output terminal of the sum of the output signal of the embedded layer and the output signal of the position encoding module is connected to the input terminal of the fully connected layer encoder and the first input terminal of the fully connected layer decoder, respectively; the first output terminal of the fully connected layer encoder is connected to the second input terminal of the fully connected layer decoder; the second output terminal of the fully connected layer encoder is connected to the input terminal of the first classifier; the output terminal of the fully connected layer decoder is connected to the input terminal of the second classifier; the output terminals of the first classifier and the second classifier are both connected to the input terminal of the output module, and the output terminal of the output module is used to output the heart rate classification result.
7. A heart rate classification device, characterized in that, include: At least one memory for storing programs; At least one processor is configured to load the program to execute the heartbeat classification method as described in any one of claims 1-5.
8. A computer storage medium, characterized in that, It contains a computer-executable program, which, when executed by a processor, is used to implement the heart rate classification method as described in any one of claims 1-5.
Citation Information
Patent Citations
Electrocardiosignal real-time classification method, device and readable storage medium
CN114041800A
Heart beat classification model training method, classification method, equipment and storage medium
CN116342963A