A Transformer-based vehicle operating condition classification method, product and device
By adopting a Transformer-based vehicle operating condition classification method in vehicle operating condition data processing, and using a multi-head attention mechanism for parallel encoding and cluster loss training, the problem of insufficient gradient vanishing and nonlinear information representation in the prior art is solved, and a more efficient vehicle operating condition classification and training process is achieved.
Patent Information
- Application Number
- CN202411071639.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-06
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-08-06
AI Technical Summary
When processing vehicle operating condition data, the existing autoencoder neural network model cannot effectively learn the relationship between data features in parallel, resulting in the gradient disappearance or explosion, and the abstract features generated by the encoder cannot fully represent the nonlinear information of vehicle operating condition data, affecting the classification accuracy.
Using the Transformer-based vehicle operating condition classification method, the Transformer network is constructed, and the vehicle operating condition data is encoded in parallel using the multi-head attention mechanism to generate abstract feature vectors, and iterative training is performed through clustering loss and reconstruction loss to obtain the vehicle operating condition encoder.
It effectively avoids the disappearance or explosion of gradients caused by long-term dependencies during recurrent neural network encoding, and can better handle dependencies in vehicle operating conditions, generate more comprehensive features, improve the accuracy of vehicle operating conditions classification, and improve training efficiency by introducing clustering losses and parallel computing.
Smart Images

Figure CN118965030B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of vehicle operating status analysis, and in particular to a vehicle operating condition classification method, product and equipment based on Transformer. Background Art
[0002] Vehicle operating condition data includes vehicle speed and acceleration, and for cars, even steering angle, engine speed, throttle opening and other data. Since most vehicle operating condition data are unsupervised data, clustering is required to achieve vehicle operating condition classification through clustering. Vehicle operating condition classification can help understand and analyze the operating status and safety level of vehicles under different operating conditions, thereby providing useful information and services to vehicle drivers, vehicle manufacturers, traffic management agencies, etc. It is the basis for identifying driving modes and analyzing vehicle operating status, and can be used to reduce traffic accidents and optimize vehicle energy management.
[0003] Since abstract features are easier to cluster than original vehicle operating condition data, existing vehicle operating condition clustering methods are usually based on autoencoder neural network models. The autoencoder neural network model is mainly composed of an encoder and a decoder. The encoder is used to reduce the dimension of vehicle operating condition data features to generate abstract features, and the abstract features are clustered using traditional clustering methods such as K-means. The effect is significantly better than directly reducing the dimension using principal component analysis. The decoder restores the abstract features to vectors that are extremely similar to the input vehicle operating condition data features, so as to train the encoder so that the output abstract feature vector accurately expresses the input vehicle operating condition data features.
[0004] However, the encoders of existing autoencoder neural network models often use recurrent neural networks (RNNs), convolutional neural networks (CNNs), etc. These neural networks cannot learn the relationship between vehicle operating condition data features in parallel when learning operating condition features. When faced with rich vehicle operating condition data feature samples, the long-term dependencies that exist can easily lead to gradient disappearance or explosion, and the nonlinear information of the original vehicle operating condition data cannot be fully represented by the abstract features generated by the encoder, which in turn affects the accuracy of vehicle operating condition classification. In addition, in the current training process of the operating condition clustering encoder based on the autoencoder, it is generally necessary to initialize the cluster center and the predicted distribution of the data before each gradient descent to construct clustering losses such as KL divergence. The computational efficiency is relatively low, resulting in slow training speed. Summary of the invention
[0005] The present invention aims to at least solve the technical problems existing in the prior art and provide a vehicle operating condition classification method, product and equipment based on Transformer.
[0006] In order to achieve the above-mentioned purpose of the present invention, according to the first aspect of the present invention, the present invention provides a vehicle operating condition classification method based on Transformer, comprising: obtaining a vehicle operating condition data set, and obtaining a true sample set based on the vehicle operating condition data set; constructing a Transformer network, wherein the Transformer network comprises an encoder and a decoder; iteratively training the Transformer network to obtain a vehicle operating condition encoder; using the vehicle operating condition encoder to generate an abstract feature vector set corresponding to the true sample set, and clustering the abstract feature vector set to obtain a vehicle operating condition classification result; wherein the t-th iteration training of the Transformer network comprises: The true sample subset for the t-th iteration training is concentratedly extracted; the encoder generates an abstract feature vector subset corresponding to the true sample subset; the decoder reconstructs the true sample subset based on the abstract feature vector subset corresponding to the true sample subset to obtain a decoding sequence set; the clustering loss is calculated based on the abstract feature vector subset corresponding to the true sample subset; the reconstruction loss is calculated based on the abstract feature vector subset corresponding to the true sample subset and the decoding sequence set; the total loss of the t-th iteration is obtained by summing the clustering loss and the reconstruction loss; if the total loss of the t-th iteration reaches the iteration stopping condition, the encoder of the t-th iteration is used as the vehicle operating condition encoder, otherwise the network parameters of the Transformer network are updated using the gradient descent method according to the total loss of the t-th iteration, and t is a positive integer.
[0007] In order to achieve the above-mentioned purpose of the present invention, according to the second aspect of the present invention, the present invention provides a computer program product, including a computer program / instructions, characterized in that when the computer program / instructions are executed by a processor, the steps of the method described in the first aspect of the present invention are implemented.
[0008] In order to achieve the above-mentioned purpose of the present invention, according to the third aspect of the present invention, the present invention provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Transformer-based vehicle operating condition classification method as described in the first aspect of the present invention.
[0009] The present invention obtains a vehicle operating condition encoder by training a Transformer network, which uses an attention mechanism to perform parallel encoding processing on various feature data of samples, thereby avoiding gradient vanishing or exploding due to long-term dependencies when using recurrent network encoding, and can better handle dependencies in vehicle operating conditions, learn more comprehensive features, and effectively alleviate the gradient vanishing problem, so that the abstract feature vector generated by the vehicle operating condition encoder can accurately express the original vehicle operating condition information, thereby improving the accuracy of vehicle operating condition classification; in addition, the introduction of clustering loss eliminates the need to search for initial clustering centers during the training process, so that the Transformer network can process more data within the same training time, accurately guide the direction of gradient descent, improve the efficiency of gradient descent, achieve rapid convergence, and improve training efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0010] Figure 1 is a flow chart of a vehicle operating condition classification method in a preferred embodiment of the present invention;
[0011] Figure 2 It is a schematic diagram of the attention mechanism of the Transformer network in a preferred embodiment of the present invention;
[0012] Figure 3 It is a flowchart of iterative training in a preferred embodiment of the present invention;
[0013] Figure 4 It is an iterative training flow chart in another preferred embodiment of the present invention;
[0014] Figure 5 It is a flow chart of working condition classification in a specific application scenario of the present invention;
[0015] Figure 6 This is a diagram of experimental verification results of the vehicle operating condition classification method based on the Transformer network provided by the present invention;
[0016] Figure 7 This is the K-means clustering result diagram of the original vehicle operating condition data;
[0017] Figure 8 This is the K-means clustering result diagram based on the existing DTCR classification method;
[0018] Fig. 9 It is a schematic structural diagram of an electronic device in a preferred embodiment of the present invention. DETAILED DESCRIPTION
[0019] Embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be understood as limiting the present invention.
[0020] In the description of the present invention, it is necessary to understand that the terms "longitudinal", "lateral", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", etc., indicating the orientation or position relationship, are based on the orientation or position relationship shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention.
[0021] In the description of the present invention, unless otherwise specified and limited, it should be noted that the terms "installed", "connected" and "connected" should be understood in a broad sense. For example, it can be a mechanical connection or an electrical connection, or it can be the internal connection between two components. It can be a direct connection or an indirect connection through an intermediate medium. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to the specific circumstances.
[0022] The execution subject of the Transformer-based vehicle operating condition classification method includes but is not limited to at least one of the electronic devices such as a server and a terminal that can be configured to execute the method provided in the embodiment of the present application. In other words, the Transformer-based vehicle operating condition classification method can be executed by software or hardware installed on a terminal device or a server device. The server includes but is not limited to: a single server, a server cluster, a cloud server or a cloud server cluster, etc. The server can be an independent server, or it can be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms.
[0023] In a preferred embodiment of the vehicle operating condition classification method based on Transformer disclosed in the present invention, referring to Figure 1 , Figure 3 , Figure 4 and Figure 5 ,include:
[0024] Step S1, obtaining a vehicle operating condition data set, and obtaining a true sample set based on the vehicle operating condition data set.
[0025] In this embodiment, the vehicle operating condition data set includes a vehicle speed time series and a vehicle acceleration time series. The vehicle is preferably, but not limited to, various automobiles, various electric vehicles, and motorcycles. The time step in the vehicle speed time series and the vehicle acceleration time series can be 1 s. For uniform sampling, the vehicle operating condition data set can be collected by a vehicle speed sensor or a vehicle acceleration sensor installed on the vehicle.
[0026] In this embodiment, in order to improve the accuracy of vehicle operating condition classification, preferably, in step S1, obtaining a true sample set based on the vehicle operating condition data set includes:
[0027] Step S11, processing the vehicle operating condition data set into a plurality of column data of preset time lengths.
[0028] In this embodiment, the preset time length can be customized by the user, such as 60s. The speed time series and acceleration time series of the vehicle operating condition data set are segmented in sequence according to the preset time length to obtain a plurality of time segment data, each of which is a column data, and a corresponding true sample is subsequently generated.
[0029] Step S12, obtaining multiple statistical features of each column data, the multiple statistical features include average speed, maximum speed, speed variance, time seconds that the speed is greater than the first speed threshold, time seconds that the speed is greater than the second speed threshold, average acceleration, maximum acceleration, time seconds that the absolute value of acceleration is greater than the first acceleration threshold, time seconds that the absolute value of acceleration is greater than the second acceleration threshold, and acceleration variance, all or part of them. The first speed threshold and the second speed threshold are both absolute value thresholds, and the first speed threshold is less than the second speed threshold. The first acceleration threshold and the second acceleration threshold are both absolute value thresholds, and the first acceleration threshold is greater than the second acceleration threshold. In an example, the statistical features of the sample are listed as follows:
[0030] Table 1 List of statistical features
[0031]
[0032] Step S13: normalize the statistical features of all column data to obtain a true sample set. The normalization method is preferably, but not limited to, normalizing to a preset interval, which may be [0, 1].
[0033] Step S2: construct a Transformer network, which includes an encoder and a decoder.
[0034] Step S3, iteratively train the Transformer network to obtain a vehicle operating condition encoder.
[0035] The encoder of the Transformer network uses a multi-head attention mechanism to encode samples of vehicle operating condition data. The encoding process is as follows: Figure 2 shown.
[0036] Suppose a statistical feature (single-value vector) of a sample is a i For example, the sample is different from a i The statistical characteristics of a j . Initialize their query matrix, key matrix and value matrix respectively: V i , V j . Calculate the query and key of each feature to obtain the vector q i ,k i ,q j ,k j :
[0037]
[0038] Then calculate a i The relationship between all eigenvectors including itself, a i The relevance to the jth feature is expressed using the attention score α i,j express.
[0039] α i,i =q i ·k i
[0040] α i,j =q i ·k j
[0041] Perform softmax operation on the attention score to obtain α' i,i ,α' i,j , they are respectively inner-producted with their respective value matrices and summed to obtain a i The corresponding code b i :
[0042]
[0043] The Transformer network of this application uses a two-headed attention mechanism to perform the above operations on the data of each statistical feature in the sample, obtains the encoding of all features, and then transforms them through the fully connected layer. In addition, the Transformer network will standardize the input of each layer. Layer standardization helps to reduce the internal covariate shift (Internal Covariate Shift) during the model training process, thereby accelerating the convergence speed of the model and increasing the stability of the model.
[0044] After being processed by two encoding units consisting of an attention mechanism layer and a fully connected layer, each sample is encoded to obtain an abstract feature vector of the same shape, such as (10, 1), where 10 represents the number of statistical features in each sample.
[0045] In order to enable the decoder of the Transformer network to reconstruct the original sample statistical feature data to the greatest extent through the abstract feature vector, the present invention inputs the real data and its corresponding abstract feature vector as input vectors into the decoder of the Transformer network, and uses a two-headed attention mechanism for processing, so as to capture the key features of the original sample statistical feature data in the decoded sequence. Then, the decoded sequence is obtained through the full connection layer, linear layer and softmax processing, and the decoded sequence is a reconstruction and restoration of the original feature data.
[0046] Step S4, using the vehicle operating condition encoder to generate an abstract feature vector set corresponding to the true sample set, and performing clustering processing on the abstract feature vector set to obtain a vehicle operating condition classification result.
[0047] In this embodiment, after the training is completed, a vehicle operating condition encoder is obtained, and the true sample set is re-input into the vehicle operating condition encoder to obtain a new set of abstract feature vectors, and the vehicle operating condition classification result is obtained through clustering processing. Since the survey found that the safety of vehicle driving is negatively correlated with vehicle speed, acceleration, and sudden acceleration. According to this survey, multiple operating condition categories can be defined, and multiple operating condition categories correspond to different safety levels. Let the target cluster number be expressed as N, then the vehicle operating condition classification result divides the true sample set into N clusters, each cluster represents a working condition category, and also corresponds to a safety level.
[0048] In one example, N is 5 and the defined operating conditions are:
[0049] Category 0 has a higher average speed, but the variance of speed and acceleration is low, the absolute value of acceleration is low, and there is almost no sudden acceleration or deceleration. The corresponding safety level is high-speed safety type.
[0050] Category 1 has a high average speed and sometimes exceeds 80 km / h, but has a low variance and low acceleration and deceleration, and its corresponding safety level is high-speed general type.
[0051] Category 2 has a low average speed and a lower speed variance than other low-speed situations. It also has a low absolute value of acceleration and a low rate of change. The corresponding safety level is low-speed safety.
[0052] Category 3 has a slightly higher average speed and a larger speed variance, but a lower absolute value of acceleration and fewer sudden accelerations and decelerations, and its corresponding safety level is low-speed general.
[0053] Category 4 has a low average speed, a large speed variance, a large absolute value of acceleration, a large rate of change, and frequent sudden acceleration and deceleration. The corresponding safety level is low-speed dangerous type.
[0054] According to the negative correlation between vehicle speed, acceleration value and safety, the five types of safety are ranked from high to low: low-speed safety type, high-speed safety type, low-speed general type, high-speed general type, and low-speed dangerous type.
[0055] In this embodiment, refer to Figure 3 As shown, the t-th iteration training of the Transformer network includes:
[0056] Step A101, extract the true sample subset for the tth iteration training from the true sample set to obtain the true sample subset for this batch training. The true sample set can be evenly divided into multiple true sample subsets in advance, and a true sample subset is obtained for each iteration training. After the entire true sample set training is completed, a verification test can be performed.
[0057] Step A102: The encoder generates a subset of abstract feature vectors corresponding to the subset of true samples. The encoder generates a corresponding abstract feature vector for each true sample to express the true sample for subsequent clustering processing.
[0058] Step A103: The decoder reconstructs the true sample subset based on the abstract feature vector subset corresponding to the true sample subset to obtain a decoding sequence set.
[0059] The decoder reconstructs each true sample based on its abstract feature vector to obtain a corresponding decoding sequence. The decoding sequences corresponding to all true samples constitute a decoding sequence set.
[0060] Step A104, calculating the clustering loss based on the abstract feature vector subset corresponding to the true sample subset k ; The clustering loss can be calculated using the existing K-means clustering method.
[0061] Calculate the reconstruction loss Loss based on the abstract feature vector subset corresponding to the true sample subset and the decoding sequence set reconstruction .
[0062] Step A105, sum the clustering loss and reconstruction loss to obtain the total loss Loss of the tth iteration:
[0063] Loss=Loss k +Loss reconstruction .
[0064] Step A106, if the total loss of the tth iteration reaches the iteration stop condition, the encoder of the tth iteration is used as the vehicle operating condition encoder, otherwise the network parameters of the Transformer network are updated using the gradient descent method according to the total loss of the tth iteration.
[0065] In this embodiment, t is a positive integer. The iteration stop condition is preferably, but not limited to, that the total loss drops to an acceptable range, specifically, that the total loss is less than or equal to a preset loss threshold; or, the iteration stop condition is that the number of iterations t reaches a preset maximum number of iterations T.
[0066] In a preferred embodiment, in order to make the abstract feature vector learned by the encoder more balanced, to capture the nonlinear patterns and relationships in the data, and to improve the efficiency of gradient descent, when calculating the clustering loss, the clustering loss is calculated based on the Gaussian kernel. Therefore, in step A104, the clustering loss is calculated based on the subset of abstract feature vectors corresponding to the subset of true samples, including:
[0067] Step a, construct the kernel matrix K based on the abstract feature vector subset corresponding to the true sample subset:
[0068] K=[k i,j ] n×n ;
[0069] Among them, the element k in the i-th row and j-th column of the kernel matrix K is i,j :
[0070]
[0071] The size of the kernel matrix K is n×n, where n represents the number of samples in the true sample subset; w i represents the abstract feature vector corresponding to the i-th true sample in the true sample subset, w j Represents the abstract feature vector corresponding to the jth true sample in the true sample subset; σ1 represents the preset first adjustment parameter; i,j∈[1,n].
[0072] The abstract feature vector subset corresponding to the true sample subset can be expressed as an abstract feature matrix W:
[0073] W=[w1,w2,...,w n ];
[0074] The number of columns of the abstract feature matrix W is the number of samples in the sample subset, and the number of rows is the number of statistical features.
[0075] Step b: Calculate the clustering loss according to the following formula:
[0076] Loss k = trace(K)-trance(F T KF)
[0077] Where k represents the number of target clusters; F represents the cluster indicator matrix; F T represents the transpose of the cluster indicator matrix F; trace(·) represents the trace of the matrix. At the beginning of the iteration, the cluster indicator matrix is initialized to an orthogonal matrix with the number of rows equal to the number of samples in the true sample subset and the number of columns equal to the number of target clusters.
[0078] In an example, when the target clustering number is 5 and the number of statistical features of each sample is 10, the number of rows of the cluster indication matrix is initially the number of samples in the true sample subset, and the number of columns is the target clustering number 5.
[0079] In this embodiment, further preferably, the cluster indicator matrix is updated in iterative training as follows:
[0080] Step 1: If the current iteration number t is not an integer multiple of the preset update period TN, the cluster indicator matrix is not updated;
[0081] If the current iteration number t is an integer multiple of the preset update period TN, then:
[0082] Step 2: Perform singular value decomposition on the kernel matrix K of the tth iteration to obtain the left singular vector matrix U, the singular value vector σ, and the right singular vector matrix V T ;
[0083] Step 3: According to the size of the singular value vector σ, the right singular vector matrix V T Sort the vectors in and select the number of vectors of the former target clusters as the new cluster indicator matrix F new , as the cluster indicator matrix for the t+1th iteration; the update period TN ranges from 10 to 30, preferably 20. Specifically, the singular value vector σ is a diagonal matrix, the diagonal elements of the singular value vector σ are sorted from large to small, and the right singular vector matrix V is updated according to the column index sequence of the diagonal elements in the sorting. T Sort the column vectors corresponding to the column index numbers in the cluster, and select the column vectors of the previous target clusters to form a new cluster indicator matrix F new .
[0084] In this embodiment, the abstract feature vector learned by the encoder model of the Transformer network based on the clustering loss of the Gaussian kernel matrix has a more complex structure in the feature space, and is relatively more capable of capturing nonlinear patterns and relationships in the data, reflecting the deeper understanding of the data by the Transformer network based on the Gaussian kernel clustering loss, as well as its more powerful feature learning ability. Thanks to the parallel calculation of the Gaussian kernel clustering loss function and the attention mechanism, the introduction of the clustering loss does not require searching for the initial cluster center during the training process. Parallel calculation enables the model to process more data in the same training time, accurately guides the direction of gradient descent, and improves the efficiency of gradient descent. The two converge to better results faster, which can reduce the training time of the Transformer network.
[0085] In a preferred embodiment, the reconstruction loss of the tth iteration is:
[0086]
[0087] Among them, n represents the number of samples in the true sample subset, x i represents the i-th true sample in the true sample subset; Represents the decoding sequence corresponding to the i-th true sample in the true sample subset.
[0088] In this embodiment, the difference between the original data and the reconstructed data is measured by reconstruction loss to encourage the model to learn more informative feature representations. This prevents the occurrence of meaningless feature vectors that are unrelated to the original feature data but very suitable for clustering. The present invention uses the mean square error between the decoded data and the original data as the reconstruction loss.
[0089] In a preferred embodiment, the present invention provides a Transformer-based vehicle operating condition classification method, further comprising:
[0090] Construct a set of false samples corresponding to the true sample set. After obtaining the true sample set, generate a corresponding false sample for each true sample to obtain a false sample set. For a true sample, at least one statistical feature value can be changed by a large amplitude (such as the difference between the changed statistical feature value and the original statistical feature value is greater than a preset difference threshold) to obtain a false sample corresponding to the true sample. Set labels for true samples and false samples respectively, the true label of the true sample is set to true (1), and the true label of the false sample is set to false (0).
[0091] Construct a classification neural network. The abstract feature vectors extracted by the encoder for the real samples and fake samples and the real labels (indicating whether they are real) are input into the classification neural network to complete the auxiliary classification task. The goal of the classification neural network is to identify whether the corresponding sample is real data or fake data through the abstract feature vector. The classification neural network includes at least two cascaded fully connected layers.
[0092] In this implementation, the t-th iteration training of the Transformer network also includes:
[0093] A fake sample subset corresponding to the true sample subset is extracted from the fake sample set, that is, the fake sample subset corresponds one-to-one to the samples in the true sample subset.
[0094] The encoder generates a subset of abstract feature vectors corresponding to the subset of fake samples.
[0095] The classification neural network is used to classify the abstract feature vector subset corresponding to the true sample subset and the abstract feature vector subset corresponding to the false sample subset to obtain the classification loss. The classification loss of the tth iteration is:
[0096]
[0097] Where 2n represents the total number of abstract feature vectors of the abstract feature vector subset corresponding to the true sample subset and the abstract feature vector subset corresponding to the false sample subset at the tth iteration, y p Represents the true label corresponding to the pth abstract feature vector; Represents the predicted label of the pth abstract feature vector output by the classification neural network, 1≤p≤2n. The real label content is true and false (corresponding to 1 and 0), and the predicted label content is true and false (corresponding to 1 and 0).
[0098] The total loss of the tth iteration also includes the classification loss. The specific total loss is:
[0099] Loss=Loss k +Loss reconstruction +Loss classify .
[0100] In this embodiment, refer to Figure 4 , the t-th iteration training process of the Transformer network includes:
[0101] Step B101, extracting a true sample subset for the t-th iteration training from the true sample set, and extracting a false sample subset corresponding to the true sample subset from the false sample set.
[0102] Step B102: The encoder generates a subset of abstract feature vectors corresponding to the subset of true samples. The encoder generates a subset of abstract feature vectors corresponding to the subset of fake samples.
[0103] Step B103: The decoder reconstructs the true sample subset based on the abstract feature vector subset corresponding to the true sample subset to obtain a decoding sequence set.
[0104] Step B104, using a classification neural network to classify the abstract feature vector subset corresponding to the true sample subset and the abstract feature vector subset corresponding to the false sample subset to obtain a classification loss.
[0105] Step B105, calculating the clustering loss Loss based on the abstract feature vector subset corresponding to the true sample subset k ; Calculate the reconstruction loss Loss based on the abstract feature vector subset corresponding to the true sample subset and the decoding sequence set reconstruction .
[0106] Step B106, summing up the clustering loss, reconstruction loss and classification loss to obtain the total loss of the tth iteration.
[0107] Step B107, if the total loss of the tth iteration reaches the iteration stop condition, the encoder of the tth iteration is used as the vehicle operating condition encoder, otherwise the network parameters of the Transformer network are updated using the gradient descent method according to the total loss of the tth iteration.
[0108] In this embodiment, the auxiliary classification task is introduced through the classification neural network, and the encoder of the Transformer network is forced to learn more discriminative feature representations, which helps to improve the performance and generalization ability of the encoder. At the same time, the auxiliary classification task also serves as a regularization method to help prevent overfitting.
[0109] Figure 5 A flow chart of the present embodiment in a specific application scenario is shown. The true data is a subset of true samples, and the false data is a subset of false samples. After the training is completed, the working condition classification is completed by the spectral clustering method. In the method provided by the present invention, Transformer is used for clustering. The goal is that the encoder can extract good feature representations from the working condition data, rather than generating an excellent target sequence. It is necessary to consider all input working condition feature information. Therefore, the decoding process does not limit the model to only focus on the information before the current position, and the original feature data is not masked in order to improve the feature extraction ability and clustering effect of the model.
[0110] In a preferred embodiment, in step S4, a spectral clustering method is used to cluster the abstract feature vector set to obtain a vehicle operating condition classification result.
[0111] In this embodiment, the spectral clustering method performs clustering by constructing a similarity graph between abstract feature vectors, which can better consider the connectivity between samples. This method can help identify the connectivity between different regions in the abstract feature vector set. Compared with the K-means algorithm, which is easily affected by the selection of the initial cluster center, spectral clustering is not sensitive to the selection of initial values, and is not easy to fall into the local optimal solution, reducing the dependence on the initial value. And better separate different clusters, so that the vehicle operating condition classification results obtained have a stronger degree of separation.
[0112] The effect of the Transformer-based vehicle operating condition classification method provided by the present invention is verified:
[0113] To obtain the experimental data set, we select the existing TSDC vehicle operating condition data set. The valid data includes the acceleration and speed of the vehicle. Part of the data is shown in Table 2:
[0114] Table 2 Partial data of TSDC
[0115]
[0116] In order to preserve the long-term speed change characteristics and detailed characteristics of the vehicle working conditions, they are processed into time series samples with a length of 60s, and the ten statistical features in Table 1 above are calculated for each sample, and a total of 8560 samples are obtained. In other words, the shape of the input data of the Transformer model is (8560,10). After standardization, a fake sample is generated for each sample, and the two are input into the Transformer encoder together, with all 8560 real data in front and 8560 fake data in the back, for a total of 17120 samples.
[0117] Use real samples for training, add noise perturbations randomly sampled from a normal distribution with a mean of 0 and a standard deviation of 0.01, input the real samples and the corresponding fake samples into the network, and initialize the query, key, and value matrices in the Transformer according to the uniform distribution of (-0.1, 0.1). After 1000 generations of training, the total loss function is reduced to about 1, and then spectral clustering is performed on the abstract features of the real samples. The clustering results are visualized using the t-sne method as shown below: Figure 6 , and directly perform K-means clustering on the original data Figure 7 , the results of the DTCR model encoded using a bidirectional dilated recurrent neural network on the same dataset Figure 8By comparison, it is found that the Transformer-RKB model provided by the present invention has a good separation degree and can clearly separate the working conditions with different average vehicle speeds, and there is no intersection between the average vehicle speeds of different clusters. The classification method provided by the present invention obtains 5 clusters and the characteristic values of the cluster centers of each cluster as shown in Table 3 below.
[0118] Table 3 The eigenvalues of the cluster centers of the five clusters
[0119]
[0120] It can be seen that the vehicle operating condition classification method based on Transformer provided by the present invention has the following advantages:
[0121] 1. The learned abstract features are more balanced: refer to Figure 6-Figure 8 Through clustering visualization, it can be found that the abstract vectors learned by the existing DTCR model are almost linearly arranged in three clusters after clustering using K-means, while the abstract vectors learned by the Transformer model of the present invention are not linearly arranged after spectral clustering. This shows that the abstract features learned by the DTCR model have a simpler structure, resulting in a relatively balanced linear relationship in the feature space. It is more inclined to capture the basic patterns and structures in the data. The abstract features learned by the Transformer model based on Gaussian kernel clustering loss in this application have a more complex structure in the feature space, and are relatively more capable of capturing nonlinear patterns and relationships in the data. This reflects the deeper understanding of the data by the Transformer model based on Gaussian kernel clustering loss, as well as its more powerful feature learning capabilities.
[0122] 2. Alleviate the problem of gradient vanishing. The attention mechanism used by the Transformer in this application performs parallel encoding processing on each feature data, thereby avoiding the gradient vanishing or exploding caused by the long-term dependency relationship when using recurrent network coding, better handling the dependency relationship in the vehicle working conditions, and learning more comprehensive features.
[0123] 3. Fast training speed: The existing DTCR model takes longer to train than the Transformer in this application, thanks to the parallel calculation of the Gaussian kernel clustering loss function and the attention mechanism. The introduction of this clustering loss does not require searching for the initial cluster center during the training process. Parallel calculation enables the model to process more data in the same training time, accurately guides the direction of gradient descent, and improves the efficiency of gradient descent. Both converge to better results faster.
[0124] 4. Spectral clustering has stronger separation of clustering results: Spectral clustering performs clustering by constructing similarity graphs between samples, reducing the dependence on initial values, which can better consider the connectivity between samples. This method can help identify the connectivity between different regions in the data set and better separate different clusters.
[0125] The present invention also discloses a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the above-mentioned Transformer-based vehicle operating condition classification method provided by the present invention. The computer program product should be understood as a software product that mainly implements its solution through a computer program, such as a program product integrated in the cloud or a software library.
[0126] The present invention also discloses an electronic device. In one embodiment, the electronic device includes at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Transformer-based vehicle operating condition classification method provided by the present invention.
[0127] like Fig. 9 , which is a schematic diagram of the structure of an electronic device of a vehicle operating condition classification method based on Transformer according to an embodiment of the present invention. The electronic device may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13, and may also include a computer program stored in the memory 11 and executable on the processor 10, such as a vehicle operating condition classification method program based on Transformer.
[0128] In some embodiments, the processor 10 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 10 is the control core (Control Unit) of the electronic device, and uses various interfaces and lines to connect various components of the entire electronic device. It runs or executes programs or modules stored in the memory 11 (for example, executing a vehicle operating condition classification method based on a Transformer, etc.), and calls data stored in the memory 11 to execute various functions of the electronic device and process data.
[0129] The memory 11 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a mobile hard disk, a multimedia card, a card-type memory (for example, SD or DX memory, etc.), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 11 may be an internal storage unit of an electronic device, such as a mobile hard disk of the electronic device. In other embodiments, the memory 11 may also be an external storage device of an electronic device, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device. Further, the memory 11 may also include both an internal storage unit of the electronic device and an external storage device. The memory 11 can not only be used to store application software and various types of data installed in the electronic device, such as the code of the vehicle operating condition classification method program based on Transformer, but also can be used to temporarily store data that has been output or is to be output.
[0130] The communication bus 12 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. The bus is configured to realize connection and communication between the memory 11 and at least one processor 10, etc.
[0131] The communication interface 13 is used for communication between the above-mentioned electronic device and other devices, including a network interface and a user interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), which is generally used to establish a communication connection between the electronic device and other electronic devices. The user interface may be a display (Display), an input unit (such as a keyboard (Keyboard)), and optionally, the user interface may also be a standard wired interface, a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode, organic light-emitting diode) touch device, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface.
[0132] Fig. 9 Only an electronic device with components is shown, and those skilled in the art will understand that Fig. 9The structure shown does not constitute a limitation on the electronic device, and may include fewer or more components than shown, or combine certain components, or arrange the components differently. For example, although not shown, the electronic device may also include a power supply (such as a battery) for supplying power to each component. Preferably, the power supply may be logically connected to at least one processor 10 through a power management device, so that functions such as charging management, discharging management, and power consumption management are implemented through the power management device. The power supply may also include any components such as one or more DC or AC power supplies, recharging devices, power failure detection circuits, power converters or inverters, power status indicators, etc. The electronic device may also include a variety of sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.
[0133] It should be understood that the embodiment is for illustration only and the scope of the patent application is not limited by this structure.
[0134] Furthermore, if the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a mobile hard disk, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).
[0135] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", "an implementation", "a preferred implementation" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.
[0136] Although the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.
Claims
1. A vehicle operating condition classification method based on Transformer, characterized in that: include: Acquire a vehicle operating condition data set, and acquire a true sample set based on the vehicle operating condition data set; Constructing a Transformer network, wherein the Transformer network includes an encoder and a decoder; Iteratively train the Transformer network to obtain the vehicle operating condition encoder; The vehicle operating condition encoder is used to generate an abstract feature vector set corresponding to the true sample set, and the abstract feature vector set is clustered to obtain the vehicle operating condition classification result; Among them, the t-th iteration training of the Transformer network includes: Extract the true sample subset for the t-th iteration training from the true sample set; The encoder generates a subset of abstract feature vectors corresponding to the subset of true samples; The decoder reconstructs the true sample subset based on the abstract feature vector subset corresponding to the true sample subset to obtain a decoding sequence set; Calculate the clustering loss based on the subset of abstract feature vectors corresponding to the subset of true samples; The reconstruction loss is calculated based on the abstract feature vector subset corresponding to the true sample subset and the decoded sequence set; Sum the clustering loss and reconstruction loss to get the total loss of the tth iteration; If the total loss of the tth iteration reaches the iteration stop condition, the encoder of the tth iteration is used as the vehicle condition encoder. Otherwise, the network parameters of the Transformer network are updated using the gradient descent method according to the total loss of the tth iteration, where t is a positive integer. The clustering loss is calculated based on the abstract feature vector subset corresponding to the true sample subset, including: Construct the kernel matrix K based on the abstract feature vector subset corresponding to the true sample subset: K=[k i,j ] n×n ; Among them, the element k in the i-th row and j-th column of the kernel matrix K is i,j : The size of the kernel matrix K is n×n, where n represents the number of samples in the true sample subset; w i represents the abstract feature vector corresponding to the i-th true sample in the true sample subset, w j represents the abstract feature vector corresponding to the jth true sample in the true sample subset; σ1 represents the preset first adjustment parameter; i,j∈[1,n]; The clustering loss is calculated according to the following formula: Loss k =trace(K)-trance(F T KF) Where k represents the number of target clusters; F represents the cluster indicator matrix; F T represents the transpose of the cluster indicator matrix F; trace(·) represents obtaining the trace of the matrix.
2. The vehicle operating condition classification method based on Transformer according to claim 1, characterized in that: The obtaining of a true sample set based on the vehicle operating condition data set comprises: Processing the vehicle operating condition data set into a plurality of column data of preset time lengths; Acquire multiple statistical features of each column data, wherein the multiple statistical features include all or part of an average speed, a maximum speed, a speed variance, a time in seconds when the speed is greater than a first speed threshold, a time in seconds when the speed is greater than a second speed threshold, an average acceleration, a maximum acceleration, a time in seconds when the absolute value of the acceleration is greater than a first acceleration threshold, a time in seconds when the absolute value of the acceleration is greater than a second acceleration threshold, and an acceleration variance; The statistical characteristics of all column data are standardized to obtain the true sample set.
3. The vehicle operating condition classification method based on Transformer according to claim 1, characterized in that: The updating method of the cluster indicator matrix in iterative training is: If the current iteration number t is not an integer multiple of the preset update period TN, the cluster indicator matrix is not updated; If the current iteration number t is an integer multiple of the preset update period TN, then: Perform singular value decomposition on the kernel matrix K of the tth iteration to obtain the left singular vector matrix U, the singular value vector σ and the right singular vector matrix V T ; According to the size of the singular value vector σ, the right singular vector matrix V T Sort the vectors in and select the number of vectors of the former target clusters as the new cluster indicator matrix F new , as the cluster indicator matrix for the t+1th iteration; The update period TN ranges from 10 to 30.
4. The vehicle operating condition classification method based on Transformer according to claim 1, characterized in that: The reconstruction loss at the tth iteration is: Among them, n represents the number of samples in the true sample subset, x i represents the i-th true sample in the true sample subset; Represents the decoding sequence corresponding to the i-th true sample in the true sample subset.
5. The vehicle operating condition classification method based on Transformer according to any one of claims 1 to 4, characterized in that: Also includes: Construct a fake sample set corresponding to the real sample set; Build a classification neural network; The t-th iteration training of the Transformer network also includes: Extracting a subset of fake samples corresponding to the subset of true samples from the fake sample set; The encoder generates a subset of abstract feature vectors corresponding to the subset of fake samples; A classification neural network is used to classify the abstract feature vector subset corresponding to the true sample subset and the abstract feature vector subset corresponding to the false sample subset to obtain the classification loss; The total loss at iteration t also includes the classification loss.
6. The vehicle operating condition classification method based on Transformer according to claim 5, characterized in that: The classification loss at the tth iteration is: Where 2n represents the total number of abstract feature vectors of the abstract feature vector subset corresponding to the true sample subset and the abstract feature vector subset corresponding to the false sample subset at the tth iteration, y p Represents the true label corresponding to the pth abstract feature vector; Represents the predicted label of the pth abstract feature vector output by the classification neural network, 1≤p≤2n.
7. The vehicle operating condition classification method based on Transformer according to any one of claims 1 to 4 and 6, characterized in that: The spectral clustering method is used to cluster the abstract feature vector set to obtain the vehicle operating condition classification results.
8. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
9. An electronic device, characterized in that: The electronic device comprises: At least one processor; and, a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the Transformer-based vehicle operating condition classification method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Depth image clustering method and system and storage medium
CN116342915A
Target detection method based on transformer architecture
CN117315223A