A long-range electrocardiogram heartbeat classification method and device combined with memory features

CN122196782BActive Publication Date: 2026-10-30SHENZHEN CAREWELL ELECTRONICS
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202610263776.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-03-05
Publication Date
2026-10-30
Estimated Expiration
2046-03-05

AI Technical Summary

Technical Problem

本发明一方面通过局部键值缓存或全局记忆压缩、将前序片段的关键特征以记忆形式保留并用于当前片段的分类决策,由此可以解决常规方案难以捕捉心电信号长程依赖关系的问题;另一方面通过下采样或划片等嵌入编码方式可以压缩输入表示、减少计算与存储开销、提高计算效率;再一方面,通过分段序列的顺序分类机制,也可以降低长序列处理时的计算与存储开销,提高计算效率

Benefits of technology

[0018]本发明实施例提供了一种结合记忆特征的长程心电图心搏分类方法、装置、电子设备及计算机可读存储介质。由上述内容可知,本发明实施例先以Transformer的编码器为核心设计一个片段分类模型框架,并为该框架的嵌入层和编码器分别设置了对应的三类嵌入编码模式(点对点嵌入模式、下采样嵌入模式、划片嵌入模式)和两类记忆融合模式(局部键值缓存模式、全局记忆压缩模式),并对三类嵌入与两类融合模式进行组合得到六类组合模式,并基于当前框架为每类组合模式设置对应的定制分类模型。然后通过数据采集构建通用模型数据集(即第一数据集)对六类定制模型分别进行训练。并在训练结束后,对用户指定的长程心电图进行分段,并基于用户指定的款定制模型对所有分段进行心搏分类、并在对每段分类识别时对前一段的历史记忆特征进行特征融合、并对所有片段的分类向量进行顺次拼接并对拼接序列进行分类后处理得到对应的全程心搏类型序列向当前用户反馈。本发明实施例一方面通过局部键值缓存或全局记忆压缩、将前序片段的关键特征以记忆形式保留并用于当前片段的分类决策,解决了常规方案难以捕捉心电信号长程依赖关系的问题;另一方面通过下采样或划片等嵌入编码方式压缩了输入表示、减少了计算与存储开销、提高了计算效率;再一方面,通过分段序列的顺序分类机制也降低了长序列处理时的计算与存储开销,提高了计算效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122196782B_ABST
    Figure CN122196782B_ABST
Patent Text Reader

Abstract

The embodiment of the application relates to a long-range electrocardiogram heartbeat classification method and device combined with memory features, the method comprising: setting a segment classification model framework, and setting six types of customized classification models based on a combination of three types of embedding coding modes and two types of memory fusion modes; constructing a first data set to train the six types of customized models; segmenting and traversing a long-range electrocardiogram input by a user, inputting a current segment and corresponding previous segment historical memory features into a user-specified customized model for processing during traversal, and sequentially splicing all segment classification vectors obtained after traversal according to time sequence and performing classification post-processing on the splicing sequence to obtain a whole-range heartbeat type sequence, which is fed back to the user. The application can establish long-range dependencies, reduce calculation and storage overhead, and improve calculation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, and in particular to a method and apparatus for long-term electrocardiogram heart rate classification that incorporates memory features. Background Technology

[0002] In the field of long-term electrocardiography (ECG) heart rate classification, existing technologies typically employ deep learning models to analyze ECG segments independently, lacking effective utilization of historical ECG information, resulting in significant limitations when processing long-sequence data. Conventional methods suffer from two main drawbacks: First, the models struggle to capture long-term dependencies in ECG signals. Due to the temporal continuity of cardiac activity, analyzing only the current segment ignores its association with previous segments, affecting the accuracy of identifying intermittent abnormal heartbeats (such as occasional premature ventricular contractions). Second, existing models are computationally inefficient when processing continuous ECGs lasting several hours to tens of hours, with memory usage increasing linearly with sequence length, limiting their deployment capabilities in embedded devices or real-time systems. Summary of the Invention

[0003] The purpose of this invention is to address the shortcomings of existing technologies by providing a long-term electrocardiogram (ECG) heart rate classification method, device, electronic device, and computer-readable storage medium that incorporates memory features. This invention first designs a segment classification model framework based on the Transformer encoder. For the embedding layer and encoder of this framework, three types of embedding encoding modes (point-to-point embedding mode, downsampling embedding mode, and slice embedding mode) and two types of memory fusion modes (local key-value caching mode and global memory compression mode) are set. The three types of embedding and the two types of fusion modes are combined to obtain six combined modes, and a corresponding customized classification model is set for each combined mode based on the current framework. Then, a general model dataset (i.e., the first dataset) is constructed through data collection, and the six customized models are trained respectively. After training, the user-specified long-term ECG is segmented, and heart rate classification is performed on all segments based on the user-specified customized models. During the classification and recognition of each segment, the historical memory features of the previous segment are fused, and the classification vectors of all segments are sequentially concatenated. The concatenated sequence is then classified and processed to obtain the corresponding full-length heart rate type sequence, which is then fed back to the current user. This invention addresses the problem of conventional schemes failing to capture long-range dependencies in electrocardiogram signals by using local key-value caching or global memory compression to retain key features of preceding segments in memory form and use them for classification decisions of the current segment. On the other hand, it compresses input representation, reduces computational and storage overhead, and improves computational efficiency through embedding coding methods such as downsampling or slicing. Furthermore, it reduces computational and storage overhead and improves computational efficiency by using a segmented sequence sequential classification mechanism.

[0004] To achieve the above objectives, a first aspect of the present invention provides a long-term electrocardiogram heartbeat classification method incorporating memory features, the method comprising: A deep learning model framework, denoted as the segment classification model framework, is set up to classify and identify the current ECG signal segment by combining the memory features of previous segments. Three types of embedding encoding modes and two types of memory fusion modes are respectively set for the embedding layer and encoder of the segment classification model framework. The three types of embedding encoding modes and the two types of memory fusion modes are combined to obtain six types of embedding-fusion modes. A corresponding customized classification model is set for each type of embedding-fusion mode based on the segment classification model framework. The three types of embedding encoding modes include point-to-point embedding mode, downsampling embedding mode, and slice embedding mode. The two types of memory fusion modes include local key-value caching mode and global memory compression mode. The segment classification model framework and each of the customized classification models are used to embed and encode the ECG signal segment X input to the model to obtain the embedding vector E, and based on the historical memory features G input to the model... old The feature vector H is obtained by feature encoding with the embedded vector E, and the updated memory feature G is obtained by updating the memory feature based on the encoding process data. new The system outputs the data and performs classification feature mapping on the feature vector H to obtain the feature vector Y. Based on the feature vector Y, it performs classification probability prediction to obtain the segment classification vector P and outputs it. Each customized classification model corresponds to a unique model index. The dataset used to construct a general model through data collection is denoted as the first dataset. Based on the first dataset, the customized classification models for the six categories are trained respectively; After all six types of customized models have been trained, the user inputs a long-term electrocardiogram and a customized model index as the corresponding current electrocardiogram and current index. The customized classification model corresponding to the current index is taken as the current customized model; and an initialized historical memory feature G is set according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is then segmented to obtain multiple corresponding signal segments. All signal segments are sequentially traversed in chronological order; during this traversal, the currently traversed signal segment is designated as the current segment; and the current segment is used as the corresponding ECG signal segment X and the historical memory feature G. old The fragment classification vector P and the updated memory feature G are input together into the current customized model for processing to obtain the corresponding fragment classification vector P and the updated memory feature G. new ; and based on the updated memory feature G newRegarding the historical memory feature G old Reset; At the end of this round of traversal of all signal segments, the obtained segment classification vectors P are sequentially concatenated according to time sequence, and the concatenated sequence is classified and processed to obtain the corresponding whole heartbeat type sequence, which is then fed back to the current user.

[0005] Preferably, the fragment classification model framework and the model structure of each of the customized classification models include the embedding layer, the encoder, the memory update module, the feature mapping layer, and the Softmax function layer; The input terminal of the embedded layer is used to receive the electrocardiogram signal segment X, and the output terminal is connected to the first input terminal of the encoder; the second input terminal of the encoder is used to receive the historical memory feature G. old The output terminal is connected to the feature mapping layer; the memory update module is connected to the encoder, and its output terminal is used to output the corresponding updated memory feature G. new The output of the feature mapping layer is connected to the input of the Softmax function layer; the output of the Softmax function layer is used to output the corresponding segment classification vector P. The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding embedding encoding mode to obtain the corresponding embedding vector E and send it to the encoder; The electrocardiogram (ECG) signal segment X consists of multiple ECG data points x. i Composition; each of the said electrocardiogram data x i Each sampling point corresponds to a single sampling point and consists of multiple single-lead data points at that sampling point; 1 ≤ index i ≤ N X N X This represents the total number of sampling points in the current segment; The embedding vector E consists of multiple embedding features e j Composition; each embedded feature e j For a given embedding point, 1 ≤ index j ≤ N E N E This represents the total number of embedding points in the current vector; the temporal correspondence between embedding points and sampling points is determined by the corresponding embedding coding mode. The encoder is composed of multiple l-th coding layers connected sequentially, where 1 ≤ index l ≤ L, and the total number of coding layers L is a preset positive integer, L > 3. Each l-th coding layer is implemented based on the model structure of the coding module of the Transformer model framework, and is composed of a corresponding multi-head self-attention layer, a first residual connection and layer normalization layer, a feedforward neural network layer, and a second residual connection and layer normalization layer connected sequentially. midThe attention span of the multi-head self-attention layer of the l-th encoding layer is defined by a preset local window width L. win Decision; L mid The attention range of the multi-head self-attention layer of the l-th coding layer from +1 to the L-th layer is the global range; L mid For the preset intermediate layer index, 1 < L mid <L; 1 <L win <N E ; The encoder is used to perform the corresponding memory fusion mode according to the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; The feature vector H consists of multiple feature vectors h j Composition; the feature vector h j With the embedded feature e j One-to-one correspondence; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output; The feature mapping layer is implemented based on the MLP model structure; the feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y and send it to the Softmax function layer; Wherein, the feature vector Y is composed of multiple feature vectors y j Composition; the feature vector y j With the feature vector h j One-to-one correspondence; each of the aforementioned feature vectors y j Given the corresponding S characteristic scalars y j,s Composition, 1≤index s≤S, where S is the total number of preset heartbeat types; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, the fragment classification vector P consists of multiple classification vectors p j Composition; the classification vector p j With the feature vector y j One-to-one correspondence; the classification vector p j Given the corresponding S predicted probabilities ρ j,s Composition; each of the predicted probabilities ρ j,s Corresponding to a type of heartbeat; the heartbeat type includes at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat; The six types of embedding-fusion modes include point-to-point embedding-local key-value caching mode, downsampling embedding-local key-value caching mode, slicing embedding-local key-value caching mode, point-to-point embedding-global memory compression mode, downsampling embedding-global memory compression mode, and slicing embedding-global memory compression mode; The first dataset consists of multiple first data records; each first data record includes a first training segment sequence, a first label vector sequence, a second label vector sequence, and a third label vector sequence; the first training segment sequence is a segmented sequence of an original long-term electrocardiogram signal, formed by sequentially sorting multiple first training segments; the first label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the point-to-point embedding mode; the second label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the downsampling embedding mode; the third label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the slice embedding mode; the first label vector sequence is formed by sequentially sorting multiple first label vectors; the second label vector sequence is formed by sequentially sorting multiple second label vectors; the third label vector sequence is formed by sequentially sorting multiple third label vectors; each of the first label vector, the second label vector, and the third label vector corresponds one-to-one with the first training segment.

[0006] Preferably, the inference process of the customized classification model corresponding to the point-to-point embedding-local key-value caching mode is as follows: The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder; Wherein, the embedding feature e j The encoding process is as follows: ; , The first embedding coding weight matrix and the first embedding coding bias vector are respectively; the total number of embedding points N of the embedding vector E is 1. E The total number of sampling points N of the electrocardiogram signal segment X X They are equal, and there is a one-to-one correspondence between index j and index i; The encoder is used to operate according to the corresponding local key-value caching pattern, based on the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; Among them, the historical memory feature G oldIt consists of L corresponding historical key-value vector groups; each historical key-value vector group consists of R single-head key-value vector pairs, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations; each single-head key-value vector pair consists of a set of corresponding historical key vectors. Historical value vector Composition; 1 ≤ index r ≤ R; the history key vector and the historical value vector The length of the vector is denoted as N. old , 1 < N old <N E The historical memory feature G old The initial value is all zero features; The inference process of the l-th encoding layer consists of four parts: the multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. The reasoning process of the multi-head self-attention layer is as follows: Calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 The feature vector output by the (l-1)th layer, where the feature vector H is when l=1. l-1=0 =E; , , The query weight matrix, key weight matrix, and value weight matrix of the r-th head of the l-th encoding layer; the query vector Q l,r The key vector K l,r The value vector V l,r The feature dimensions are the same, denoted as d l,r ; The key vector K is processed by vector concatenation. l,r The corresponding historical key vector Feature fusion is performed to obtain the corresponding fusion key vector. For the value vector The corresponding historical value vector The fusion value vector corresponding to feature fusion : , ; Where concate() is a vector concatenation function; the fusion key vector and the fusion value vector The length of the vector is denoted as N. con =N old +N E The fusion key vector From the corresponding N con eigenvectors Composition, the fused value vector From the corresponding N con eigenvectors Composition, 1 ≤ index ≤N con ; Set the attention mask matrix M l ; In 1≤l≤L mid At that time, based on the local window width L win Calculate the starting position ws of the local window corresponding to each index j. j Local window end position we j And set a shape of N E ×N con The matrix is ​​used as the corresponding attention mask matrix M l And the attention mask matrix M l Each matrix element is denoted as the corresponding And based on each of the matrix units The corresponding local window start position ws j and the end position of the local window we j Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of N. E ×N con The all-zero matrix is ​​used as the corresponding attention mask matrix M. l ; Based on the query vector Q l,r The fusion bond vector The fused value vector The feature dimension d l,r The attention mask matrix M l Perform self-attention operations to obtain the corresponding single-head attention vector A. l,r : ; For R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions.l The attention vector A l The shape is N E ×d l Feature dimension d l For R feature dimensions d l,r The sum; The inference process of the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l The feature vector output by the first residual connection and the layer normalization layer; The reasoning process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first weight matrix and the second weight matrix corresponding to the current feedforward neural network layer; , For the first bias vector and the second bias vector corresponding to the current feedforward neural network layer; F l This refers to the feature vector output by the current feedforward neural network layer. The inference process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l The feature vector output by the l-th encoding layer; The feature vector H output by the encoder is the feature vector H output by the l-th coding layer in the L-th layer. l=L ; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output; Wherein, the updated memory feature G new It consists of L corresponding updated historical key-value vector groups; each updated historical key-value vector group consists of R updated single-head key-value vector pairs; each updated single-head key-value vector pair consists of a set of updated historical key vectors. Updated historical value vector Composition; the updated history key vector The corresponding fusion bond vector The last N old eigenvectors Composition, the updated historical value vector The corresponding fusion bond vector The last N old eigenvectors composition; The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer. The mapping process of the feature vector Y is as follows: ; ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E The feature vector y j Composition; the feature vector y j S feature scalars y j,s composition; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, each of the predicted probabilities ρ of the segment classification vector P j,s for: .

[0007] Preferably, the difference between the inference process of the custom classification model corresponding to the downsampling embedding-local key-value caching mode and the inference process of the custom classification model corresponding to the point-to-point embedding-local key-value caching mode is as follows: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset one-dimensional convolution operation function Conv1D a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder; The encoding process of the embedding vector E is as follows: ; a is the kernel size, b is the stride; the total number of embedding points N of the embedding vector E E =floor(N X / b), floor() is the floor function, N E <N X The embedding vector E is composed of N E eigenvectors ej Composition; The correspondence between index j and index i is as follows: .

[0008] Preferably, the difference between the inference process of the custom classification model corresponding to the slice embedding-local key-value caching mode and the inference process of the custom classification model corresponding to the point-to-point embedding-local key-value caching mode is as follows: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slicing embedding pattern to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset sub-segment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(N X / L C ), ceiling() is the floor function, which rounds up each of the sub-segments X. c From the most L C The electrocardiogram data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C The sub-fragment X c The segment length is extended to L C ; and for each of the aforementioned sub-fragments X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E The eigenvectors e j The corresponding embedding vector E is sent to the encoder; Wherein, the feature vector e j The feature mapping process is as follows: ; The second embedding encoding weight matrix is ​​preset; the correspondence between index j and index i is as follows: .

[0009] Preferably, the inference process of the customized classification model corresponding to the point-to-point embedding-global memory compression mode is as follows: The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder; Wherein, the embedding feature e j The encoding process is as follows: ; , The first embedding coding weight matrix and the first embedding coding bias vector are respectively; the total number of embedding points N of the embedding vector E is 1. E The total number of sampling points N of the electrocardiogram signal segment X X They are equal, and there is a one-to-one correspondence between index j and index i; The encoder is used to compress the corresponding global memory mode according to the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; Among them, the historical memory feature G old From the corresponding N slot eigenvectors Composition, 1 ≤ index o ≤ N slot N slot The preset total number of memory slots, 1 < N slot <N E The feature vector Feature dimensions and the embedded feature e j The feature dimensions remain consistent; the historical memory feature G old The initial value is the weight matrix parameter W of the currently customized classification model. mem ; The inference process of the l-th encoding layer consists of four parts: the multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. The reasoning process of the multi-head self-attention layer is as follows: Regarding the historical memory feature G old The feature vector H0 is obtained by concatenating the embedded vector E with the feature vector H0. Wherein, the feature vector H0 is composed of N slot +N E Feature vector Composition, 1 ≤ index ≤N slot +N E ; the first N slot The feature vectors With N slot The feature vectors One-to-one correspondence, followed by N E The feature vectors With N E The embedded feature e j One-to-one correspondence; Calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 For the feature vector of the l-th encoding layer as input, H is when l=1. l-1 =H0;1≤indexr≤R, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations; , , The query weight matrix, key weight matrix, and value weight matrix of the r-th head of the l-th encoding layer; the query vector Q l,r The key vector K l,r The value vector V l,r The feature dimensions are the same, denoted as d l,r ; Set the attention mask matrix M l ; In 1≤l≤L mid When, set a shape as (N) slot +N E )×(N slot +N E The matrix M is used as the corresponding attention mask matrix. l And the attention mask matrix M l Each matrix element is denoted as m. u,v , 1≤index u, v≤(N) slot +N E ); and based on the local window width L win Calculate the starting position ws of the local window corresponding to each index u. u Local window end position we u ; and based on each of the matrix units m u,v The corresponding local window start position ws u and the end position of the local window we u Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of (N) slot +N E )×(N slot +N E The all-zero matrix is ​​used as the corresponding attention mask matrix M. l ; Based on the query vector Q l,rThe key vector K l,r The value vector V l,r The feature dimension d l,r The attention mask matrix M l Perform self-attention operations to obtain the corresponding single-head attention vector A. l,r : ; For R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions. l The attention vector A l The shape is (N) slot +N E )×d l Feature dimension d l For R feature dimensions d l,r The sum; The inference process of the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l The feature vector output by the first residual connection and the layer normalization layer; The reasoning process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first weight matrix and the second weight matrix corresponding to the current feedforward neural network layer; , For the first bias vector and the second bias vector corresponding to the current feedforward neural network layer; F l This refers to the feature vector output by the current feedforward neural network layer. The inference process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l The feature vector output by the l-th encoding layer; The feature vector H output by the l-th encoding layer in the L-th layer l=L By N slot +N E Feature vector composition; The feature vector H output by the encoder is composed of feature vector H L The after N E eigenvectors composition; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output, specifically: From the feature vector H L The first N slot eigenvectors Form the corresponding query vector Q slot And by the feature vector H L The after N E eigenvectors The eigenvectors formed serve as the corresponding key vectors K. slot Value vector V slot ; and based on the query vector Q slot The key vector K slot and the value vector V slot Perform cross-attention calculation and use the result as the updated memory feature G. new And output; in, , , , The query vector Q slot The key vector K slot and the value vector V slot The feature dimensions are the same, denoted as d slot ; The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer. The mapping process of the feature vector Y is as follows: ; ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E The feature vector y j Composition; the feature vector y j S feature scalars y j,s composition; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, each of the predicted probabilities ρ of the segment classification vector Pj,s for: .

[0010] Preferably, the difference between the inference process of the customized classification model corresponding to the downsampling embedding-global memory compression mode and the inference process of the customized classification model corresponding to the point-to-point embedding-global memory compression mode is as follows: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset one-dimensional convolution operation function Conv1D a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder; The encoding process of the embedding vector E is as follows: ; a is the kernel size, b is the stride; the total number of embedding points N of the embedding vector E E =floor(N X / b), floor() is the floor function, N E <N X The embedding vector E is composed of N E eigenvectors e j Composition; The correspondence between index j and index i is as follows: .

[0011] Preferably, the difference between the reasoning process of the customized classification model corresponding to the slice embedding-global memory compression mode and the reasoning process of the customized classification model corresponding to the point-to-point embedding-global memory compression mode is as follows: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slicing embedding pattern to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset sub-segment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(N X / L C ), ceiling() is the floor function, which rounds up each of the sub-segments X. c From the most L C The electrocardiogram data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C The sub-fragment X c The segment length is extended to L C; and for each of the aforementioned sub-fragments X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E The eigenvectors e j The corresponding embedding vector E is sent to the encoder; Wherein, the feature vector e j The feature mapping process is as follows: ; The second embedding encoding weight matrix is ​​preset; the correspondence between index j and index i is as follows: .

[0012] Preferably, the general model dataset constructed through data collection is denoted as the first dataset, and specifically includes: Multiple raw long-term ECGs were collected through multiple publicly available long-term ECG data acquisition channels; the publicly available long-term ECG data acquisition channels include multiple publicly available ECG databases; Each original long-range electrocardiogram (ECG) is used as the current ECG; the current ECG is segmented to obtain multiple corresponding signal segments; all signal segments of the current ECG are traversed once; during this traversal, the currently traversed signal segment is used as the current segment; the data format of the ECG signal segment X is used to convert the current segment to obtain the corresponding first training segment; the current first training segment is embedded and encoded according to the embedding encoding modes of the point-to-point embedding mode, the downsampling embedding mode, and the slicing embedding mode to obtain the corresponding three types of embedding vectors; each type of embedding vector is used as the current vector, and the label classification vectors corresponding to all embedding points of the current vector are manually labeled, and the label classification vectors of all embedding points of the current vector form a pair. The corresponding first label vector, second label vector, or third label vector; and at the end of this round of traversal, the corresponding first training segment sequence is formed by all the first training segments of the current electrocardiogram in chronological order, the corresponding first label vector sequence is formed by all the first label vectors of the current electrocardiogram in chronological order, the corresponding second label vector sequence is formed by all the second label vectors of the current electrocardiogram in chronological order, and the corresponding second label vector sequence is formed by all the second label vectors of the current electrocardiogram in chronological order; and the corresponding first data record is formed by the first training segment sequence, the first label vector sequence, the second label vector sequence, and the third label vector sequence corresponding to the current electrocardiogram; The first dataset is composed of all the first data records obtained.

[0013] Preferably, the step of training the customized classification models for the six categories based on the first dataset specifically includes: Step 101: Take each of the customized classification models as the current classification model; and take the embedding encoding mode and memory fusion mode corresponding to the current classification model as the corresponding current embedding encoding mode and current memory fusion mode; Step 102: Based on a preset first segmentation ratio, the first dataset is randomly divided into two subsets, denoted as the first training set and the first evaluation set. Wherein, both the first training set and the first evaluation set are composed of multiple first data records; the ratio of the total number of records in the first training set to the total number of records in the first evaluation set satisfies the first segmentation ratio; Step 103: Take the first data record of the first training set as the current training record; Step 104: Record the first training segment sequence of the current training record as the corresponding segment sequence {X}. q}; and take the first label vector sequence, the second label vector sequence, or the third label vector sequence in the current training record that corresponds to the current embedding encoding mode as the corresponding label vector sequence { }; and based on the historical memory feature G corresponding to the current memory fusion mode. old The data format constructs the corresponding current historical memory feature G old And set the current historical memory feature G according to the initial value setting method of the historical memory feature corresponding to the current memory fusion mode. old Perform initialization; Fragment X q For the q-th first training segment, 1 ≤ index q ≤ N Q N Q The total number of segments in the current segment sequence; label vector. For the corresponding q-th first label vector, second label vector, or third label vector; Step 105, sort the segment sequence {X} in ascending order of index q. q All of the fragments X mentioned in} q Perform one round of sequential traversal; and during this round of traversal, change the currently traversed segment X. q As the current electrocardiogram signal segment X and the current historical memory feature G old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are then processed. new As the new current historical memory feature G oldThe segment classification vector P obtained in this process is then used as the corresponding prediction vector. ; and by the prediction vector The corresponding label vector Form a corresponding first prediction-label pair ( , ); and at the end of this traversal, the N obtained in this traversal is... Q The first prediction-label pair ( , Substitute the value into the preset first model loss function to calculate the corresponding first loss value; The first model loss function is based on cross-entropy loss. Step 106: Identify whether the first loss value meets the preset first loss value range; if the first loss value meets the first loss value range, identify whether the current training record is the last first data record of the first training set; if yes, proceed to step 107; otherwise, take the next first data record of the first training set as the new current training record and return to step 104; if the first loss value does not meet the first loss value range, perform a round of modulation on the model parameters of the current classification model based on the preset first model optimizer in the direction of minimizing the first model loss function, and return to step 105 when the modulation ends. The first model optimizer includes the Adam optimizer; Step 107: Take each of the first data records in the first evaluation set as the current evaluation record; take the first training segment sequence of the current evaluation record as the current segment sequence; and take the first label vector sequence, the second label vector sequence, or the third label vector sequence in the current evaluation record that corresponds to the current embedding encoding mode as the corresponding current label vector sequence; and based on the historical memory feature G corresponding to the current memory fusion mode... old The data format constructs the corresponding current historical memory feature G old And set the current historical memory feature G according to the initial value setting method of the historical memory feature corresponding to the current memory fusion mode. old Initialization is performed; and in chronological order, all the first training segments of the current segment sequence are sequentially traversed once; during this traversal, the currently traversed first training segment is used as the current ECG signal segment X and the current historical memory feature G. old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are then processed. new As the new current historical memory feature Gold The segment classification vector P obtained in this process is used as the corresponding current prediction vector; and the current prediction vector and its corresponding label vector form a corresponding second prediction-label pair; and at the end of this traversal, the corresponding F1 score is calculated based on all the second prediction-label pairs obtained in this traversal to obtain the corresponding first F1 score. Step 108: Identify whether the first F1 score meets the preset first F1 score range; if not, return to step 102; if yes, stop training the current classification model and confirm that the current classification model training has ended.

[0014] Preferably, the step of sequentially concatenating all the obtained segment classification vectors P in chronological order and classifying the concatenated sequence to obtain the corresponding whole-process heartbeat type sequence and feeding it back to the current user specifically includes: The obtained segment classification vectors P are sequentially concatenated according to their chronological order to obtain the corresponding full-process classification vector sequence. }; Full-process classification vector sequence { } consists of multiple classification vectors Composition, 1 ≤ embedding point index ≤N total N total The total number of embedding points corresponding to the current full-process classification vector sequence; each of the classification vectors Given the corresponding S predicted probabilities Composition; each of the predicted probabilities Corresponding to one of the aforementioned heartbeat types; the heartbeat types include at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat; And based on the entire classification vector sequence { The corresponding sampling frequency of the current electrocardiogram, the whole-process classification vector sequence { The correspondence between the embedding points of} and the sampling points of the current electrocardiogram is used to classify the entire classification vector sequence { Time information corresponding to each embedding point of} Confirmation is performed; and based on the preset segmented sliding step size and segment duration, the entire classification vector sequence { is evaluated. The sliding segmentation process yields multiple corresponding sequence segments; each sequence segment includes multiple classification vectors. ; Each of the aforementioned sequence segments is taken as the current segment; and all the aforementioned time information is delivered based on the current segment. The center time of the current segment is calculated to obtain the corresponding segment center time; the sum of predicted probabilities for each heartbeat type in the current segment is calculated to obtain the corresponding type probability sum, and the heartbeat type corresponding to the largest type probability sum is taken as the segment heartbeat type corresponding to the current segment; and the segment heartbeat data is composed of the segment center time and the segment heartbeat type corresponding to the current segment. The obtained fragment heartbeat data are sorted according to time sequence to form the corresponding full heartbeat type sequence and fed back to the current user.

[0015] A second aspect of the present invention provides an apparatus for implementing the long-term electrocardiogram heart rate classification method combining memory features as described in the first aspect above. The apparatus includes: a model setting module, a data acquisition module, a model training module, a data receiving module, an analysis and preprocessing module, a long-term electrocardiogram analysis module, and a data feedback module. The model setting module is used to set up a deep learning model framework, denoted as the segment classification model framework, that can classify and identify the current ECG signal segment by combining the memory features of the previous segment. It sets up three types of embedding encoding modes and two types of memory fusion modes for the embedding layer and encoder of the segment classification model framework, respectively. It then combines the three types of embedding encoding modes with the two types of memory fusion modes to obtain six corresponding embedding-fusion modes. Based on the segment classification model framework, it sets up a corresponding customized classification model for each type of embedding-fusion mode. The three types of embedding encoding modes include point-to-point embedding mode, downsampling embedding mode, and slice embedding mode. The two types of memory fusion modes include local key-value caching mode and global memory compression mode. The segment classification model framework and each of the customized classification models are used to embed and encode the ECG signal segment X input to the model to obtain the embedding vector E, and based on the historical memory features G input to the model... old The feature vector H is obtained by feature encoding with the embedded vector E, and the updated memory feature G is obtained by updating the memory feature based on the encoding process data. new The system outputs the data and performs classification feature mapping on the feature vector H to obtain the feature vector Y. Based on the feature vector Y, it performs classification probability prediction to obtain the segment classification vector P and outputs it. Each customized classification model corresponds to a unique model index. The data acquisition module constructs a general model dataset, denoted as the first dataset, through data acquisition. The model training module trains the six customized classification models based on the first dataset. The data receiving module is used to receive the long-term electrocardiogram and the customized model index input by the user after all six types of customized models have been trained, as the corresponding current electrocardiogram and current index. The analysis preprocessing module is used to take the customized classification model corresponding to the current index as the current customized model; and to set an initialized historical memory feature G according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is then segmented to obtain multiple corresponding signal segments. The long-range electrocardiogram (ECG) analysis module is used to perform a sequential traversal of all signal segments according to their time sequence; during this traversal, the currently traversed signal segment is taken as the current segment; and the current segment is used as the corresponding ECG signal segment X and the historical memory feature G. old The fragment classification vector P and the updated memory feature G are input together into the current customized model for processing to obtain the corresponding fragment classification vector P and the updated memory feature G. new ; and based on the updated memory feature G new Regarding the historical memory feature G old Reset; The data feedback module is used to sequentially concatenate all the obtained segment classification vectors P in chronological order at the end of the current round of traversal of all signal segments, and then perform classification and post-processing on the concatenated sequence to obtain the corresponding whole-process heartbeat type sequence and feed it back to the current user.

[0016] A third aspect of the present invention provides an electronic device, including: a memory, a processor, and a transceiver; The processor is used to couple with the memory, read and execute instructions in the memory to implement the steps of the method described in the first aspect above; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

[0017] A fourth aspect of the present invention provides a computer-readable storage medium storing computer instructions that, when executed by a computer, cause the computer to perform the instructions described in the first aspect.

[0018] This invention provides a method, apparatus, electronic device, and computer-readable storage medium for long-term electrocardiogram (ECG) heart rate classification that incorporates memory features. As described above, this invention first designs a segment classification model framework centered on the Transformer encoder. For the embedding layer and encoder of this framework, three types of embedding encoding modes (point-to-point embedding mode, downsampling embedding mode, and slice embedding mode) and two types of memory fusion modes (local key-value caching mode and global memory compression mode) are set respectively. The three types of embedding and the two types of fusion modes are combined to obtain six combined modes, and a corresponding customized classification model is set for each combined mode based on the current framework. Then, a general model dataset (i.e., the first dataset) is constructed through data collection, and the six customized models are trained respectively. After training, the user-specified long-term ECG is segmented, and heart rate classification is performed on all segments based on the user-specified customized model. During the classification and recognition of each segment, the historical memory features of the previous segment are fused, and the classification vectors of all segments are sequentially concatenated. The concatenated sequence is then processed for classification to obtain the corresponding full-process heart rate type sequence, which is then fed back to the current user. The embodiments of the present invention, on the one hand, solve the problem that conventional schemes are difficult to capture long-range dependencies of electrocardiogram signals by using local key-value caching or global memory compression to retain key features of preceding segments in memory form and use them for classification decisions of the current segment; on the other hand, the input representation is compressed by embedding coding methods such as downsampling or slicing, reducing computational and storage overhead and improving computational efficiency; furthermore, the sequential classification mechanism of segmented sequences also reduces the computational and storage overhead when processing long sequences and improves computational efficiency. Attached Figure Description

[0019] Figure 1 This is a schematic diagram of a long-term electrocardiogram heartbeat classification method that combines memory features, provided in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the structure of the fragment classification model framework provided in Embodiment 1 of the present invention; Figure 3 This is a schematic diagram of the encoder structure implemented using the standard encoding module based on the Transformer model framework. Figure 4 This is a schematic diagram of an encoder structure for adapting to a local key-value caching mode, provided in Embodiment 1 of the present invention. Figure 5 This is a schematic diagram of an encoder structure for adapting to a global memory compression mode, provided in Embodiment 1 of the present invention. Figure 6 This is a module structure diagram of a long-term electrocardiogram heart rate classification device that combines memory features, provided in Embodiment 2 of the present invention; Figure 7This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of this invention, and not all embodiments. Based on the embodiments of this invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this invention.

[0021] Embodiment 1 of the present invention provides a long-term electrocardiogram heartbeat classification method that combines memory features, such as... Figure 1 The schematic diagram shows a long-term electrocardiogram heartbeat classification method combining memory features provided in Embodiment 1 of the present invention. The method mainly includes the following steps: Step 1: Set up a deep learning model framework that can classify and identify the heartbeat of the current ECG signal segment by combining the memory features of the previous segment; and set up three types of embedding coding modes and two types of memory fusion modes for the embedding layer and encoder of the segment classification model framework respectively; and combine the three types of embedding coding modes and the two types of memory fusion modes to obtain six types of embedding-fusion modes; and set up a corresponding customized classification model for each type of embedding-fusion mode based on the segment classification model framework.

[0022] Here, the three types of embedding encoding modes in this embodiment of the invention include point-to-point embedding mode, downsampling embedding mode, and piecewise embedding mode. The two types of memory fusion modes in this embodiment of the invention include local key-value caching mode and global memory compression mode.

[0023] Each customized classification model in this embodiment of the invention corresponds to a unique model index.

[0024] The fragment classification model framework and various customized classification models in this invention are used to embed and encode the ECG signal fragment X input to the model to obtain the embedding vector E, and to perform historical memory features G input to the model. old Feature vector H is obtained by encoding the embedding vector E, and updated memory features G is obtained by updating the memory features based on the encoding process data. new The function outputs the data, performs classification feature mapping on the feature vector H to obtain the feature vector Y, and predicts the segment classification vector P based on the feature vector Y, then outputs the result. For example... Figure 2 The diagram shows the structure of the fragment classification model framework provided in Embodiment 1 of the present invention.

[0025] The electrocardiogram (ECG) signal segment X in this embodiment of the invention consists of multiple ECG data x i Composition; each ECG data point xi Each sampling point corresponds to a single sampling point and consists of multiple single-lead data points at that sampling point; 1 ≤ index i ≤ N X N X This represents the total number of sampling points for the current segment.

[0026] The embedding vector E in this embodiment of the invention consists of multiple embedding features e j Composition; each embedded feature e j For a given embedding point, 1 ≤ index j ≤ N E N E This represents the total number of embedding points in the current vector; the temporal correspondence between embedding points and sampling points is determined by the corresponding embedding coding mode.

[0027] The feature vector H in this embodiment of the invention consists of multiple feature vectors h j Composition; eigenvector h j With embedded feature e j One-to-one correspondence.

[0028] The feature vector Y in this embodiment of the invention consists of multiple feature vectors y j Composition; eigenvector y j With eigenvector h j One-to-one correspondence; each feature vector y j Given the corresponding S characteristic scalars y j,s Composition, 1≤index s≤S, where S is the total number of preset heartbeat types.

[0029] In this embodiment of the invention, the segment classification vector P consists of multiple classification vectors p j Composition; classification vector p j With the eigenvector y j One-to-one correspondence; classification vector p j Given the corresponding S predicted probabilities ρ j,s Composition; each prediction probability ρ j,s Corresponding to a type of heartbeat; the heartbeat types in the embodiments of the present invention include at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat.

[0030] like Figure 2 As shown, the fragment classification model framework and the model structure of each customized classification model in this embodiment of the invention include an embedding layer, an encoder, a memory update module, a feature mapping layer, and a Softmax function layer.

[0031] The connection relationships of each model component are as follows: the input of the embedding layer is used to receive the ECG signal segment X, and its output is connected to the first input of the encoder; the second input of the encoder is used to receive the historical memory feature G. oldThe output is connected to the feature mapping layer; the memory update module is connected to the encoder, and its output is used to output the corresponding updated memory feature G. new The output of the feature mapping layer is connected to the input of the Softmax function layer; the output of the Softmax function layer is used to output the corresponding segment classification vector P.

[0032] The basic component functions of each model component are shown below.

[0033] 1) The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding embedding coding mode to obtain the corresponding embedding vector E and send it to the encoder.

[0034] 2) The encoder consists of multiple sequentially connected l-th coding layers, where 1 ≤ index l ≤ L, and the total number of coding layers L is a preset positive integer, L > 3. Each l-th coding layer is implemented based on the model structure of the coding module of the Transformer model framework, consisting of a corresponding multi-head self-attention layer, a first residual connection and layer normalization layer, a feedforward neural network layer, and a second residual connection and layer normalization layer connected sequentially. For example... Figure 3 The diagram shows the encoder structure implemented using the standard encoding module based on the Transformer model framework.

[0035] It should be noted that the encoder of the embodiments of the present invention has sections 1 to L. mid The attention span of the multi-head self-attention layer of the l-th encoding layer is defined by a preset local window width L. win Decision; L mid The attention scope of the multi-head self-attention layer from +1 to the l-th coding layer of the L-th layer is the global scope; L mid For the preset intermediate layer index, 1 < L mid <L; 1 <L win <N E .

[0036] The encoder is used to determine the corresponding memory fusion mode based on the corresponding historical memory feature G. old The feature vector H is obtained by feature encoding with the embedding vector E and sent to the feature mapping layer.

[0037] 3) The memory update module is used to update the memory features based on the encoder's encoding process data to obtain the corresponding updated memory features G. new And output it.

[0038] 4) The feature mapping layer is implemented based on the MLP model structure. The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer.

[0039] 5) The Softmax function layer is used to calculate the probability vector based on the feature vector Y using the Softmax function, and then output the corresponding segment classification vector P.

[0040] The six embedding-fusion modes in this invention include point-to-point embedding-local key-value caching mode, downsampling embedding-local key-value caching mode, sliced ​​embedding-local key-value caching mode, point-to-point embedding-global memory compression mode, downsampling embedding-global memory compression mode, and sliced ​​embedding-global memory compression mode. Each custom model has its own unique implementation details, which will be described in detail below.

[0041] 1) Customized classification model corresponding to point-to-point embedding-local key-value caching mode.

[0042] The reasoning process for this type of custom model is as follows: 1) The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder.

[0043] Here, the embedding feature e in the point-to-point embedding mode of this embodiment of the invention. j The encoding process is as follows: ; in, , For the corresponding first embedding coding weight matrix and first embedding coding bias vector; the total number of embedding points N of the embedding vector E. E The total number of sampling points N of the electrocardiogram signal segment X X If they are equal, the correspondence between index j and index i is one-to-one.

[0044] 2) The encoder is used to cache the corresponding local key-value pairs according to the corresponding historical memory features G. old The feature vector H is obtained by feature encoding with the embedding vector E and sent to the feature mapping layer.

[0045] Here, the encoder of the custom classification model corresponding to the point-to-point embedding-local key-value caching pattern is... Figure 3 The standard encoder in the document has been fine-tuned; details of the fine-tuning can be found in [reference needed]. Figure 4 This is a schematic diagram of the encoder structure for adapting to the local key-value caching mode provided in Embodiment 1 of the present invention.

[0046] Here, as Figure 4 As shown, the historical memory feature G in the local key-value caching mode of this embodiment of the invention... oldIt consists of L corresponding historical key-value vector groups. Each historical key-value vector group consists of R single-head key-value vector pairs, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations. Each single-head key-value vector pair consists of a set of corresponding historical key vectors. Historical value vector Composition; 1 ≤ index r ≤ R. History key vector and historical value vector The length of the vector is denoted as N. old , 1 < N old <N E In the local key-value caching mode of this invention embodiment, the historical memory feature G old The initial value is all zero features.

[0047] In the local key-value caching mode of this embodiment of the invention, the inference process of each l-th encoding layer of the encoder consists of four parts: the corresponding multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. Wherein: a) The reasoning process of the multi-head self-attention layer is as follows: Step A1: Calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 The feature vector output by the (l-1)th layer, where the feature vector H is when l=1. l-1=0 =E; , , Here are the query weight matrix, key weight matrix, and value weight matrix for the r-th head of the l-th encoding layer; and the query vector Q. l,r Key vector K l,r Value vector V l,r The feature dimensions are the same, denoted as d l,r .

[0048] Step A2, concatenate the key vector K. l,r Its corresponding historical key vector Feature fusion is performed to obtain the corresponding fusion key vector. , value vector Its corresponding historical value vector The fusion value vector corresponding to feature fusion : , ; Here, `concate()` is the vector concatenation function; it merges the key vectors. and fusion value vector The length of the vector is denoted as N. con =N old +N E ; Fusion key vector From the corresponding N con eigenvectors Composition, fusion value vector From the corresponding N con eigenvectors Composition, 1 ≤ index ≤N con .

[0049] Step A3, set the attention mask matrix M l : In 1≤l≤L mid At that time, based on the local window width L win Calculate the starting position ws of the local window corresponding to each index j. j Local window end position we j And set a shape of N E ×N con The matrix is ​​used as the corresponding attention mask matrix M. l And the attention mask matrix M l Each matrix element is denoted as the corresponding And based on each matrix unit The corresponding local window start position ws j and the end position of the local window j Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of N. E ×N con The all-zero matrix is ​​used as the corresponding attention mask matrix M l .

[0050] Here, the attention mask matrix M l Shape like Figure 4 As shown.

[0051] Step A4, based on query vector Q l,r fusion key vector fusion value vector Feature dimension d l,r Attention mask matrix M lPerform self-attention operations to obtain the corresponding single-head attention vector A. l,r : .

[0052] Step A5, for R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions. l .

[0053] Here, in this embodiment of the invention, the attention vector A l The shape is N E ×d l Feature dimension d l For R feature dimensions d l,r The sum of .

[0054] b) The reasoning process for the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l This is the feature vector output by the current first residual connection and the layer normalization layer.

[0055] c) The inference process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first and second weight matrices corresponding to the current feedforward neural network layer; , F represents the first bias vector and the second bias vector corresponding to the current feedforward neural network layer. l This is the feature vector output by the current feedforward neural network layer.

[0056] d) The reasoning process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l This is the feature vector output by the l-th encoding layer.

[0057] It should be noted that, in the local key-value caching mode of this embodiment of the invention, the feature vector H output by the encoder is the feature vector H output by the l-th coding layer of the L-th layer. l=L .

[0058] 3) The memory update module is used to update the memory features based on the encoder's encoding process data to obtain the corresponding updated memory features G. new And output it.

[0059] In the local key-value caching mode of this embodiment of the invention, the memory feature G is updated. new It consists of L corresponding updated historical key-value vector groups; each updated historical key-value vector group consists of R updated single-head key-value vector pairs; each updated single-head key-value vector pair consists of a set of updated historical key vectors. Updated historical value vector Composition. It should be noted that the updated historical key vector in the local key-value caching mode of this embodiment of the invention... From the corresponding fusion bond vector The last N old eigenvectors Composition, updated historical value vector From the corresponding fusion bond vector The last N old eigenvectors composition.

[0060] 4) The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer.

[0061] Here, the mapping process of the feature vector Y in this embodiment of the invention is as follows: ; Where ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E eigenvectors y j Composition; eigenvector y j S characteristic scalars y j,s composition.

[0062] 5) The Softmax function layer is used to calculate the probability vector based on the feature vector Y using the Softmax function, and then output the corresponding segment classification vector P.

[0063] Here, the predicted probabilities ρ of each segment classification vector P in this embodiment of the invention are... j,s for: .

[0064] (ii) Customized classification models corresponding to the downsampling embedding-local key-value caching mode.

[0065] The main difference between the custom classification model corresponding to downsampling embedding-local key-value caching and the custom classification model corresponding to point-to-point embedding-local key-value caching lies in the embedding pattern used in the embedding layer. Correspondingly, the difference in the inference process between the custom classification model corresponding to downsampling embedding-local key-value caching and the custom classification model corresponding to point-to-point embedding-local key-value caching lies in: In the custom classification model corresponding to the downsampling embedding-local key-value caching mode, the embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically, it is based on the preset one-dimensional convolution operation function Conv1D. a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder.

[0066] Here, the encoding process of the embedding vector E in the downsampling embedding mode of this embodiment of the invention is as follows: ; Where a is the kernel size and b is the stride; The total number of embedding points N of the embedding vector E E =floor(N X / b), floor() is the floor function, N E <N X The embedding vector E is composed of N E eigenvectors e j composition; The correspondence between index j and index i is as follows: .

[0067] (iii) Customized classification model corresponding to the slice embedding-local key-value caching mode.

[0068] The main difference between the custom classification model corresponding to the piecewise embedding-local key-value caching pattern and the custom classification model corresponding to the point-to-point embedding-local key-value caching pattern lies in the embedding pattern used in the embedding layer. Correspondingly, the difference in the inference process between the custom classification model corresponding to the piecewise embedding-local key-value caching pattern and the custom classification model corresponding to the point-to-point embedding-local key-value caching pattern lies in: In the custom classification model corresponding to the slice embedding-local key-value caching mode, the embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slice embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset sub-segment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(NX / L C ), ceiling() is the floor function, which rounds up each sub-segment X. c From the most L C ECG data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C sub-fragment X c The segment length is extended to L C ; and for each sub-fragment X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E eigenvectors e j The corresponding embedding vector E is then sent to the encoder.

[0069] Here, the feature vector e in the slice embedding mode of this embodiment of the invention. j The feature mapping process is as follows: ; in, This is the preset second embedding encoding weight matrix; The correspondence between index j and index i is as follows: .

[0070] (iv) Customized classification model corresponding to point-to-point embedding-global memory compression mode.

[0071] The reasoning process for this type of custom model is as follows: 1) The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder.

[0072] Here, the embedding feature e under point-to-point embedding in this embodiment of the invention. j The encoding process is as follows: ; in, , For the corresponding first embedding coding weight matrix and first embedding coding bias vector; the total number of embedding points N of the embedding vector E. E The total number of sampling points N of the electrocardiogram signal segment X X They are equal, and there is a one-to-one correspondence between index j and index i.

[0073] 2) The encoder is used to compress the corresponding global memory mode according to the corresponding historical memory feature G. old The feature vector H is obtained by feature encoding with the embedding vector E and sent to the feature mapping layer.

[0074] Here, the encoder of the custom classification model corresponding to the point-to-point embedding-global memory compression mode is... Figure 3 The standard encoder in the document has been fine-tuned; details of the fine-tuning can be found in [reference needed]. Figure 5 This is a schematic diagram of the encoder structure for adapting to the global memory compression mode provided in Embodiment 1 of the present invention.

[0075] Here, as Figure 5 As shown, the historical memory feature G in the global memory compression mode of this embodiment of the invention old From the corresponding N slot eigenvectors Composition, 1 ≤ index o ≤ N slot N slot The preset total number of memory slots, 1 < N slot <N E ; Eigenvector Feature dimensions and embedding features e j The feature dimensions remain consistent. In the global memory compression mode of this embodiment of the invention, the historical memory feature G... old The initial value is the weight matrix parameter W of the current custom classification model. mem This parameter can be learned through model training.

[0076] In the global memory compression mode of this invention embodiment, the inference process of each l-th coding layer of the encoder consists of four parts: the corresponding multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. Wherein: a) The reasoning process of the multi-head self-attention layer is as follows: Step B1, regarding historical memory features G old The corresponding feature vector H0 is obtained by concatenating the feature vector with the embedded vector E. Wherein, the feature vector H0 is composed of N slot +N E Feature vector Composition, 1 ≤ index ≤N slot +N E ; the first N slot eigenvectors With N slot eigenvectors One-to-one correspondence, followed by N E eigenvectors With N E Embedded features e j One-to-one correspondence.

[0077] Step B2, calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 Given the feature vector of the l-th encoding layer as input, H = 1 l-1 =H0;1≤indexr≤R, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations; , , Here are the query weight matrix, key weight matrix, and value weight matrix for the r-th head of the l-th encoding layer; and the query vector Q. l,r Key vector K l,r Value vector V l,r The feature dimensions are the same, denoted as d l,r .

[0078] Step B3, set the attention mask matrix M l ; In 1≤l≤L mid When, set a shape as (N) slot +N E )×(N slot +N E The matrix M is used as the corresponding attention mask matrix. l And the attention mask matrix M l Each matrix element is denoted as m. u,v , 1≤index u, v≤(N) slot +N E ); and based on the local window width L win Calculate the starting position ws of the local window corresponding to each index u. u Local window end position we u ; and based on each matrix unit m u,v The corresponding local window start position ws u and the end position of the local window u Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of (N) slot +N E )×(N slot +N E The all-zero matrix is ​​used as the corresponding attention mask matrix M. l .

[0079] Here, the attention mask matrix M l Shape like Figure 5 As shown.

[0080] Step B4, based on query vector Q l,r Key vector K l,r Value vector V l,r Feature dimension d l,r Attention mask matrix M l Perform self-attention operations to obtain the corresponding single-head attention vector A. l,r : .

[0081] Step B5, for R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions. l .

[0082] Here, in this embodiment of the invention, the attention vector A l The shape is (N) slot +N E )×d l Feature dimension d l For R feature dimensions d l,r The sum of .

[0083] b) The reasoning process for the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l This is the feature vector output by the current first residual connection and the layer normalization layer.

[0084] c) The inference process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first and second weight matrices corresponding to the current feedforward neural network layer; , F represents the first bias vector and the second bias vector corresponding to the current feedforward neural network layer. l This is the feature vector output by the current feedforward neural network layer.

[0085] d) The reasoning process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l This is the feature vector output by the l-th encoding layer.

[0086] It should be noted that, in the global memory compression mode of this embodiment of the invention, the feature vector H output by the l-th coding layer of the encoder at layer L is... l=L By N slot +N E Feature vector Composed of; and the feature vector H output by the encoder is composed of the feature vector H L The last N extracted from the middle E eigenvectors composition.

[0087] 3) The memory update module is used to update the memory features based on the encoder's encoding process data to obtain the corresponding updated memory features G. new And output, specifically: From the eigenvector H L The first N slot eigenvectors Form the corresponding query vector Q slot And by the eigenvector H L The after N E eigenvectors The eigenvectors formed serve as the corresponding key vectors K. slot Value vector V slot ; and based on query vector Q slot Key vector K slot Sum vector V slot Perform cross-attention calculation and use the result to update memory features G. new And output; in, , , , Query vector Q slot Key vector K slot Sum vector V slot The feature dimensions are the same, denoted as d slot .

[0088] 4) The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer.

[0089] Here, the mapping process of the feature vector Y in this embodiment of the invention is as follows: ; Where ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E eigenvectors y j Composition; eigenvector y j S characteristic scalars y j,s composition.

[0090] 5) The Softmax function layer is used to calculate the probability vector based on the feature vector Y using the Softmax function, and then output the corresponding segment classification vector P.

[0091] Here, the predicted probabilities ρ of each segment classification vector P in this embodiment of the invention are... j,s for: .

[0092] (v) Customized classification model corresponding to downsampling embedding-global memory compression mode.

[0093] The main difference between the custom classification model corresponding to the downsampling embedding-global memory compression mode and the point-to-point embedding-global memory compression mode lies in the different embedding modes used in the embedding layer. Correspondingly, the difference in the inference process between the custom classification model corresponding to the downsampling embedding-global memory compression mode and the point-to-point embedding-global memory compression mode lies in: In the custom classification model corresponding to the downsampling embedding-global memory compression mode, the embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the one-dimensional convolution operation function Conv1D a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder; Here, the encoding process of the embedding vector E in the downsampling embedding mode of this embodiment of the invention is as follows: ; a is the kernel size, b is the stride; N is the total number of embedding points in the embedding vector E. E =floor(N X / b), N E <N X The embedding vector E is composed of N E eigenvectors e j Composition; The correspondence between index j and index i is as follows: .

[0094] (vi) Customized classification model corresponding to the slice embedding-global memory compression mode.

[0095] The main difference between the custom classification model corresponding to the piecewise embedding-global memory compression mode and the custom classification model corresponding to the point-to-point embedding-global memory compression mode lies in the different embedding modes used in the embedding layer. Correspondingly, the difference in the inference process between the custom classification model corresponding to the piecewise embedding-global memory compression mode and the custom classification model corresponding to the point-to-point embedding-global memory compression mode lies in: In the custom classification model corresponding to the slice embedding-global memory compression mode, the embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slice embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on sub-fragment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(N X / L C ), each sub-fragment X c From the most L C ECG data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C sub-fragment X c The segment length is extended to L C ; and for each sub-fragment X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E eigenvectors e j The corresponding embedding vector E is then sent to the encoder.

[0096] Here, the feature vector e in the slice embedding mode of this embodiment of the invention. j The feature mapping process is as follows: ; in, The second embedding encoding weight matrix is ​​preset; the correspondence between index j and index i is as follows: .

[0097] Step 2: Construct a general model dataset through data collection, denoted as the first dataset.

[0098] Here, the first dataset in this embodiment of the invention consists of multiple first data records; the first data records include a first training segment sequence, a first label vector sequence, a second label vector sequence, and a third label vector sequence; the first training segment sequence is a segmented sequence of an original long-term electrocardiogram signal, which is formed by sequentially sorting multiple first training segments; the first label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on a point-to-point embedding mode; the second label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on a downsampling embedding mode; the third label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on a slice embedding mode; the first label vector sequence is formed by sequentially sorting multiple first label vectors; the second label vector sequence is formed by sequentially sorting multiple second label vectors; the third label vector sequence is formed by sequentially sorting multiple third label vectors; the first label vector, the second label vector, and the third label vector each correspond one-to-one with the first training segment.

[0099] The current step 2 specifically includes: Step 21, collecting multiple raw long-term electrocardiograms through multiple publicly available long-term electrocardiogram data acquisition channels.

[0100] Here, publicly available long-term ECG data acquisition channels include various publicly available ECG databases, such as the MIT-BIH database, SVDB database, CPSC 2018 dataset, CCDD database, and so on.

[0101] Step 22: Use each original long-range electrocardiogram (ECG) as the current ECG; segment the current ECG signal to obtain multiple corresponding signal segments; perform a round of traversal on all signal segments of the current ECG; during this round of traversal, use the currently traversed signal segment as the current segment; convert the data format of the ECG signal segment X to the current segment to obtain the corresponding first training segment; embed and encode the current first training segment according to the embedding encoding modes of point-to-point embedding mode, downsampling embedding mode, and segmented embedding mode to obtain the corresponding three types of embedding vectors; use each type of embedding vector as the current vector; manually label the label classification vectors corresponding to all embedding points of the current vector; and assign the current vector to all embedding points of the current vector. The label classification vectors of the entry points form the corresponding first label vector, second label vector, or third label vector; and at the end of this round of traversal, the corresponding first training segment sequence is formed by all the first training segments of the current ECG in chronological order, the corresponding first label vector sequence is formed by all the first label vectors of the current ECG in chronological order, the corresponding second label vector sequence is formed by all the second label vectors of the current ECG in chronological order, and the corresponding second label vector sequence is formed by all the second label vectors of the current ECG in chronological order; and the corresponding first data record is formed by the first training segment sequence, first label vector sequence, second label vector sequence, and third label vector sequence of the current ECG.

[0102] Step 23, and the first dataset is composed of all the first data records obtained.

[0103] Step 3: Train the six custom classification models based on the first dataset.

[0104] Specifically, this includes: Step 31, taking various customized classification models as the current classification model; and taking the embedding encoding mode and memory fusion mode corresponding to the current classification model as the corresponding current embedding encoding mode and current memory fusion mode.

[0105] Step 32: Based on the preset first segmentation ratio, the first dataset is randomly divided into two sub-datasets, denoted as the first training set and the first evaluation set.

[0106] Here, the first segmentation ratio in this embodiment of the invention is a pre-set arm strength parameter, such as 8:2; both the first training set and the first evaluation set consist of multiple first data records; the ratio of the total number of records in the first training set to the total number of records in the first evaluation set satisfies the first segmentation ratio.

[0107] Step 33: Take the first data record of the first training set as the current training record.

[0108] Step 34: Record the first training segment sequence of the current training record as the corresponding segment sequence {X}. q}; and take the first label vector sequence, second label vector sequence, or third label vector sequence in the current training record that corresponds to the current embedding encoding mode as the corresponding label vector sequence { }; and based on the historical memory features G corresponding to the current memory fusion mode. old The data format constructs the corresponding current historical memory feature G old And set the initial value of the historical memory feature G according to the initial value setting method corresponding to the current memory fusion mode. old Perform initialization.

[0109] Here, fragment X of the embodiment of the present invention. q For the q-th first training segment, 1 ≤ index q ≤ N Q N Q The total number of segments in the current segment sequence; label vector. This corresponds to the q-th first label vector, second label vector, or third label vector.

[0110] Step 35, sort the segment sequence {X} in ascending order of index q. q All fragments of X q Perform one round of sequential traversal; and during this round of traversal, change the currently traversed segment X. q As the current electrocardiogram signal segment X and the current historical memory feature G old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are used as input. new As a new characteristic of current historical memory G old The segment classification vector P obtained from this processing is used as the corresponding prediction vector. ; and by the prediction vector Its corresponding label vector Form a corresponding first prediction-label pair ( , ); and at the end of this traversal, the N obtained in this traversal is... Q The first prediction-label pair ( , Substitute the value into the preset first model loss function to calculate the corresponding first loss value.

[0111] Here, the first model loss function in this embodiment of the invention is implemented based on cross-entropy loss.

[0112] Step 36: Identify whether the first loss value meets the preset first loss value range; if the first loss value meets the first loss value range, identify whether the current training record is the last first data record of the first training set; if so, proceed to step 37; otherwise, take the next first data record of the first training set as the new current training record and return to step 34; if the first loss value does not meet the first loss value range, perform a round of modulation on the model parameters of the current classification model based on the preset first model optimizer in the direction of minimizing the first model loss function, and return to step 35 when the modulation ends.

[0113] Here, the first model optimizer in this embodiment of the invention includes the Adam optimizer; the first loss value range is a pre-set numerical range.

[0114] Step 37: Take each first data record of the first evaluation set as the current evaluation record; take the first training segment sequence of the current evaluation record as the current segment sequence; and take the first label vector sequence, second label vector sequence, or third label vector sequence in the current evaluation record that corresponds to the current embedding encoding mode as the corresponding current label vector sequence; and based on the historical memory feature G corresponding to the current memory fusion mode... old The data format constructs the corresponding current historical memory feature G old And set the initial value of the historical memory feature G according to the initial value setting method corresponding to the current memory fusion mode. old Initialize the sequence; and sequentially iterate through all the first training segments of the current segment sequence in chronological order; during this iteration, use the first training segment of the current iteration as the current ECG signal segment X and the current historical memory feature G. old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are used as input. new As a new characteristic of current historical memory G old The segment classification vector P obtained in this process is used as the corresponding current prediction vector; and the current prediction vector and its corresponding label vector form a corresponding second prediction-label pair; and at the end of this traversal, the corresponding F1 score is calculated based on all the second prediction-label pairs obtained in this traversal to obtain the corresponding first F1 score. Step 38: Identify whether the first F1 score meets the preset first F1 score range; if not, return to step 32; if yes, stop training the current classification model and confirm that the current classification model training has ended.

[0115] Here, the first F1 score range in this embodiment of the invention is a pre-set numerical range.

[0116] Step 4: After all six types of customized models have been trained, the user inputs a long-term electrocardiogram and a customized model index as the corresponding current electrocardiogram and current index.

[0117] Step 5: Use the customized classification model corresponding to the current index as the current customized model; and set an initialized historical memory feature G according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is segmented to obtain multiple corresponding signal segments.

[0118] Step 6: Perform a sequential traversal of all signal segments according to their time sequence; during this traversal, the currently traversed signal segment is designated as the current segment; and the current segment is used as the corresponding ECG signal segment X and historical memory feature G. old The data is input into the current customized model and processed to obtain the corresponding fragment classification vector P and updated memory features G. new ; and based on the updated memory feature G new Characteristics of historical memory G old Reset.

[0119] Step 7: At the end of this round of traversal of all signal segments, the obtained segment classification vectors P are sequentially concatenated according to time sequence, and the concatenated sequence is classified and processed to obtain the corresponding whole heartbeat type sequence and fed back to the current user.

[0120] Specifically, this includes: Step 71, sequentially concatenating all the obtained segment classification vectors P in chronological order to obtain the corresponding full-process classification vector sequence. }; Here, the complete classification vector sequence of this invention embodiment { } consists of multiple classification vectors Composition, 1 ≤ embedding point index ≤N total N total This represents the total number of embedding points corresponding to the current complete classification vector sequence; each classification vector... Given the corresponding S predicted probabilities Composition; each predicted probability It corresponds to a type of heartbeat; heartbeat types include at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat.

[0121] Step 72, and based on the entire classification vector sequence { The corresponding sampling frequency of the current electrocardiogram and the whole classification vector sequence { The correspondence between the embedding points of} and the sampling points of the current electrocardiogram is used to classify the entire vector sequence { Time information corresponding to each embedding point of} Confirmation is performed; and based on the preset segmented sliding step size and segment duration, the entire classification vector sequence { is evaluated. The sliding segmentation process yields multiple corresponding sequence segments; each sequence segment includes multiple classification vectors. .

[0122] Step 73, and take each sequence segment as the current segment; and deliver all time information based on the current segment. The center time of the current segment is calculated to obtain the corresponding segment center time; the sum of predicted probabilities for each heartbeat type in the current segment is calculated to obtain the corresponding type probability sum, and the heartbeat type corresponding to the largest type probability sum is taken as the segment heartbeat type of the current segment; and the segment heartbeat data is composed of the segment center time and segment heartbeat type of the current segment.

[0123] Step 74: Sort all the obtained fragment heartbeat data in chronological order to form the corresponding full heartbeat type sequence and feed it back to the current user.

[0124] Figure 6 This is a module structure diagram of a long-term electrocardiogram heart rate classification device combining memory features provided in Embodiment 2 of the present invention. This device can be a terminal device or server implementing the aforementioned method embodiments, or it can be a device that enables the aforementioned terminal device or server to implement the aforementioned method embodiments. For example, the device can be a device or chip system of the aforementioned terminal device or server. Figure 6 As shown, the device includes: a model setting module 201, a data acquisition module 202, a model training module 203, a data receiving module 204, an analysis and preprocessing module 205, a long-term electrocardiogram analysis module 206, and a data feedback module 207.

[0125] The model setting module 201 is used to set up a deep learning model framework, denoted as the segment classification model framework, that can combine the memory features of previous segments to classify and identify the heartbeat of the current ECG signal segment. It sets up three types of embedding encoding modes and two types of memory fusion modes for the embedding layer and encoder of the segment classification model framework, respectively. It then combines the three types of embedding encoding modes and the two types of memory fusion modes to obtain six corresponding embedding-fusion modes. Based on the segment classification model framework, it sets up a corresponding customized classification model for each type of embedding-fusion mode. The three types of embedding encoding modes include point-to-point embedding mode, downsampling embedding mode, and slice embedding mode. The two types of memory fusion modes include local key-value caching mode and global memory compression mode. The segment classification model framework and each customized classification model are used to embed and encode the ECG signal segment X input to the model to obtain the embedding vector E, and based on the historical memory features G input to the model... oldFeature vector H is obtained by encoding the embedding vector E, and updated memory features G is obtained by updating the memory features based on the encoding process data. new The system outputs the classification vector Y by performing classification feature mapping on the feature vector H, and then performs classification probability prediction based on the feature vector Y to obtain the segment classification vector P and outputs it. Each customized classification model corresponds to a unique model index.

[0126] The data acquisition module 202 constructs a general model dataset through data acquisition, denoted as the first dataset.

[0127] The model training module 203 trains six custom classification models based on the first dataset.

[0128] The data receiving module 204 is used to receive the long-term electrocardiogram and the customized model index input by the user after all six types of customized models have been trained, as the corresponding current electrocardiogram and current index.

[0129] The analysis and preprocessing module 205 is used to take the customized classification model corresponding to the current index as the current customized model; and to set an initialized historical memory feature G according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is segmented to obtain multiple corresponding signal segments.

[0130] The long-term ECG analysis module 206 is used to perform a sequential traversal of all signal segments according to their time sequence; during this traversal, the currently traversed signal segment is taken as the current segment; and the current segment is used as the corresponding ECG signal segment X and historical memory feature G. old The data is input into the current customized model and processed to obtain the corresponding fragment classification vector P and updated memory features G. new ; and based on the updated memory feature G new Characteristics of historical memory G old Reset.

[0131] The data feedback module 207 is used to sequentially concatenate all the obtained segment classification vectors P in chronological order at the end of the current round of traversal of all signal segments, and to process the concatenated sequence after classification to obtain the corresponding whole heartbeat type sequence and feed it back to the current user.

[0132] The long-term electrocardiogram heart rate classification device that combines memory features provided in this embodiment of the invention can execute the method steps in the above method embodiment. Its implementation principle and technical effect are similar, and will not be repeated here.

[0133] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. For example, the model setting module can be a separate processing element, or it can be integrated into a chip in the above device. Alternatively, it can be stored as program code in the memory of the above device, and called and executed by a processing element of the device. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element described here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.

[0134] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more Digital Signal Processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together as a System-on-a-Chip (SOC).

[0135] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the foregoing method embodiments are generated. The computer described above can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The aforementioned computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the aforementioned computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, Bluetooth, microwave, etc.) means. The aforementioned computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The aforementioned available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state disks (SSDs)).

[0136] Figure 7 This is a schematic diagram of an electronic device provided in Embodiment 3 of the present invention. This electronic device can be a terminal device or server implementing the methods of the aforementioned embodiments, or it can be a terminal device or server connected to the aforementioned terminal device or server implementing the methods of the aforementioned embodiments. Figure 7 As shown, the electronic device may include: a processor 301 (e.g., CPU), a memory 302, and a transceiver 303; the transceiver 303 is coupled to the processor 301, and the processor 301 controls the transmission and reception operations of the transceiver 303. The memory 302 may store various instructions for performing various processing functions and implementing the processing steps described in the foregoing embodiments. Preferably, the electronic device involved in the embodiments of the present invention further includes: a power supply 304, a system bus 305, and a communication port 306. The system bus 305 is used to realize communication connections between components. The communication port 306 is used for communication between the electronic device and other peripherals.

[0137] exist Figure 7The system bus 305 mentioned can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., clients, read-write libraries, and read-only libraries). Memory may include Random Access Memory (RAM) and may also include Non-Volatile Memory, such as at least one disk storage device.

[0138] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), graphics processing units (GPUs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0139] It should be noted that the embodiments of the present invention also provide a computer-readable storage medium storing instructions that, when run on a computer, cause the computer to perform the methods and processes provided in the above embodiments.

[0140] This invention provides a method, apparatus, electronic device, and computer-readable storage medium for long-term electrocardiogram (ECG) heart rate classification that incorporates memory features. As described above, this invention first designs a segment classification model framework centered on the Transformer encoder. For the embedding layer and encoder of this framework, three types of embedding encoding modes (point-to-point embedding mode, downsampling embedding mode, and slice embedding mode) and two types of memory fusion modes (local key-value caching mode and global memory compression mode) are set respectively. The three types of embedding and the two types of fusion modes are combined to obtain six combined modes, and a corresponding customized classification model is set for each combined mode based on the current framework. Then, a general model dataset (i.e., the first dataset) is constructed through data collection, and the six customized models are trained respectively. After training, the user-specified long-term ECG is segmented, and heart rate classification is performed on all segments based on the user-specified customized model. During the classification and recognition of each segment, the historical memory features of the previous segment are fused, and the classification vectors of all segments are sequentially concatenated. The concatenated sequence is then processed for classification to obtain the corresponding full-process heart rate type sequence, which is then fed back to the current user. The embodiments of the present invention, on the one hand, solve the problem that conventional schemes are difficult to capture long-range dependencies of electrocardiogram signals by using local key-value caching or global memory compression to retain key features of preceding segments in memory form and use them for classification decisions of the current segment; on the other hand, the input representation is compressed by embedding coding methods such as downsampling or slicing, reducing computational and storage overhead and improving computational efficiency; furthermore, the sequential classification mechanism of segmented sequences also reduces the computational and storage overhead when processing long sequences and improves computational efficiency.

[0141] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented in hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0142] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A long-term electrocardiogram heartbeat classification method combining memory features, characterized in that, The method includes: A deep learning model framework, denoted as the segment classification model framework, is set up to classify and identify the current ECG signal segment by combining the memory features of previous segments. Three types of embedding encoding modes and two types of memory fusion modes are respectively set for the embedding layer and encoder of the segment classification model framework. The three types of embedding encoding modes and the two types of memory fusion modes are combined to obtain six types of embedding-fusion modes. A corresponding customized classification model is set for each type of embedding-fusion mode based on the segment classification model framework. The three types of embedding encoding modes include point-to-point embedding mode, downsampling embedding mode, and slice embedding mode. The two types of memory fusion modes include local key-value caching mode and global memory compression mode. The segment classification model framework and each of the customized classification models are used to embed and encode the ECG signal segment X input to the model to obtain the embedding vector E, and based on the historical memory features G input to the model... old The feature vector H is obtained by feature encoding with the embedded vector E, and the updated memory feature G is obtained by updating the memory feature based on the encoding process data. new The system outputs the data and performs classification feature mapping on the feature vector H to obtain the feature vector Y. Based on the feature vector Y, it performs classification probability prediction to obtain the segment classification vector P and outputs it. Each customized classification model corresponds to a unique model index. In local key-value caching mode, the historical memory feature G... old The historical memory feature G is composed of L historical key-value vector groups, where L is the total number of encoding layers of the encoder. Each historical key-value vector group consists of R single-head key-value vector pairs, where R is the total number of heads in the l-th encoding layer of the encoder performing multi-head self-attention operations, 1 ≤ index l ≤ L. Each single-head key-value vector pair consists of a corresponding set of historical key vectors and historical value vectors. In global memory compression mode, the historical memory feature G... old By N slot Composed of N feature vectors slot The preset total number of memory slots, 1 < N slot <N E N E The total number of embedding features of the embedding vector E, and the historical memory feature G old The feature dimensions are consistent with the embedding vector E; The dataset used to construct a general model through data collection is denoted as the first dataset. Based on the first dataset, the customized classification models for the six categories are trained respectively; After all six types of customized models have been trained, the user inputs a long-term electrocardiogram and a customized model index as the corresponding current electrocardiogram and current index. The customized classification model corresponding to the current index is taken as the current customized model; and an initialized historical memory feature G is set according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is then segmented to obtain multiple corresponding signal segments. All signal segments are sequentially traversed in chronological order; during this traversal, the currently traversed signal segment is designated as the current segment; and the current segment is used as the corresponding ECG signal segment X and the historical memory feature G. old The fragment classification vector P and the updated memory feature G are input together into the current customized model for processing to obtain the corresponding fragment classification vector P and the updated memory feature G. new ; and based on the updated memory feature G new Regarding the historical memory feature G old Reset; At the end of this round of traversal of all signal segments, the obtained segment classification vectors P are sequentially concatenated according to time sequence, and the concatenated sequence is classified and processed to obtain the corresponding whole heartbeat type sequence, which is then fed back to the current user.

2. The long-term electrocardiogram heart rate classification method combining memory features according to claim 1, characterized in that, The fragment classification model framework and the model structure of each of the customized classification models all include the embedding layer, the encoder, the memory update module, the feature mapping layer, and the Softmax function layer; The input terminal of the embedded layer is used to receive the electrocardiogram signal segment X, and the output terminal is connected to the first input terminal of the encoder; the second input terminal of the encoder is used to receive the historical memory feature G. old The output is connected to the feature mapping layer; The memory update module is connected to the encoder, and its output is used to output the corresponding updated memory feature G. new The output of the feature mapping layer is connected to the input of the Softmax function layer; the output of the Softmax function layer is used to output the corresponding segment classification vector P. The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding embedding encoding mode to obtain the corresponding embedding vector E and send it to the encoder; The electrocardiogram signal segment X consists of multiple electrocardiogram data x i Composition; each of the said electrocardiogram data x i Each sampling point corresponds to a single sampling point and consists of multiple single-lead data points at that sampling point; 1 ≤ index i ≤ N X N X This represents the total number of sampling points in the current segment; The embedding vector E consists of multiple embedding features e j Composition; each embedded feature e j For a given embedding point, 1 ≤ index j ≤ N E N E This represents the total number of embedding points in the current vector; the temporal correspondence between embedding points and sampling points is determined by the corresponding embedding coding mode. The encoder is composed of multiple l-th coding layers connected sequentially, where 1 ≤ index l ≤ L, and the total number of coding layers L is a preset positive integer, L > 3. Each l-th coding layer is implemented based on the model structure of the coding module of the Transformer model framework, and is composed of a corresponding multi-head self-attention layer, a first residual connection and layer normalization layer, a feedforward neural network layer, and a second residual connection and layer normalization layer connected sequentially. mid The attention span of the multi-head self-attention layer of the l-th encoding layer is defined by a preset local window width L. win Decision; L mid The attention range of the multi-head self-attention layer of the l-th coding layer from +1 to the L-th layer is the global range; L mid For the preset intermediate layer index, 1 < L mid <L; 1 <L win <N E ; The encoder is used to perform the corresponding memory fusion mode according to the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; The feature vector H is composed of multiple feature vectors h. j Composition; the feature vector h j With the embedded feature e j One-to-one correspondence; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output; The feature mapping layer is implemented based on the MLP model structure; the feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y and send it to the Softmax function layer; The feature vector Y is composed of multiple feature vectors y j Composition; the feature vector y j With the feature vector h j One-to-one correspondence; each of the aforementioned feature vectors y j Given the corresponding S characteristic scalars y j,s Composition, 1≤index s≤S, where S is the total number of preset heartbeat types; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, the fragment classification vector P consists of multiple classification vectors p j Composition; the classification vector p j With the feature vector y j One-to-one correspondence; the classification vector p j Given the corresponding S predicted probabilities ρ j,s Composition; each of the predicted probabilities ρ j,s Corresponding to a type of heartbeat; the heartbeat type includes at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat; The six types of embedding-fusion modes include point-to-point embedding-local key-value caching mode, downsampling embedding-local key-value caching mode, slicing embedding-local key-value caching mode, point-to-point embedding-global memory compression mode, downsampling embedding-global memory compression mode, and slicing embedding-global memory compression mode; The first dataset consists of multiple first data records; each first data record includes a first training segment sequence, a first label vector sequence, a second label vector sequence, and a third label vector sequence; the first training segment sequence is a segmented sequence of an original long-term electrocardiogram signal, formed by sequentially sorting multiple first training segments; the first label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the point-to-point embedding mode; the second label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the downsampling embedding mode; the third label vector sequence is a segment classification vector label sequence obtained by embedding encoding based on the slice embedding mode; the first label vector sequence is formed by sequentially sorting multiple first label vectors; the second label vector sequence is formed by sequentially sorting multiple second label vectors; the third label vector sequence is formed by sequentially sorting multiple third label vectors; each of the first label vector, the second label vector, and the third label vector corresponds one-to-one with the first training segment.

3. The long-term electrocardiogram heart rate classification method combining memory features according to claim 2, characterized in that, The reasoning process of the custom classification model corresponding to the point-to-point embedding-local key-value caching mode is as follows: The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder; Wherein, the embedding feature e j The encoding process is as follows: ; , The first embedding coding weight matrix and the first embedding coding bias vector are respectively; the total number of embedding points N of the embedding vector E is N. E The total number of sampling points N of the electrocardiogram signal segment X X They are equal, and there is a one-to-one correspondence between index j and index i; The encoder is used to operate according to the corresponding local key-value caching pattern, based on the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; Among them, the historical memory feature G old It consists of L corresponding historical key-value vector groups; each historical key-value vector group consists of R single-head key-value vector pairs, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations; each single-head key-value vector pair consists of a set of corresponding historical key vectors. Historical value vector Composition; 1 ≤ index r ≤ R; the history key vector and the historical value vector The length of the vector is denoted as N. old , 1 < N old <N E The historical memory feature G old The initial value is all zero features; The inference process of the l-th encoding layer consists of four parts: the multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. The reasoning process of the multi-head self-attention layer is as follows: Calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 The feature vector output by the (l-1)th layer, where the feature vector H is when l=1. l-1=0 =E; , , The query weight matrix, key weight matrix, and value weight matrix of the r-th head of the l-th encoding layer; the query vector Q l,r The key vector K l,r The value vector V l,r The feature dimensions are the same, denoted as d l,r ; The key vector K is processed by vector concatenation. l,r The corresponding historical key vector Feature fusion is performed to obtain the corresponding fusion key vector. For the value vector The corresponding historical value vector The fusion value vector corresponding to feature fusion : , ; Where concate() is the vector concatenation function; the fusion key vector and the fusion value vector The length of the vector is denoted as N. con =N old +N E The fusion key vector From the corresponding N con eigenvectors Composition, the fused value vector From the corresponding N con eigenvectors Composition, 1 ≤ index ≤N con ; Set the attention mask matrix M l ; In 1≤l≤L mid At that time, based on the local window width L win Calculate the starting position ws of the local window corresponding to each index j. j Local window end position we j And set a shape of N E ×N con The matrix is ​​used as the corresponding attention mask matrix M l And the attention mask matrix M l Each matrix element is denoted as the corresponding And based on each of the matrix units The corresponding local window start position ws j and the end position of the local window we j Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of N. E ×N con The all-zero matrix is ​​used as the corresponding attention mask matrix M. l ; Based on the query vector Q l,r The fusion bond vector The fused value vector The feature dimension d l,r The attention mask matrix M l Perform self-attention operations to obtain the corresponding single-head attention vector A. l,r : ; For R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions. l The attention vector A l The shape is N E ×d l Feature dimension d l For R feature dimensions d l,r The sum; The inference process of the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l The feature vector output by the first residual connection and the layer normalization layer; The reasoning process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first weight matrix and the second weight matrix corresponding to the current feedforward neural network layer; , For the first bias vector and the second bias vector corresponding to the current feedforward neural network layer; F l This refers to the feature vector output by the current feedforward neural network layer. The inference process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l The feature vector output by the l-th encoding layer; The feature vector H output by the encoder is the feature vector H output by the l-th coding layer in the L-th layer. l=L ; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output; Wherein, the updated memory feature G new It consists of L corresponding updated historical key-value vector groups; each updated historical key-value vector group consists of R updated single-head key-value vector pairs; each updated single-head key-value vector pair consists of a set of updated historical key vectors. Updated historical value vector Composition; the updated history key vector The corresponding fusion bond vector The last N old eigenvectors Composition, the updated historical value vector The corresponding fusion bond vector The last N old eigenvectors composition; The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer. The mapping process of the feature vector Y is as follows: ; ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E The feature vector y j Composition; the feature vector y j S feature scalars y j,s composition; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, each of the predicted probabilities ρ of the segment classification vector P j,s for: .

4. The long-term electrocardiogram heart rate classification method combining memory features according to claim 3, characterized in that, The difference between the inference process of the custom classification model corresponding to the downsampling embedding-local key-value caching mode and the inference process of the custom classification model corresponding to the point-to-point embedding-local key-value caching mode is: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset one-dimensional convolution operation function Conv1D a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder; The encoding process of the embedding vector E is as follows: ; a is the kernel size, b is the stride; the total number of embedding points N of the embedding vector E E =floor(N X / b), floor() is the floor function, N E <N X The embedding vector E is composed of N E eigenvectors e j Composition; The correspondence between index j and index i is as follows: .

5. The long-term electrocardiogram heart rate classification method combining memory features according to claim 3, characterized in that, The difference between the inference process of the custom classification model corresponding to the slice embedding-local key-value caching mode and the inference process of the custom classification model corresponding to the point-to-point embedding-local key-value caching mode is: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slicing embedding pattern to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset sub-segment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(N X / L C ), ceiling() is the floor function, which rounds up each of the sub-segments X. c From the most L C The electrocardiogram data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C The sub-fragment X c The segment length is extended to L C ; and for each of the aforementioned sub-fragments X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E The eigenvectors e j The corresponding embedding vector E is sent to the encoder; Wherein, the feature vector e j The feature mapping process is as follows: ; The second embedding encoding weight matrix is ​​preset; the correspondence between index j and index i is as follows: .

6. The long-term electrocardiogram heart rate classification method combining memory features according to claim 2, characterized in that, The reasoning process of the customized classification model corresponding to the point-to-point embedding-global memory compression mode is as follows: The embedding layer is used to embed and encode the electrocardiogram signal segment X according to the corresponding point-to-point embedding mode to obtain the corresponding embedding vector E and send it to the encoder; Wherein, the embedding feature e j The encoding process is as follows: ; , The first embedding coding weight matrix and the first embedding coding bias vector are respectively; the total number of embedding points N of the embedding vector E is N. E The total number of sampling points N of the electrocardiogram signal segment X X They are equal, and there is a one-to-one correspondence between index j and index i; The encoder is used to compress the corresponding global memory mode according to the corresponding historical memory feature G. old The feature vector H is obtained by performing feature encoding on the embedding vector E and then sending it to the feature mapping layer; Among them, the historical memory feature G old From the corresponding N slot eigenvectors Composition, 1 ≤ index o ≤ N slot N slot The preset total number of memory slots, 1 < N slot <N E The feature vector Feature dimensions and the embedded feature e j The feature dimensions remain consistent; the historical memory feature G old The initial value is the weight matrix parameter W of the currently customized classification model. mem ; The inference process of the l-th encoding layer consists of four parts: the multi-head self-attention layer, the first residual connection and layer normalization layer, the feedforward neural network layer, and the second residual connection and layer normalization layer. The reasoning process of the multi-head self-attention layer is as follows: Regarding the historical memory feature G old The feature vector H0 is obtained by concatenating the embedded vector E with the feature vector H0. Wherein, the feature vector H0 is composed of N slot +N E Feature vector Composition, 1 ≤ index ≤N slot +N E ; the first N slot The feature vectors With N slot The feature vectors One-to-one correspondence, followed by N E The feature vectors With N E The embedded feature e j One-to-one correspondence; Calculate the query vector Q of the l-th layer and r-th head. l,r Key vector K l,r Value vector V l,r : , , ; Among them, H l-1 For the feature vector of the l-th encoding layer as input, H is when l=1. l-1 =H0;1≤indexr≤R, where R is the total number of heads in the l-th coding layer performing multi-head self-attention operations; , , The query weight matrix, key weight matrix, and value weight matrix of the r-th head of the l-th encoding layer; the query vector Q l,r The key vector K l,r The value vector V l,r The feature dimensions are the same, denoted as d l,r ; Set the attention mask matrix M l ; In 1≤l≤L mid When, set a shape as (N) slot +N E )×(N slot +N E The matrix M is used as the corresponding attention mask matrix. l And the attention mask matrix M l Each matrix element is denoted as m. u,v , 1≤index u, v≤(N) slot +N E ); and based on the local window width L win Calculate the starting position ws of the local window corresponding to each index u. u Local window end position we u ; and based on each of the matrix units m u,v The corresponding local window start position ws u and the end position of the local window we u Set the cell value of the current matrix element: , , ; In L mid When +1≤l≤L, set a shape of (N) slot +N E )×(N slot +N E The all-zero matrix is ​​used as the corresponding attention mask matrix M. l ; Based on the query vector Q l,r The key vector K l,r The value vector V l,r The feature dimension d l,r The attention mask matrix M l Perform self-attention operations to obtain the corresponding single-head attention vector A. l,r : ; For R single-head attention vectors A l,r The attention vector A is obtained by concatenating features according to dimensions. l The attention vector A l The shape is (N) slot +N E )×d l Feature dimension d l For R feature dimensions d l,r The sum; The inference process of the first residual connection and the layer normalization layer is as follows: ; Where LayerNorm() is the layer normalization function, Z l The feature vector output by the first residual connection and the layer normalization layer; The reasoning process of the feedforward neural network layer is as follows: ; Where GELU() is the GELU activation function; , These are the first weight matrix and the second weight matrix corresponding to the current feedforward neural network layer; , For the first bias vector and the second bias vector corresponding to the current feedforward neural network layer; F l This refers to the feature vector output by the current feedforward neural network layer. The inference process of the second residual connection and the layer normalization layer is as follows: ; Among them, H l The feature vector output by the l-th encoding layer; The feature vector H output by the l-th encoding layer in the L-th layer l=L By N slot +N E Feature vector composition; The feature vector H output by the encoder is composed of feature vector H L After N E eigenvectors composition; The memory update module is used to update the memory features based on the encoding process data of the encoder to obtain the corresponding updated memory features G. new And output, specifically: From the feature vector H L The first N slot eigenvectors Form the corresponding query vector Q slot And by the feature vector H L After N E eigenvectors The eigenvectors formed serve as the corresponding key vectors K. slot Value vector V slot ; and based on the query vector Q slot The key vector K slot and the value vector V slot Perform cross-attention calculation and use the result as the updated memory feature G. new And output; in, , , , The query vector Q slot The key vector K slot and the value vector V slot The feature dimensions are the same, denoted as d slot ; The feature mapping layer is used to perform classification feature mapping on the feature vector H to obtain the corresponding feature vector Y, which is then sent to the Softmax function layer. The mapping process of the feature vector Y is as follows: ; ReLU() is the ReLU activation function. , These are the first and second weight matrices corresponding to the current feature mapping layer. , These are the first and second bias vectors corresponding to the current feature mapping layer; the feature vector Y is composed of N E The feature vector y j Composition; the feature vector y j S feature scalars y j,s composition; The Softmax function layer is used to calculate the corresponding segment classification vector P based on the feature vector Y using the Softmax function and then outputs it. Wherein, each of the predicted probabilities ρ of the segment classification vector P j,s for: .

7. The long-term electrocardiogram heart rate classification method combining memory features according to claim 6, characterized in that, The difference between the inference process of the custom classification model corresponding to the downsampling embedding-global memory compression mode and the inference process of the custom classification model corresponding to the point-to-point embedding-global memory compression mode is: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding downsampling embedding mode to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset one-dimensional convolution operation function Conv1D a,b () The ECG signal segment X is downsampled and embedded to obtain the corresponding embedding vector E, which is then sent to the encoder; The encoding process of the embedding vector E is as follows: ; a is the kernel size, b is the stride; the total number of embedding points N of the embedding vector E E =floor(N X / b), floor() is the floor function, N E <N X The embedding vector E is composed of N E eigenvectors e j Composition; The correspondence between index j and index i is as follows: .

8. The long-term electrocardiogram heart rate classification method combining memory features according to claim 6, characterized in that, The difference between the reasoning process of the custom classification model corresponding to the slice embedding-global memory compression mode and the reasoning process of the custom classification model corresponding to the point-to-point embedding-global memory compression mode is as follows: The embedding layer is used to embed and encode the ECG signal segment X according to the corresponding slicing embedding pattern to obtain the corresponding embedding vector E, which is then sent to the encoder. Specifically: Based on the preset sub-segment length L C The electrocardiogram signal segment X is divided into N. E A continuous sub-segment X j N E =ceiling(N X / L C ), ceiling() is the floor function, which rounds up each of the sub-segments X. c From the most L C The electrocardiogram data x i Composition; and by padding the end of the fragment with zeros, the length is less than L. C The sub-fragment X c The segment length is extended to L C ; and for each of the aforementioned sub-fragments X j Feature mapping is performed to obtain the corresponding feature vector e. j ; and from the obtained N E The eigenvectors e j The corresponding embedding vector E is sent to the encoder; Wherein, the feature vector e j The feature mapping process is as follows: ; The second embedding encoding weight matrix is ​​preset; the correspondence between index j and index i is as follows: .

9. The long-term electrocardiogram heart rate classification method combining memory features according to claim 2, characterized in that, The general model dataset constructed through data collection is denoted as the first dataset, and specifically includes: Multiple raw long-term ECGs were collected through multiple publicly available long-term ECG data acquisition channels; the publicly available long-term ECG data acquisition channels include multiple publicly available ECG databases; Each original long-range electrocardiogram (ECG) is used as the current ECG; the current ECG is segmented to obtain multiple corresponding signal segments; all signal segments of the current ECG are traversed once; during this traversal, the currently traversed signal segment is used as the current segment; the data format of the ECG signal segment X is used to convert the current segment to obtain the corresponding first training segment; the current first training segment is embedded and encoded according to the embedding encoding modes of the point-to-point embedding mode, the downsampling embedding mode, and the slicing embedding mode to obtain the corresponding three types of embedding vectors; each type of embedding vector is used as the current vector, and the label classification vectors corresponding to all embedding points of the current vector are manually labeled, and the label classification vectors of all embedding points of the current vector form a pair. The corresponding first label vector, second label vector, or third label vector; and at the end of this round of traversal, the corresponding first training segment sequence is formed by all the first training segments of the current electrocardiogram in chronological order, the corresponding first label vector sequence is formed by all the first label vectors of the current electrocardiogram in chronological order, the corresponding second label vector sequence is formed by all the second label vectors of the current electrocardiogram in chronological order, and the corresponding second label vector sequence is formed by all the second label vectors of the current electrocardiogram in chronological order; and the corresponding first data record is formed by the first training segment sequence, the first label vector sequence, the second label vector sequence, and the third label vector sequence corresponding to the current electrocardiogram; The first dataset is composed of all the first data records obtained.

10. The long-term electrocardiogram heartbeat classification method combining memory features according to claim 2, characterized in that, The step of training the customized classification models for the six categories based on the first dataset specifically includes: Step 101: Take each of the customized classification models as the current classification model; and take the embedding encoding mode and memory fusion mode corresponding to the current classification model as the corresponding current embedding encoding mode and current memory fusion mode; Step 102: Based on a preset first segmentation ratio, the first dataset is randomly divided into two subsets, denoted as the first training set and the first evaluation set. Wherein, both the first training set and the first evaluation set are composed of multiple first data records; the ratio of the total number of records in the first training set to the total number of records in the first evaluation set satisfies the first segmentation ratio; Step 103: Take the first data record of the first training set as the current training record; Step 104: Record the first training segment sequence of the current training record as the corresponding segment sequence {X}. q }; and take the first label vector sequence, the second label vector sequence, or the third label vector sequence in the current training record that corresponds to the current embedding encoding mode as the corresponding label vector sequence { }; and based on the historical memory feature G corresponding to the current memory fusion mode. old The data format constructs the corresponding current historical memory feature G old And set the current historical memory feature G according to the initial value setting method of the historical memory feature corresponding to the current memory fusion mode. old Perform initialization; Fragment X q For the q-th first training segment, 1 ≤ index q ≤ N Q N Q The total number of segments in the current segment sequence; label vector. For the corresponding q-th first label vector, second label vector, or third label vector; Step 105, sort the segment sequence {X} in ascending order of index q. q All of the fragments X mentioned in} q Perform one round of sequential traversal; and during this round of traversal, change the currently traversed segment X. q As the current electrocardiogram signal segment X and the current historical memory feature G old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are used as input. new As the new current historical memory feature G old The segment classification vector P obtained in this process is then used as the corresponding prediction vector. ; and by the prediction vector The corresponding label vector Form a corresponding first prediction-label pair ( , ); and at the end of this traversal, the N obtained in this traversal is... Q The first prediction-label pair ( , Substitute the value into the preset first model loss function to calculate the corresponding first loss value; The loss function of the first model is based on cross-entropy loss. Step 106: Identify whether the first loss value meets the preset first loss value range; if the first loss value meets the first loss value range, identify whether the current training record is the last first data record of the first training set; if yes, proceed to step 107; otherwise, take the next first data record of the first training set as the new current training record and return to step 104; if the first loss value does not meet the first loss value range, perform a round of modulation on the model parameters of the current classification model based on the preset first model optimizer in the direction of minimizing the first model loss function, and return to step 105 when the modulation ends. The first model optimizer includes the Adam optimizer; Step 107: Take each of the first data records in the first evaluation set as the current evaluation record; take the first training segment sequence of the current evaluation record as the current segment sequence; and take the first label vector sequence, the second label vector sequence, or the third label vector sequence in the current evaluation record that corresponds to the current embedding encoding mode as the corresponding current label vector sequence; and based on the historical memory feature G corresponding to the current memory fusion mode... old The data format constructs the corresponding current historical memory feature G old And set the current historical memory feature G according to the initial value setting method of the historical memory feature corresponding to the current memory fusion mode. old Initialization is performed; and in chronological order, all the first training segments of the current segment sequence are sequentially traversed once; during this traversal, the currently traversed first training segment is used as the current ECG signal segment X and the current historical memory feature G. old The data is input into the current classification model for processing, and the updated memory features G obtained from this processing are used as input. new As the new current historical memory feature G old The segment classification vector P obtained in this process is used as the corresponding current prediction vector; and the current prediction vector and its corresponding label vector form a corresponding second prediction-label pair; and at the end of this traversal, the corresponding F1 score is calculated based on all the second prediction-label pairs obtained in this traversal to obtain the corresponding first F1 score. Step 108: Identify whether the first F1 score meets the preset first F1 score range; if not, return to step 102; if yes, stop training the current classification model and confirm that the current classification model training has ended.

11. The long-term electrocardiogram heartbeat classification method combining memory features according to claim 2, characterized in that, The process of sequentially concatenating all the obtained segment classification vectors P in chronological order, classifying the concatenated sequence, and then processing the resulting sequence to obtain the corresponding whole-process heartbeat type sequence, which is then fed back to the current user, specifically includes: The obtained segment classification vectors P are sequentially concatenated according to their chronological order to obtain the corresponding full-process classification vector sequence. }; Full-process classification vector sequence { } consists of multiple classification vectors Composition, 1 ≤ embedding point index ≤N total N total The total number of embedding points corresponding to the current full-process classification vector sequence; each of the classification vectors Given the corresponding S predicted probabilities Composition; each of the predicted probabilities Corresponding to one of the aforementioned heartbeat types; the heartbeat types include at least no heartbeat, sinus heartbeat, ventricular heartbeat, supraventricular heartbeat, and junctional heartbeat; And based on the entire classification vector sequence { The corresponding sampling frequency of the current electrocardiogram, the whole-process classification vector sequence { The correspondence between the embedding points of} and the sampling points of the current electrocardiogram is used to classify the entire classification vector sequence { Time information corresponding to each embedding point of} Confirmation is performed; and based on the preset segmented sliding step size and segment duration, the entire classification vector sequence { is evaluated. The sliding segmentation process yields multiple corresponding sequence segments; each sequence segment includes multiple classification vectors. ; Each of the aforementioned sequence segments is taken as the current segment; and all the aforementioned time information is delivered based on the current segment. The center time of the current segment is calculated to obtain the corresponding segment center time; the sum of predicted probabilities for each heartbeat type in the current segment is calculated to obtain the corresponding type probability sum, and the heartbeat type corresponding to the largest type probability sum is taken as the segment heartbeat type corresponding to the current segment; and the segment heartbeat data is composed of the segment center time and the segment heartbeat type corresponding to the current segment. The obtained fragment heartbeat data are sorted according to time sequence to form the corresponding full heartbeat type sequence and fed back to the current user.

12. An apparatus for performing the long-term electrocardiogram heart rate classification method incorporating memory features as described in any one of claims 1-11, characterized in that, The device includes: a model setting module, a data acquisition module, a model training module, a data receiving module, an analysis and preprocessing module, a long-term electrocardiogram analysis module, and a data feedback module; The model setting module is used to set up a deep learning model framework, denoted as the segment classification model framework, that can classify and identify the current ECG signal segment by combining the memory features of the previous segment. It sets up three types of embedding encoding modes and two types of memory fusion modes for the embedding layer and encoder of the segment classification model framework, respectively. It then combines the three types of embedding encoding modes with the two types of memory fusion modes to obtain six corresponding embedding-fusion modes. Based on the segment classification model framework, it sets up a corresponding customized classification model for each type of embedding-fusion mode. The three types of embedding encoding modes include point-to-point embedding mode, downsampling embedding mode, and slice embedding mode. The two types of memory fusion modes include local key-value caching mode and global memory compression mode. The segment classification model framework and each of the customized classification models are used to embed and encode the ECG signal segment X input to the model to obtain the embedding vector E, and based on the historical memory features G input to the model... old The feature vector H is obtained by feature encoding with the embedded vector E, and the updated memory feature G is obtained by updating the memory feature based on the encoding process data. new The system outputs the data and performs classification feature mapping on the feature vector H to obtain the feature vector Y. Based on the feature vector Y, it performs classification probability prediction to obtain the segment classification vector P and outputs it. Each customized classification model corresponds to a unique model index. In local key-value caching mode, the historical memory feature G... old The historical memory feature G is composed of L historical key-value vector groups, where L is the total number of encoding layers of the encoder. Each historical key-value vector group consists of R single-head key-value vector pairs, where R is the total number of heads in the l-th encoding layer of the encoder performing multi-head self-attention operations, 1 ≤ index l ≤ L. Each single-head key-value vector pair consists of a corresponding set of historical key vectors and historical value vectors. In global memory compression mode, the historical memory feature G... old By N slot Composed of N feature vectors slot The preset total number of memory slots, 1 < N slot <N E N E The total number of embedding features of the embedding vector E, and the historical memory feature G old The feature dimensions are consistent with the embedding vector E; The data acquisition module constructs a general model dataset, denoted as the first dataset, through data acquisition. The model training module trains the six customized classification models based on the first dataset. The data receiving module is used to receive the long-term electrocardiogram and the customized model index input by the user after all six types of customized models have been trained, as the corresponding current electrocardiogram and current index. The analysis preprocessing module is used to take the customized classification model corresponding to the current index as the current customized model; and to set an initialized historical memory feature G according to the historical memory feature data format corresponding to the current customized model. old The current electrocardiogram is then segmented to obtain multiple corresponding signal segments. The long-range electrocardiogram (ECG) analysis module is used to perform a sequential traversal of all signal segments according to their time sequence; during this traversal, the currently traversed signal segment is taken as the current segment; and the current segment is used as the corresponding ECG signal segment X and the historical memory feature G. old The fragment classification vector P and the updated memory feature G are input together into the current customized model for processing to obtain the corresponding fragment classification vector P and the updated memory feature G. new ; and based on the updated memory feature G new Regarding the historical memory feature G old Reset; The data feedback module is used to sequentially concatenate all the obtained segment classification vectors P in chronological order at the end of the current round of traversal of all signal segments, and then perform classification and post-processing on the concatenated sequence to obtain the corresponding whole-process heartbeat type sequence and feed it back to the current user.

13. An electronic device, characterized in that, include: Memory, processor, and transceiver; The processor is configured to be coupled to the memory, read and execute instructions in the memory to implement the method according to any one of claims 1-11; The transceiver is coupled to the processor, and the processor controls the transceiver to send and receive messages.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a computer, cause the computer to perform the method according to any one of claims 1-11.

Citation Information

Patent Citations

  • Method and device for predicting blood pressure

    WO2021164346A1

  • Heartbeat tag data sequence generation method and apparatus based on multi-lead electrocardiogram signal

    WO2022073374A1