Transform-based driving habit prediction method and device
Through the driving habit prediction method based on Transformer, the multi-head self-attention mechanism and residual connection are used to solve the problem of difficult to predict drivers' personalized driving habits in the prior art, efficient and accurate driving habit prediction is achieved, and driving safety and comfort are improved.
Patent Information
- Application Number
- CN202411719119.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-03-21
AI Technical Summary
The existing driving habit prediction methods are difficult to accurately capture and predict drivers’ personalized driving habits in different situations, and there are problems of gradient disappearance and gradient explosion, so they cannot be calculated in parallel.
Using the driving habit prediction method based on Transformer, the driver's historical vehicle driving data is obtained and preprocessed, the data samples are extracted using the sliding window, and the Transformer model is used for training, combining the multi-head self-attention mechanism and residual connection to solve the problem of gradient vanishing and parallel computing.
Accurate prediction of driver driving habits is achieved, timeliness and accuracy of predictions are improved, gradient disappearance and gradient explosion problems are avoided, parallel computing capabilities of the model are enhanced, and driving safety and comfort are significantly improved.
Smart Images

Figure CN119659639A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a driving habit prediction method and device based on Transformer, belonging to the technical field of automatic driving and intelligent driving assistance. Background Art
[0002] With the rapid development of autonomous driving technology, improving the vehicle's ability to understand and predict the driver's intentions has become the key. Common prediction methods can be divided into prediction methods based on physical models, prediction methods based on traditional machine learning, and prediction methods based on deep learning.
[0003] Among them, the prediction method based on physical models mainly models the vehicle according to its dynamic or kinematic constraints to predict the vehicle's future motion state, but it often relies on complex sensor networks and preset rules, making it difficult to accurately capture and predict the driver's personalized driving habits in different situations.
[0004] The prediction method based on traditional machine learning establishes corresponding algorithms and models for prediction by associating vehicle historical data with prediction data, such as Kalman filter prediction, Bayesian network prediction, Markov chain prediction, etc. The above prediction methods can realize the prediction of vehicle motion state in a short time, but the method has low prediction accuracy, cannot make full use of historical data and is not suitable for training and learning of massive data. At the same time, it is sensitive to data fluctuations and is not suitable for prediction with a longer horizon.
[0005] The prediction method based on deep learning relies on huge network training and can learn more and richer types of features from historical information, so as to make more accurate predictions. Currently, the most commonly used deep learning prediction models are long short-term memory networks (LSTM) and the combination of LSTM and convolutional neural networks (CNN). LSTM and its variant models can basically solve the prediction difficulties of traditional prediction methods. However, as the scale of data sets becomes larger and the scene information becomes richer, LSTM still has not solved the problems of gradient disappearance and gradient explosion and cannot perform parallel operations.
[0006] Therefore, existing prediction methods have various defects and are unable to guide autonomous driving and assisted driving in real time; therefore, it is particularly important to study and develop a technology that can efficiently learn and predict driving habits based on the driving habits of different drivers. Summary of the invention
[0007] The purpose of the present invention is to provide a driving habit prediction method and device based on Transformer, which can obtain relevant predicted driving information based on individual differences to assist driving and improve the driver's driving experience.
[0008] In order to solve the above technical problems, the present invention is implemented by adopting the following technical solutions.
[0009] A driving habit prediction method based on Transformer, comprising:
[0010] Obtain the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0011] A sliding window is used to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels;
[0012] The Transformer-based driving habit prediction model is trained using data samples containing corresponding data labels. During the training process, back propagation and parameter optimization are performed using the mean square error loss function to obtain the trained driving habit prediction model.
[0013] The real-time vehicle driving data is input into the trained driving habit prediction model to perform real-time prediction of the vehicle driving data and obtain the driving habit prediction results.
[0014] Optionally, the vehicle driving data includes: accelerator pedal opening, brake pedal opening, motor target speed, motor target torque, battery maximum discharge power and steering angle.
[0015] Optionally, the driver's historical vehicle driving data is preprocessed to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters, including:
[0016] Interpolate and index the vehicle driving data respectively to obtain the vehicle driving data aligned with the time axis;
[0017] Normalizing the vehicle driving data aligned with the time axis to obtain the vehicle driving data with extreme values removed;
[0018] Selecting vehicle driving data with extreme values removed based on preset step length parameters to obtain vehicle driving data with a fixed step length;
[0019] According to the vehicle driving data with a fixed step length, data with different physical meanings are spliced to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0020] The expression of the interpolation index is:
[0021]
[0022] In the formula, mid is the time axis alignment data returned by the interpolation index, low is the starting point of the search range on the time axis, high is the end point of the search range on the time axis, key is the actual sampling point of the target to be searched, arr is a sorted array, arr[low] and arr[high] are the actual values of the array at low and high respectively;
[0023] The normalized expression is:
[0024]
[0025] In the formula, To remove any data point in the vehicle driving data with extreme values, For each data point, is any data point in the vehicle driving data after interpolation search, is the minimum value of the vehicle driving data aligned with the time axis, It is the maximum value in the time-axis aligned vehicle driving data.
[0026] Optionally, a sliding window is used to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels, including:
[0027] A sliding window with a fixed step size is used to perform rolling sampling on the vehicle driving data sequence to obtain a set of multiple continuous data segments with a fixed size;
[0028] Concatenate a set of multiple continuous data segments of fixed size to obtain data labels;
[0029] Multiple continuous data segments of fixed size are concatenated with data labels to obtain data samples containing data labels;
[0030] Among them, the sliding window needs to be initialized before rolling sampling, and the sliding window size, step parameters and boundary conditions of the sliding window need to be set in advance;
[0031] The data sample is the current vehicle driving characteristics, and the data label is the operation performed by the user's driving habits corresponding to a fixed time in the future.
[0032] Optionally, a data sample containing corresponding data labels is used to train the Transformer-based driving habit prediction model. The training process includes:
[0033] Divide the data samples into training set and test set;
[0034] Perform position encoding on the training set and the test set to obtain the training set and the test set containing position information of different granularities;
[0035] Input the training set containing location information of different granularities into the Transformer-based driving habit prediction model to obtain the driving habit prediction results;
[0036] According to the data labels of the driving habit prediction results, find out the real driving habit results corresponding to the data labels;
[0037] Substitute the actual driving habit results and the predicted driving habit results into the mean square error loss function respectively, and calculate the mean square error loss value;
[0038] Back propagation and parameter optimization are performed according to the square error loss value to obtain an updated driving habit prediction model;
[0039] The updated driving habit prediction model is evaluated using the test set to obtain the driving habit prediction model with the best performance.
[0040] Optionally, divide the data sample into training and test sets, including:
[0041] Randomly sort all data samples containing data labels to obtain re-sorted data samples;
[0042] The reordered data samples are divided into training set and test set in a ratio of 8:2.
[0043] Optionally, position encoding is performed on the training set and the test set to obtain training sets and test sets containing position information of different granularities, including:
[0044] The position encoding matrix is used to perform position encoding on the training set and the test set to obtain the training set and the test set containing position information of different granularities.
[0045] Optionally, the training set containing location information of different granularities is input into the Transformer-based driving habit prediction model to obtain driving habit prediction results, including:
[0046] Perform feature extraction on the training set containing location information of different granularities to obtain training set features and training set feature vectors;
[0047] Perform weighted processing on the feature vector of the training set to obtain a weighted feature vector;
[0048] Prediction is performed based on the weighted feature vector to obtain the driving habit prediction result.
[0049] Optionally, the driving habit prediction model includes: a Transformer encoder, a loss function layer and an AdamW optimizer;
[0050] The Transformer encoder consists of a self-attention layer, a residual link layer, a normalization layer, and a fully connected layer;
[0051] The self-attention layer performs masking on the input training set containing position information of different granularities to obtain information about operations performed by the user's driving habits at a fixed time in the future;
[0052] Then, the information about the operations performed by the user's driving habits at a fixed time in the future is packaged and processed with a new dimension to obtain data samples without correlation;
[0053] A multi-head attention mechanism is used to extract deep features from unrelated data samples, obtaining deep features of the current user's driving habits and vehicle conditions in an adjusted dimension.
[0054] The residual link layer is used to perform weighted processing on the operations performed by the current user's driving habits, so that the model can comprehensively learn the relationship between the current operation and the future operation; if the dimensional matching relationship between the operations performed by the current user's driving habits and the vehicle driving characteristics does not meet the output requirements, a linear transformation is used to adjust the dimensional relationship between the operations performed by the current user's driving habits and the vehicle driving characteristics until the output requirements of the residual link layer are met;
[0055] The normalization layer normalizes each deep feature to improve model performance and optimize model prediction results;
[0056] The fully connected layer performs weighting and bias processing on the operations performed by the current user's driving habits and the deep features of the vehicle status to obtain the prediction results of the operations performed by the future user's driving habits;
[0057] The loss function layer calculates the error loss value between the prediction result and the true value through the MSELoss function, which is used to test the prediction accuracy of the driving habit prediction model;
[0058] The AdamW optimizer back-propagates the MSELoss loss value through AdamW and recalculates the MSELoss loss value until the MSELoss loss value is minimized and tends to be stable or reaches a preset number of training times, and then outputs the weight gradient of the driving habit prediction model.
[0059] Optionally, the expression of the mean square error loss value is:
[0060]
[0061] In the formula, is the mean square error loss value, is the sample size, For each data sample, Predict results for driving habits, The actual driving habits corresponding to the data labels.
[0062] Optionally, back propagation and parameter optimization are performed according to the square error loss value to obtain an updated driving habit prediction model, including:
[0063] The AdamW optimizer is used to back-propagate the mean square error loss value until the mean square error loss value is minimized and tends to be stable or reaches the preset number of training times, and then the weight gradient of the driving habit prediction model is output;
[0064] The model parameters of the driving habit prediction model are updated according to the weight gradient of the driving habit prediction model to obtain an updated driving habit prediction model.
[0065] A prediction device for driving habit prediction based on Transformer, comprising:
[0066] A data acquisition and processing module is used to acquire the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0067] A data screening module is used to slide a sliding window on the vehicle driving data sequence to extract data samples containing corresponding data labels;
[0068] The model training module is used to train the Transformer-based driving habit prediction model using data samples containing corresponding data labels. During the training process, back propagation and parameter optimization are performed using the mean square error loss function to obtain the trained driving habit prediction model;
[0069] The prediction module is used to input real-time vehicle driving data into the trained driving habit prediction model to perform real-time prediction of vehicle driving data and obtain driving habit prediction results.
[0070] Compared with the prior art, the present invention has the following beneficial effects:
[0071] The Transformer model is introduced into the field of vehicle driving to directly process time series, and its powerful sequence modeling ability and self-attention mechanism are used to accurately predict the driver's driving habits. This innovation breaks the limitations of traditional reliance on complex sensor networks and preset rules.
[0072] A prediction model based on real-time vehicle driving data is proposed. Key parameters such as accelerator pedal opening and brake pedal opening are collected in real time through CAN communication equipment, and deep learning technology is used for prediction, which enhances the timeliness and accuracy of the prediction.
[0073] Based on the Transformer model, a multi-head self-attention mechanism is introduced to intelligently filter and strengthen key information, improving the model's ability to recognize the driver's driving habits. At the same time, the residual connection is used to solve the gradient vanishing or gradient exploding problems in deep network training.
[0074] A dynamic learning rate adjustment strategy is adopted. When the gradient no longer decreases for multiple consecutive epochs during model training, the learning rate is automatically adjusted to optimize the model training process and improve the model's convergence speed and prediction accuracy.
[0075] In summary, the method of the present invention can accurately predict the driver's driving habits, and the automatic driving system or intelligent driving assistance system can respond in advance to avoid potential dangers, such as sudden braking, sudden acceleration, etc., thereby significantly improving driving safety. Predicting and adapting to the driver's personalized driving habits, such as acceleration, deceleration, turning, etc., makes the driving style of the automatic driving or intelligent driving assistance system closer to the driver's expectations, improving driving comfort and satisfaction. By predicting the driver's driving habits, the vehicle system can allocate power resources more reasonably, such as adjusting the motor target speed, target torque, etc., optimize the vehicle's power output and energy consumption performance, and improve the overall performance of the vehicle. BRIEF DESCRIPTION OF THE DRAWINGS
[0076] Figure 1 Shown is a flowchart of a Transformer-based driving habit prediction method;
[0077] Figure 2 The figure shows the implementation effect of the Transformer-based driving habit prediction method. DETAILED DESCRIPTION
[0078] The present invention will be further described below in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of the present invention.
[0079] Example 1
[0080] This embodiment provides a driving habit prediction method based on Transformer. Figure 1 Shown include:
[0081] Step 1: Obtain vehicle driving data in real time;
[0082] Step 2: Perform real-time prediction of vehicle driving data based on the pre-trained driving habit prediction model to obtain driving habit prediction results;
[0083] The training method of the driving habit prediction model includes:
[0084] Step A: Obtain the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0085] Step B: Use a sliding window to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels;
[0086] Step C: Divide the data samples into training set and test set;
[0087] Step D: Position encoding is performed on the training set and the test set to obtain training sets and test sets containing position information of different granularities;
[0088] Step E: Input the training set containing location information of different granularities into the Transformer-based driving habit prediction model to obtain the driving habit prediction results;
[0089] Step F: according to the data label of the driving habit prediction result, find out the real driving habit result corresponding to the data label;
[0090] Step G: Substitute the actual driving habit result and the predicted driving habit result into the mean square error loss function respectively to calculate the mean square error loss value;
[0091] Step H: Perform back propagation and parameter optimization according to the square error loss value to obtain an updated driving habit prediction model;
[0092] Step I: Use the test set to evaluate the updated driving habit prediction model to obtain the driving habit prediction model with the best performance;
[0093] Step J: Based on the driving habit prediction model with the best performance, real-time prediction of vehicle driving data is performed to obtain driving habit prediction results.
[0094] This embodiment uses CAN communication equipment to collect a large amount of vehicle driving data, and derives the accelerator pedal opening, brake pedal opening, motor target speed, motor target torque, battery maximum discharge power, and steering angle; and pre-processes the collected data to eliminate dimensional differences and improve model training efficiency; then uses sliding window technology to generate training samples, and generates future fixed step data as labels; finally, the data samples are divided into a training set and a test set in a ratio of 8:2.
[0095] Since the Transformer model itself does not contain a mechanism for directly processing the sequence order, the position of the sample is first encoded; the multi-head self-attention mechanism in the Transformer model intelligently selects the feature vector and focuses on the correlation between the elements in the input data. This mechanism processes features by weighting, significantly enhancing the importance of feature fragments that are closely related to the motor target torque, while applying low weights or ignoring non-related features, thereby accurately identifying and strengthening key information, thereby inputting driving data into the model for prediction and obtaining the target torque after a fixed step size in the future.
[0096] Optionally, the vehicle driving data includes: accelerator pedal opening, brake pedal opening, motor target speed, motor target torque, battery maximum discharge power and steering angle.
[0097] Optionally, in step A, preprocessing the driver's historical vehicle driving data to obtain a vehicle driving data sequence that eliminates dimensional differences between different parameters includes:
[0098] Interpolate and index the vehicle driving data respectively to obtain the vehicle driving data aligned with the time axis;
[0099] Normalizing the vehicle driving data aligned with the time axis to obtain the vehicle driving data with extreme values removed;
[0100] Selecting vehicle driving data with extreme values removed based on preset step length parameters to obtain vehicle driving data with a fixed step length;
[0101] According to the vehicle driving data with a fixed step length, data with different physical meanings are spliced to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0102] The expression of the interpolation index is:
[0103]
[0104] In the formula, mid is the time axis alignment data returned by the interpolation index, low is the starting point of the search range on the time axis, high is the end point of the search range on the time axis, key is the actual sampling point of the target to be searched, arr is a sorted array, arr[low] and arr[high] are the actual values of the array at low and high respectively;
[0105] The normalized expression is:
[0106]
[0107] In the formula To remove any data point in the vehicle driving data with extreme values, For each data point, is any data point in the vehicle driving data after interpolation search, is the minimum value of the vehicle driving data aligned with the time axis, It is the maximum value in the time-axis aligned vehicle driving data.
[0108] This embodiment uses interpolation search to pre-process the data, aiming to solve the problem that different ECUs in CAN communication have different times and periods for sending messages, so that the data time axis is aligned to a period of 10ms; the maximum and minimum value normalization method is used to process the accelerator pedal opening, brake pedal opening, motor target speed, motor target torque, battery maximum discharge power, and steering angle.
[0109] Optionally, in step B, a sliding window is used to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels, including:
[0110] A sliding window with a fixed step size is used to perform rolling sampling on the vehicle driving data sequence to obtain a set of multiple continuous data segments with a fixed size;
[0111] Concatenate a set of multiple continuous data segments of fixed size to obtain data labels;
[0112] Multiple continuous data segments of fixed size are concatenated with data labels to obtain data samples containing data labels;
[0113] Among them, the sliding window needs to be initialized before rolling sampling, and the sliding window size, sliding window step parameters and boundary conditions need to be set in advance;
[0114] The data samples are the current vehicle driving characteristics, and the data labels are the operations performed by the user's driving habits corresponding to a fixed time in the future.
[0115] In this embodiment, the step parameter Num_of_step is set. For example, if the step parameter Num_of_step is 100, the data representing different physical meanings, such as the accelerator pedal opening or the brake pedal opening, are each taken as a segment of 100 cycles, i.e., 1000ms. After sampling, the data is scrolled backward on the time axis by Window_Size values to obtain several instances.
[0116] During rolling sampling, please also note that since the window size is W and the total number of data points is N, the starting index i of the last window cannot exceed N−W+1 to ensure that the window is completely within the range of the real CAN message data.
[0117] The data after rolling sampling are spliced together in a way that the array height remains unchanged and the width is increased to obtain labels, that is, the last "Window_Size" data of a real vehicle condition and user operation data on the time axis are replaced with data after a certain period of time to achieve the prediction effect, specifically: the features and labels are spliced together in a way that the width remains unchanged and the height is increased to obtain a shape of (2, Num_of_step*type of actual input data), so that the instances and labels correspond to each other, so that the model corresponds to the user operation after a certain period of time according to the current vehicle condition and user operation; the above operation is performed on the entire data set to obtain several groups of samples, the specific number of groups is the total length of the data set-Num_of_step-Window_Size+1,
[00043] and the final data shape is (number of groups, 2, Num_of_step*type of actual input data).
[0118] Optionally, dividing the data samples into a training set and a test set in step C includes:
[0119] Randomly sort all data samples containing data labels to obtain re-sorted data samples;
[0120] The reordered data samples are divided into training set and test set in a ratio of 8:2.
[0121] In this embodiment, since CAN message communication is continuous, the samples after segmentation are still continuous, and the data set needs to be shuffled by index on the first dimension. Create an index list with the same length as the data set, and use a random number generator to shuffle the index list. Finally, rearrange the data set according to the shuffled index list; and on this basis, use a fixed ratio to divide the training set and the test set.
[0122] In this embodiment, since the vehicle conditions and user operations extracted from the CAN message have a strong temporal correlation, the order is very important. For example, the meanings of "first stepping on the brake pedal and then the accelerator pedal" and "first stepping on the accelerator pedal and then the brake pedal" are completely opposite. However, the Transformer model relies on the self-attention mechanism to process input data. The self-attention mechanism can focus on the information of all positions in the input sequence, and it does not itself contain any information about the order of elements. Therefore, in the absence of additional position information, the Transformer model cannot distinguish the order of elements in the input sequence, which is a major defect for processing language data with a natural order. Therefore, the data is positionally encoded here.
[0123] Optionally, in step D, position encoding is performed on the training set and the test set to obtain training sets and test sets containing position information of different granularities, including:
[0124] The position encoding matrix is used to perform position encoding on the training set and the test set to obtain the training set and the test set containing position information of different granularities.
[0125] Optionally, in step E, the training set containing location information of different granularities is input into the Transformer-based driving habit prediction model to obtain a driving habit prediction result, including:
[0126] Perform feature extraction on the training set containing location information of different granularities to obtain training set features and training set feature vectors;
[0127] Perform weighted processing on the feature vector of the training set to obtain a weighted feature vector;
[0128] Prediction is performed based on the weighted feature vector to obtain the driving habit prediction result.
[0129] Optionally, the driving habit prediction model includes: a Transformer encoder, a loss function layer, and an AdamW optimizer;
[0130] The Transformer encoder consists of a self-attention layer, a residual link layer, a normalization layer, and a fully connected layer;
[0131] Among them, the self-attention layer masks the input training set containing position information of different granularities to obtain information about the operations performed by the user's driving habits at a fixed time in the future;
[0132] Then, the information about the operations performed by the user's driving habits at a fixed time in the future is packaged and processed with a new dimension to obtain data samples without correlation;
[0133] A multi-head attention mechanism is used to extract deep features from unrelated data samples, obtaining deep features of the current user's driving habits and vehicle conditions in an adjusted dimension.
[0134] The residual link layer is used to perform weighted processing on the operations performed by the current user's driving habits, so that the model can comprehensively learn the relationship between the current operation and the future operation; if the dimensional matching relationship between the operations performed by the current user's driving habits and the vehicle's driving characteristics does not meet the output requirements, a linear transformation is used to adjust the dimensional relationship between the operations performed by the current user's driving habits and the vehicle's driving characteristics until the output requirements of the residual link layer are met;
[0135] The normalization layer normalizes each deep feature to improve model performance and optimize model prediction results;
[0136] The fully connected layer performs weighted and biased processing on the current user's driving habits and the deep features of the vehicle's condition to obtain the prediction results of the user's future driving habits.
[0137] The loss function layer calculates the error loss value between the prediction result and the true value through the MSELoss function, which is used to test the prediction accuracy of the driving habit prediction model;
[0138] The AdamW optimizer backpropagates the MSELoss loss value through AdamW and recalculates the MSELoss loss value until the MSELoss loss value is minimized and tends to be stable or reaches the preset number of training times, and then outputs the weight gradient of the driving habit prediction model.
[0139] In order to prevent the model from seeing the user's future operations in advance, this embodiment masks the data to hide part of the data that the model should not see during the training process, and then packages the masked data to obtain a sample set in which different samples are discontinuous in time, instances within the sample are continuous in time, and the labels are masked. The packaging method is to add a new dimension, that is, the size of a group of data is (batch_size, 2, Num_of_step*type of actual input data), that is, several user operations and vehicle conditions correspond to samples of user operations after a certain period of time, and there is no time correlation between each sample; the features and labels in the packaged data in the group are taken out one by one, and the size is modified to (Num_of_step*type of actual input data, batch_size), so as to adjust the shape of the data to adapt to the input requirements of the model.
[0140] By using a multi-head attention mechanism to filter the above input data, the vehicle condition, the relationship between current operations and future operations are extracted, and then undergo a residual link. The residual link is designed to solve the gradient vanishing or gradient exploding problems and network degradation problems that may occur during deep network training.
[0141] Optionally, the expression for the mean square error loss value is:
[0142]
[0143] In the formula, is the mean square error loss value, is the sample size, For each data sample, Predict results for driving habits, The actual driving habits corresponding to the data labels.
[0144] In this embodiment The square of the difference between the predicted value and the true value of each sample is calculated, and then these squared errors are summed and divided by the total number of samples N to obtain the mean squared error. This mean squared error is the value of MSELoss, which measures the overall accuracy of the model's predictions.
[0145] Optionally, in step H, back propagation and parameter optimization are performed according to the square error loss value to obtain an updated driving habit prediction model, including:
[0146] The AdamW optimizer is used to back-propagate the mean square error loss value until the mean square error loss value is minimized and tends to be stable or reaches the preset number of training times, and then the weight gradient of the driving habit prediction model is output;
[0147] The model parameters of the driving habit prediction model are updated according to the weight gradient of the driving habit prediction model to obtain an updated driving habit prediction model.
[0148] Example 2
[0149] This embodiment provides a prediction device for driving habit prediction based on Transformer, including:
[0150] A data acquisition and processing module is used to acquire the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters;
[0151] A data screening module is used to slide a sliding window on the vehicle driving data sequence to extract data samples containing corresponding data labels;
[0152] The model training module is used to train the Transformer-based driving habit prediction model using data samples containing corresponding data labels. During the training process, back propagation and parameter optimization are performed using the mean square error loss function to obtain the trained driving habit prediction model;
[0153] The prediction module is used to input real-time vehicle driving data into the trained driving habit prediction model to perform real-time prediction of vehicle driving data and obtain driving habit prediction results.
[0154] This invention introduces the Transformer model into the field of vehicle driving to directly process time series, and uses its powerful sequence modeling capabilities and self-attention mechanism to accurately predict the driver's driving habits. This innovation breaks the limitations of traditional reliance on complex sensor networks and preset rules.
[0155] A prediction model based on real-time vehicle driving data is proposed. Key parameters such as accelerator pedal opening and brake pedal opening are collected in real time through CAN communication equipment, and deep learning technology is used for prediction, which enhances the timeliness and accuracy of the prediction.
[0156] Based on the Transformer model, a multi-head self-attention mechanism is introduced to intelligently filter and strengthen key information, improving the model's ability to recognize the driver's driving habits. At the same time, the residual connection is used to solve the gradient vanishing or gradient exploding problems in deep network training.
[0157] A dynamic learning rate adjustment strategy is adopted. When the gradient no longer decreases for multiple consecutive epochs during model training, the learning rate is automatically adjusted to optimize the model training process and improve the model's convergence speed and prediction accuracy.
[0158] like Figure 2 As shown, the method of the present invention can accurately predict the driver's driving habits, and the automatic driving system or intelligent driving assistance system can respond in advance to avoid potential dangers, such as sudden braking, sudden acceleration, etc., thereby significantly improving driving safety. Predicting and adapting to the driver's personalized driving habits, such as acceleration, deceleration, turning, etc., makes the driving style of the automatic driving or intelligent driving assistance system closer to the driver's expectations, improving driving comfort and satisfaction. By predicting the driver's driving habits, the vehicle system can allocate power resources more reasonably, such as adjusting the motor target speed, target torque, etc., optimize the vehicle's power output and energy consumption performance, and improve the overall performance of the vehicle.
[0159] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0160] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0161] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0162] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0163] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the purpose of the present invention and the claims, which all fall within the protection of the present invention.
Claims
1. A driving habit prediction method based on Transformer, characterized in that: include: Obtain the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters; A sliding window is used to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels; The Transformer-based driving habit prediction model is trained using data samples containing corresponding data labels. During the training process, back propagation and parameter optimization are performed using the mean square error loss function to obtain the trained driving habit prediction model. The real-time vehicle driving data is input into the trained driving habit prediction model to perform real-time prediction of the vehicle driving data and obtain the driving habit prediction results.
2. The driving habit prediction method based on Transformer according to claim 1 is characterized in that: The vehicle driving data includes: accelerator pedal opening, brake pedal opening, motor target speed, motor target torque, battery maximum discharge power and steering angle.
3. The Transformer-based driving habit prediction method according to claim 1 is characterized in that: Preprocess the driver's historical vehicle driving data to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters, including: Interpolate and index the vehicle driving data respectively to obtain the vehicle driving data aligned with the time axis; Normalizing the vehicle driving data aligned with the time axis to obtain the vehicle driving data with extreme values removed; Selecting vehicle driving data with extreme values removed based on preset step length parameters to obtain vehicle driving data with a fixed step length; According to the vehicle driving data with a fixed step length, data with different physical meanings are spliced to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters; Wherein, the expression of the interpolation index is: ; In the formula, mid is the time axis alignment data returned by the interpolation index, low is the starting point of the search range on the time axis, high is the end point of the search range on the time axis, and key is the actual sampling point of the target to be searched. is a sorted array, arr[low] and arr[high] are the actual values of the array at low and high respectively; The normalized expression is: ; In the formula, To remove any data point in the vehicle driving data with extreme values, For each data point, is any data point in the vehicle driving data after interpolation search, is the minimum value of the vehicle driving data aligned with the time axis, It is the maximum value in the time-axis aligned vehicle driving data.
4. The Transformer-based driving habit prediction method according to claim 1 is characterized in that: A sliding window is used to slide on the vehicle driving data sequence to extract data samples containing corresponding data labels, including: A sliding window with a fixed step size is used to perform rolling sampling on the vehicle driving data sequence to obtain a set of multiple continuous data segments with a fixed size; Concatenate a set of multiple continuous data segments of fixed size to obtain data labels; Multiple continuous data segments of fixed size are concatenated with data labels to obtain data samples containing data labels; Among them, the sliding window needs to be initialized before rolling sampling, and the sliding window size, step parameters and boundary conditions of the sliding window need to be set in advance; The data sample is the current vehicle driving characteristics, and the data label is the operation performed by the user's driving habits corresponding to a fixed time in the future.
5. The Transformer-based driving habit prediction method according to claim 1 is characterized in that: The Transformer-based driving habit prediction model is trained using data samples containing corresponding data labels. The training process includes: Divide the data samples into training set and test set; Perform position encoding on the training set and the test set to obtain the training set and the test set containing position information of different granularities; Input the training set containing location information of different granularities into the Transformer-based driving habit prediction model to obtain the driving habit prediction results; According to the data labels of the driving habit prediction results, find out the real driving habit results corresponding to the data labels; Substitute the actual driving habit results and the predicted driving habit results into the mean square error loss function respectively, and calculate the mean square error loss value; Back propagation and parameter optimization are performed according to the square error loss value to obtain an updated driving habit prediction model; The updated driving habit prediction model is evaluated using the test set to obtain the driving habit prediction model with the best performance.
6. The Transformer-based driving habit prediction method according to claim 5 is characterized in that: The training set containing location information of different granularities is input into the Transformer-based driving habit prediction model to obtain the driving habit prediction results, including: Perform feature extraction on the training set containing location information of different granularities to obtain training set features and training set feature vectors; Perform weighted processing on the feature vector of the training set to obtain a weighted feature vector; Prediction is performed based on the weighted feature vector to obtain the driving habit prediction result.
7. The Transformer-based driving habit prediction method according to claim 1 is characterized in that: The driving habit prediction model includes: a Transformer encoder, a loss function layer and an AdamW optimizer; The Transformer encoder consists of a self-attention layer, a residual link layer, a normalization layer, and a fully connected layer; The self-attention layer performs masking on the input training set containing position information of different granularities to obtain information about operations performed by the user's driving habits at a fixed time in the future; Then, the information about the operations performed by the user's driving habits at a fixed time in the future is packaged and processed with a new dimension to obtain data samples without correlation; A multi-head attention mechanism is used to extract deep features from unrelated data samples, obtaining deep features of the current user's driving habits and vehicle conditions in an adjusted dimension. The residual link layer is used to perform weighted processing on the operations performed by the current user's driving habits, so that the model can comprehensively learn the relationship between the current operation and the future operation; The normalization layer normalizes each deep feature to improve model performance and optimize model prediction results; The fully connected layer performs weighting and bias processing on the operations performed by the current user's driving habits and the deep features of the vehicle status to obtain the prediction results of the operations performed by the future user's driving habits; The loss function layer calculates the error loss value between the prediction result and the true value through the MSELoss function, which is used to test the prediction accuracy of the driving habit prediction model; The AdamW optimizer back-propagates the MSELoss loss value through AdamW and recalculates the MSELoss loss value until the MSELoss loss value is minimized and tends to be stable or reaches a preset number of training times, and then outputs the weight gradient of the driving habit prediction model.
8. The Transformer-based driving habit prediction method according to claim 1 is characterized in that: The expression of the mean square error loss value is: ; In the formula, is the mean square error loss value, is the sample size, For each data sample, Predict results for driving habits, The actual driving habits corresponding to the data labels.
9. The Transformer-based driving habit prediction method according to claim 5 is characterized in that: Back propagation and parameter optimization are performed based on the square error loss value to obtain an updated driving habit prediction model, including: The AdamW optimizer is used to back-propagate the mean square error loss value until the mean square error loss value is minimized and tends to be stable or reaches the preset number of training times, and then the weight gradient of the driving habit prediction model is output; The model parameters of the driving habit prediction model are updated according to the weight gradient of the driving habit prediction model to obtain an updated driving habit prediction model.
10. A prediction device for driving habit prediction based on Transformer, characterized in that: include: A data acquisition and processing module is used to acquire the driver's historical vehicle driving data and perform preprocessing to obtain a vehicle driving data sequence that eliminates the dimensional differences between different parameters; A data screening module is used to slide a sliding window on the vehicle driving data sequence to extract data samples containing corresponding data labels; The model training module is used to train the Transformer-based driving habit prediction model using data samples containing corresponding data labels. During the training process, back propagation and parameter optimization are performed using the mean square error loss function to obtain the trained driving habit prediction model; The prediction module is used to input real-time vehicle driving data into the trained driving habit prediction model to perform real-time prediction of vehicle driving data and obtain driving habit prediction results.