CAN bus anomaly detection method and system based on dual attention mechanism
Through the CAN bus anomaly detection method based on the dual attention mechanism, vehicle data is collected and analyzed in real time, and the federated learning optimization model is used to solve the problems of lack of real-time alarms and data scarcity in the existing technology, and improve detection accuracy and safety.
Patent Information
- Application Number
- CN202410778055.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-17
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-06-17
AI Technical Summary
Existing fault analysis methods based on CAN bus are mainly post-event analysis, which lacks real-time abnormality detection alarms and cannot provide timely help to users while driving. In addition, vehicle CAN bus abnormality data is scarce, resulting in low detection accuracy.
The CAN bus anomaly detection method based on the dual attention mechanism is used to collect vehicle data in real time, use the anomaly detection model to perform inference analysis, generate alarm information, and use federated learning to optimize the model to achieve real-time anomaly detection and data set balancing.
It improves the accuracy of CAN bus anomaly detection, reduces dependence on abnormal data, provides real-time protection solutions, and enhances security in the Internet of Vehicles environment.
Smart Images

Figure CN118540207A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of CAN bus anomaly detection, and in particular to a CAN bus anomaly detection method and system based on a dual attention mechanism. Background Art
[0002] The automotive CAN bus is a serial communication protocol designed for internal vehicle communications. The CAN bus allows multiple microcontrollers and devices on the vehicle to communicate effectively without the need for complex point-to-point wiring harness connections, significantly reducing the number and complexity of wires. It improves system integration and reliability by enabling distributed control and real-time data sharing, and has become an important component of modern automotive electronic architecture. Using the CAN bus, various sensors, actuators, and control units can work together to more conveniently obtain data from various automotive components for anomaly detection and effective implementation of automotive safety management.
[0003] The existing fault analysis methods based on CAN bus are mainly post-analysis, and most of them are applied in vehicle maintenance scenarios. They lack real-time abnormality detection and warning, and cannot provide timely assistance to users while driving. Especially with the increasing popularity of intelligent driving vehicles, the risk of external attacks in the Internet of Vehicles environment has increased sharply, and a real-time protection solution with practical value is needed.
[0004] In a real vehicle driving environment, the abnormal data collected by the CAN bus only accounts for a small part of all the data. This results in a large amount of normal data constituting the training set, while the abnormal data is extremely scarce. Although there are currently methods for artificially injecting abnormal data sets, the application of this method in a real vehicle environment is subject to many restrictions. The artificially injected abnormal data sets have strong regularity and it is difficult to fully simulate the abnormal conditions in real scenarios. Therefore, in the current research on vehicle-mounted CAN bus anomaly detection, it is relatively difficult to obtain abnormal data, which reduces the accuracy of CAN bus anomaly detection. Summary of the invention
[0005] In view of the deficiencies in the prior art, the purpose of the present invention is to provide a CAN bus anomaly detection method and system based on a dual attention mechanism to solve the above technical problems.
[0006] The above technical objectives of the present invention are achieved through the following technical solutions:
[0007] A CAN bus anomaly detection method based on a dual attention mechanism comprises the following steps:
[0008] S1. Collect vehicle data from the vehicle's OBD interface in real time. The collected vehicle data includes engine operating parameters, vehicle speed, brake system status, and other important sensor readings;
[0009] S2. Car data is analyzed by anomaly detection model on the vehicle side. Thresholds are calculated based on normal operation data to identify potential anomalies or attack patterns. Once an anomaly is detected, identification information is generated immediately, the driver is warned directly, and abnormal data is sliced and encrypted for storage.
[0010] S3, optimizing the anomaly detection model using vehicle data, and uploading the optimized anomaly detection model to the cloud server;
[0011] S4. The cloud server receives optimized anomaly detection models from different vehicles, and integrates them using the federated learning method. The integrated anomaly detection model is regularly sent to the vehicle to complete the system update.
[0012] In a preferred example, the present invention can be further configured as follows: the vehicle-mounted data is subjected to reasoning analysis using an anomaly detection model on the vehicle side, and the uploaded data is analyzed using an unsupervised anomaly detection method based on a dual attention mechanism, specifically including:
[0013] S21, Patching and normalizing CAN bus normal data;
[0014] S22, through the two parallel branches of Patch-piece and In-Patch, and introduce a multi-head attention mechanism in each branch for feature modeling;
[0015] S23, restoring the representation outputs of different branches to the same dimension by adding upsampling;
[0016] S24, a loss function based on the maximum mean difference is used to measure the similarity of two representations;
[0017] S25: Output anomaly score and perform anomaly detection.
[0018] In a preferred example, the present invention can be further configured as follows: the specific method of step S21 is:
[0019] According to the reason that the sensor data of the CAN bus anomaly detection task has multiple input features under the synchronous timing, it is divided into a multivariate time series. The input features between different sensor data are firstly subjected to channel-independent patching operations, where each channel is the data of a single sensor, and each channel shares the same self-attention mechanism. The patching processing result is output to step S22;
[0020] In the CAN bus anomaly detection task, the input multivariate time series is:
[0021] χ∈R T×d
[0022] d is the number of sensors;
[0023] After extracting single sensor data, that is, single time series data, through the self-attention mechanism, each channel shares the self-attention network, and the characterization results are shown as follows:
[0024] χ i ′ ∈R N×1 ,i=(1,2,...,d)
[0025] Finally, the features are concatenated as the input of step S22.
[0026] In a preferred example, the present invention can be further configured as follows: the two parallel branches of step S22 are Patch-piece and In-Patch respectively;
[0027] Patch-piece focuses on the connection between sensors in different time slices. A single time slice is a unit, and the intrinsic relationship between time slices is modeled by a multi-head self-attention network.
[0028] The In-Patch branch focuses on the connection between sensors within a time slice and also uses a multi-head self-attention network for modeling;
[0029] Based on the joint representation of two different branches of Patch-piece and In-Patch, the sensor data in the CAN bus anomaly detection problem is represented from a dual perspective to the greatest extent, and the local semantic information of sensors from different perspectives is obtained to the maximum extent by using a shared weight approach.
[0030] In a preferred example, the present invention can be further configured as follows: the patch-piece focuses on the connection between sensors in different time segments, defines the size of different patches as P, and converts each patch into an embedding vector with an embedding dimension of d model , use multi-head attention weights to calculate the representation of different shards, initialize the query and key Q, K:
[0031] Q Ni ,K Ni =W Qi χ Ni ,W Ki χ Ni
[0032] Among them, 1≤i≤H, H is the number of heads of the multi-head attention mechanism;
[0033]
[0034] Q Ni ,K Nirepresents the dimension of query and key, and its learnable parameter matrix is expressed as follows:
[0035]
[0036] Then the attention weight can be expressed as formula:
[0037]
[0038] Finally, we concatenate the attention weights of different slices to get Attn N :
[0039]
[0040] in, is the learnable parameter matrix.
[0041] In a preferred example, the present invention can be further configured as follows: the In-Patch branch focuses on the connection between sensors within a time slice. First, the query and key Q, K are initialized:
[0042] Q Pi ,K Pi =W Qi χ Pi ,W Ki χ Pi
[0043] The dimensions of query and key are:
[0044]
[0045] The learnable parameter matrix dimension is defined as:
[0046]
[0047] The attention weight calculation formula is defined as:
[0048]
[0049] By concatenating the weights of different nodes, we can get Attn P :
[0050]
[0051] Patch-piece and In-Patch share weights, and their shared weights are W Qi ,W Ki .
[0052] In a preferred example, the present invention can be further configured as follows: the specific method of step S23 is:
[0053] For Patch-piece, repeatedly upsampling within the patch can obtain the final Patch-piece representation N;
[0054] For In-Patch, upsampling is repeatedly performed from a single sensor data to the sensor data within the complete patch, and finally the In-Patch representation P is obtained.
[0055] In a preferred example, the present invention can be further configured as follows: the specific method of step S24 is:
[0056] For the Patch-piece time slice representation N and the In-Patch sensor node representation P, the MMD loss function is defined as follows:
[0057] Γ P {P,N;χ}=∑MMD(P,Stopgrad(N))+MMD(Stopgrad(N),P)
[0058] Γ N {P,N;χ}=∑MMD(N,Stopgrad(P))+MMD(Stopgrad(P),N)
[0059] Among them, MMD is the maximum mean difference function, and the Stopgrad operation is used to prevent the gradient from propagating backward at a specific location to ensure that some parameters remain unchanged. Finally, the total loss Γ of this model is defined as follows:
[0060]
[0061] Measuring the similarity of two representations based on the maximum mean difference loss function reduces the distance between normal data and increases the distance between normal data and abnormal data.
[0062] A CAN bus anomaly detection system based on a dual attention mechanism, comprising the above-mentioned CAN bus anomaly detection method based on a dual attention mechanism, and also comprising a vehicle-side CAN signal acquisition module, a vehicle-mounted data terminal, a CAN signal processing module, a cloud module and a cloud management module;
[0063] The vehicle-side CAN signal acquisition module reads data from the vehicle's OBD interface in real time, and the collected data covers engine operating parameters, vehicle speed, brake system status, and readings of other important sensors;
[0064] The vehicle-mounted data terminal collects vehicle data collected by the vehicle-end CAN signal acquisition module, and the vehicle-mounted data terminal is connected to the vehicle-end CAN signal acquisition module;
[0065] The CAN signal processing module uses an unsupervised anomaly detection algorithm based on a dual attention mechanism to analyze the data sent by the vehicle data terminal, provide real-time protection for users, and optimize the model using the user's current driving data, and upload the optimized model to the cloud module. Both the vehicle data terminal and the cloud module are connected to the CAN signal processing module;
[0066] The cloud module is used to receive anomaly detection models from different vehicles, and fuse them using a federated learning method, and regularly send the fused anomaly detection model to the vehicle-side CAN signal processing module to complete system updates;
[0067] The cloud management module records abnormal and alarm information, provides alarm distribution function for management personnel, and provides data support and interface for remote management and operation and maintenance.
[0068] In summary, the present invention includes at least one of the following beneficial technical effects:
[0069] 1. The present invention proposes a CAN bus anomaly detection method based on a dual attention mechanism, which detects anomalies by utilizing the strong correlation between normal data representation and the difference between abnormal data representation under different perspectives. By learning the representation of a large amount of normal data, the model can effectively distinguish between normal and abnormal data, thereby achieving the goal of anomaly detection, reducing dependence on abnormal data, and improving the accuracy of CAN bus anomaly detection.
[0070] 2. Based on the joint representation of two different branches, Patch-piece and In-Patch, the present invention can perform dual-perspective representation of sensor data in the CAN bus anomaly detection problem to the greatest extent, and adopts a shared weight approach to maximize the acquisition of local semantic information of sensors from different perspectives; an upsampling data processing scheme is introduced to balance the data set in the field of CAN bus anomaly detection, solve the problem of unbalanced data sets, and expand the feature expression in the data, so that the model can learn data features more comprehensively.
[0071] 3. The present invention adopts the MMD maximum mean difference as the loss function measurement method of the model, realizing the core concept of the contrast characterization algorithm, that is, reducing the distance between normal data, increasing the distance between normal data and abnormal data, and improving the contrast effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0073] Figure 1 It is a flow chart of a CAN bus anomaly detection method based on a dual attention mechanism of the present invention;
[0074] Figure 2 is a flow chart of the unsupervised anomaly detection method of the dual attention mechanism in the present invention;
[0075] Figure 3 It is a model framework diagram of the unsupervised anomaly detection method of the dual attention mechanism in the present invention;
[0076] Figure 4 It is a schematic diagram of the Patching operation in the present invention;
[0077] Figure 5 Schematic diagram of dual-branch upsampling in the present invention;
[0078] Figure 6 It is a system diagram of a CAN bus anomaly detection system based on a dual attention mechanism of the present invention. DETAILED DESCRIPTION
[0079] The present invention is further described in detail below in conjunction with the accompanying drawings.
[0080] Embodiment 1:
[0081] Reference Figures 1 to 5 The present invention discloses a CAN bus anomaly detection method based on a dual attention mechanism, comprising the following steps:
[0082] S1. Collect vehicle data from the vehicle's OBD interface in real time. The collected vehicle data includes engine operating parameters, vehicle speed, brake system status, and other important sensor readings;
[0083] S2. Car data is analyzed by anomaly detection model on the vehicle side. Thresholds are calculated based on normal operation data to identify potential anomalies or attack patterns. Once an anomaly is detected, identification information is generated immediately, the driver is warned directly, and abnormal data is sliced and encrypted for storage.
[0084] S3, optimizing the anomaly detection model using vehicle data, and uploading the optimized anomaly detection model to the cloud server;
[0085] S4. The cloud server receives optimized anomaly detection models from different vehicles, and integrates them using the federated learning method. The integrated anomaly detection model is regularly sent to the vehicle to complete the system update.
[0086] Reference Figure 2 and Figure 3The vehicle-mounted data is analyzed by anomaly detection model on the vehicle side. The uploaded data is analyzed by an unsupervised anomaly detection method based on a dual attention mechanism, specifically including:
[0087] S21, Patching and normalizing CAN bus normal data;
[0088] S22, through the two parallel branches of Patch-piece and In-Patch, and introduce a multi-head attention mechanism in each branch for feature modeling;
[0089] S23, restoring the representation outputs of different branches to the same dimension by adding upsampling;
[0090] S24, a loss function based on the maximum mean difference is used to measure the similarity of two representations;
[0091] S25: Output anomaly score and perform anomaly detection.
[0092] Reference Figure 4 The specific method of step S21 is:
[0093] According to the reason that the sensor data of the CAN bus anomaly detection task has multiple input features under the synchronous timing, it is divided into a multivariate time series. The input features between different sensor data are firstly subjected to channel-independent patching operations, where each channel is the data of a single sensor, and each channel shares the same self-attention mechanism. The patching processing result is output to step S22;
[0094] In the CAN bus anomaly detection task, the input multivariate time series is:
[0095] χ∈R T×d
[0096] d is the number of sensors;
[0097] After extracting single sensor data, that is, single time series data, through the self-attention mechanism, each channel shares the self-attention network, and the characterization results are shown as follows:
[0098] χ i ′ ∈R N×1 ,i=(1,2,...,d)
[0099] Finally, the features are concatenated as the input of step S22.
[0100] The two parallel branches of step S22 are Patch-piece and In-Patch respectively;
[0101] Patch-piece focuses on the connection between sensors in different time slices. A single time slice is a unit, and the intrinsic relationship between time slices is modeled by a multi-head self-attention network.
[0102] The In-Patch branch focuses on the connection between sensors within a time slice and also uses a multi-head self-attention network for modeling;
[0103] Based on the joint representation of two different branches of Patch-piece and In-Patch, the sensor data in the CAN bus anomaly detection problem is represented from a dual perspective to the greatest extent, and the local semantic information of sensors from different perspectives is obtained to the maximum extent by using a shared weight approach.
[0104] At the same time, the output dimensions of the two branches are different. Considering the subsequent calculation of shared weights and to make up for this loophole in the design, this embodiment restores the representation outputs of different branches to the same dimension by adding upsampling.
[0105] The patch-piece focuses on the connection between sensors in different time segments, defines the size of different patches as P, and converts each patch into an embedding vector with an embedding dimension of d model , use multi-head attention weights to calculate the representation of different shards, initialize the query and key Q, K:
[0106] Q Ni ,K Ni =W Qi χ Ni ,W Ki χ Ni
[0107] Among them, 1≤i≤H, H is the number of heads of the multi-head attention mechanism;
[0108]
[0109] Q Ni ,K Ni represents the dimension of query and key, and its learnable parameter matrix is expressed as follows:
[0110]
[0111] Then the attention weight can be expressed as formula:
[0112]
[0113] Finally, we concatenate the attention weights of different slices to get Attn N :
[0114]
[0115] in, is the learnable parameter matrix.
[0116] The In-Patch branch focuses on the connection between sensors within a time slice. First, the query and key Q, K are initialized:
[0117] Q Pi ,K Pi =W Qi χ Pi ,W Ki χ Pi
[0118] The dimensions of query and key are:
[0119]
[0120] The learnable parameter matrix dimension is defined as:
[0121]
[0122] The attention weight calculation formula is defined as:
[0123]
[0124] By concatenating the weights of different nodes, we can get Attn P :
[0125]
[0126] Patch-piece and In-Patch share weights, and their shared weights are W Qi ,W Ki .
[0127] Reference Figure 5 , the specific method of step S23 is:
[0128] For Patch-piece, repeatedly upsampling within the patch can obtain the final Patch-piece representation N;
[0129] For In-Patch, upsampling is repeatedly performed from a single sensor data to the sensor data within the complete patch, and finally the In-Patch representation P is obtained.
[0130] This solution can balance the dataset in the field of CAN bus anomaly detection and solve the problem of unbalanced datasets. Secondly, it can expand the feature expression in the data so that the model can learn data features more comprehensively.
[0131] The contrastive representation learning model proposed in this embodiment represents the normal data of the CAN bus from two branches and different perspectives. In order to realize the core concept of the contrastive representation algorithm, that is, to reduce the distance between normal data and increase the distance between normal data and abnormal data, we use the MMD maximum mean difference as the loss function measurement method of the model.
[0132] We believe that in the process of bus sensor transmitting data, the characteristics of normal sensor data basically meet a fixed threshold, that is, its transmitted data will basically not change irregularly, and its data changes must follow the normal driving status of the vehicle. A sudden change in the data of a normal sensor will inevitably bring about changes in the data of other normal sensors, that is, its data changes can still be traced. The MMD loss function uses the principle of the average value of sample similarity to achieve this goal.
[0133] The specific method of step S24 is:
[0134] For the Patch-piece time slice representation N and the In-Patch sensor node representation P, the MMD loss function is defined as follows:
[0135] Γ P {P,N;χ}=∑MMD(P,Stopgrad(N))+MMD(Stopgrad(N),P)
[0136] Γ N {P,N;χ}=∑MMD(N,Stopgrad(P))+MMD(Stopgrad(P),N)
[0137] Among them, MMD is the maximum mean difference function, and the Stopgrad operation is used to prevent the gradient from propagating backward at a specific location to ensure that some parameters remain unchanged. Finally, the total loss Γ of this model is defined as follows:
[0138]
[0139] Measuring the similarity of two representations based on the maximum mean difference loss function reduces the distance between normal data and increases the distance between normal data and abnormal data.
[0140] This embodiment proposes a CAN bus anomaly detection method based on a dual attention mechanism, which detects anomalies by utilizing the strong correlation between normal data representations and the difference between abnormal data representations under different perspectives. By learning the representations of a large amount of normal data, the model can effectively distinguish between normal and abnormal data, thereby achieving the goal of anomaly detection, reducing dependence on abnormal data, and improving the accuracy of CAN bus anomaly detection.
[0141] Embodiment 2:
[0142] Reference Figure 6 , a CAN bus anomaly detection system based on a dual attention mechanism, including the CAN bus anomaly detection method based on a dual attention mechanism described in Example 1, and also including a vehicle-side CAN signal acquisition module, a vehicle-mounted data terminal, a CAN signal processing module, a cloud module and a cloud management module;
[0143] The vehicle-side CAN signal acquisition module reads data from the vehicle's OBD interface in real time, and the collected data covers engine operating parameters, vehicle speed, brake system status, and readings of other important sensors;
[0144] The vehicle-mounted data terminal collects vehicle data collected by the vehicle-end CAN signal acquisition module, and the vehicle-mounted data terminal is connected to the vehicle-end CAN signal acquisition module;
[0145] The CAN signal processing module uses an unsupervised anomaly detection algorithm based on a dual attention mechanism to analyze the data sent by the vehicle data terminal, provide real-time protection for users, and optimize the model using the user's current driving data, and upload the optimized model to the cloud module. Both the vehicle data terminal and the cloud module are connected to the CAN signal processing module;
[0146] The cloud module is used to receive anomaly detection models from different vehicles, and fuse them using a federated learning method, and regularly send the fused anomaly detection model to the vehicle-side CAN signal processing module to complete system updates;
[0147] The cloud management module records abnormal and alarm information, provides alarm distribution function for management personnel, and provides data support and interface for remote management and operation and maintenance.
[0148] The implementation principle of the above embodiment is:
[0149] S1. Collect vehicle data from the vehicle's OBD interface in real time. The collected vehicle data includes engine operating parameters, vehicle speed, brake system status, and other important sensor readings;
[0150] S2. Car data is analyzed by anomaly detection model on the vehicle side. Thresholds are calculated based on normal operation data to identify potential anomalies or attack patterns. Once an anomaly is detected, identification information is generated immediately, the driver is warned directly, and abnormal data is sliced and encrypted for storage.
[0151] S3, optimizing the anomaly detection model using vehicle data, and uploading the optimized anomaly detection model to the cloud server;
[0152] S4. The cloud server receives optimized anomaly detection models from different vehicles, and integrates them using the federated learning method. The integrated anomaly detection model is regularly sent to the vehicle to complete the system update.
[0153] The embodiments of this specific implementation method are all preferred embodiments of the present invention, and are not intended to limit the protection scope of the present invention. Therefore, all equivalent changes made based on the structure, shape, and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A CAN bus anomaly detection method based on a dual attention mechanism, characterized in that: The following steps are involved: S1. Collect vehicle data from the vehicle's OBD interface in real time. The collected vehicle data includes engine operating parameters, vehicle speed, brake system status, and other important sensor readings; S2. Car data is analyzed by anomaly detection model on the vehicle side. Thresholds are calculated based on normal operation data to identify potential anomalies or attack patterns. Once an anomaly is detected, identification information is generated immediately, the driver is warned directly, and abnormal data is sliced and encrypted for storage. S3, optimizing the anomaly detection model using vehicle data, and uploading the optimized anomaly detection model to the cloud server; S4. The cloud server receives optimized anomaly detection models from different vehicles, and integrates them using the federated learning method. The integrated anomaly detection model is regularly sent to the vehicle to complete the system update.
2. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 1 is characterized in that: The vehicle-mounted data is analyzed by using an anomaly detection model on the vehicle side. The uploaded data is analyzed by an unsupervised anomaly detection method based on a dual attention mechanism, specifically including: S21, Patching and normalizing CAN bus normal data; S22, through the two parallel branches of Patch-piece and In-Patch, and introduce a multi-head attention mechanism in each branch for feature modeling; S23, restoring the representation outputs of different branches to the same dimension by adding upsampling; S24, a loss function based on the maximum mean difference is used to measure the similarity of two representations; S25: Output anomaly score and perform anomaly detection.
3. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 2 is characterized in that: The specific method of step S21 is: According to the reason that the sensor data of the CAN bus anomaly detection task has multiple input features under the synchronous timing, it is divided into a multivariate time series. The input features between different sensor data are firstly subjected to channel-independent patching operations, where each channel is the data of a single sensor, and each channel shares the same self-attention mechanism. The patching processing result is output to step S22; In the CAN bus anomaly detection task, the input multivariate time series is: χ∈R T×d d is the number of sensors; After extracting single sensor data, that is, single time series data, through the self-attention mechanism, each channel shares the self-attention network, and the characterization results are shown as follows: x i ′ ∈R N×1 ,i=(1,2,...,d) Finally, the features are concatenated as the input of step S22.
4. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 3 is characterized in that: The two parallel branches of step S22 are Patch-piece and In-Patch respectively; Patch-piece focuses on the connection between sensors in different time slices. A single time slice is a unit, and the intrinsic relationship between time slices is modeled by a multi-head self-attention network. The In-Patch branch focuses on the connection between sensors within a time slice and also uses a multi-head self-attention network for modeling; Based on the joint representation of two different branches of Patch-piece and In-Patch, the sensor data in the CAN bus anomaly detection problem is represented from a dual perspective to the greatest extent, and the local semantic information of sensors from different perspectives is obtained to the maximum extent by using a shared weight approach.
5. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 4 is characterized in that: The patch-piece focuses on the connection between sensors in different time segments, defines the size of different patches as P, and converts each patch into an embedding vector with an embedding dimension of d model , use multi-head attention weights to calculate the representation of different shards, initialize the query and key Q, K: Q Ni ,K Ni =W Qi x Ni ,W Ki x Ni Among them, 1≤i≤H, H is the number of heads of the multi-head attention mechanism; Q Ni ,K Ni represents the dimension of query and key, and its learnable parameter matrix is expressed as follows: Then the attention weight can be expressed as formula: Finally, we concatenate the attention weights of different slices to get Attn N : in, is the learnable parameter matrix.
6. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 5 is characterized in that: The In-Patch branch focuses on the connections between sensors within a time slice. First, the query and key Q, K are initialized: Q Pi ,K Pi =W Qi x Pi ,W Ki x Pi The dimensions of query and key are: The learnable parameter matrix dimension is defined as: The attention weight calculation formula is defined as: By concatenating the weights of different nodes, we can get Attn P : Patch-piece and In-Patch share weights, and their shared weights are W Qi ,W Ki .
7. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 6 is characterized in that: The specific method of step S23 is: For Patch-piece, repeatedly upsampling within the patch can obtain the final Patch-piece representation N; For In-Patch, upsampling is repeatedly performed from a single sensor data to the sensor data within the complete patch, and finally the In-Patch representation P is obtained.
8. The CAN bus anomaly detection method based on the dual attention mechanism according to claim 7 is characterized in that: The specific method of step S24 is: For the Patch-piece time slice representation N and the In-Patch sensor node representation P, the MMD loss function is defined as follows: C P {P,N;x}=∑MMD(P,Stopgrad(N))+MMD(Stopgrad(N),P) C N {P,N;x}=∑MMD(N,Stopgrad(P))+MMD(Stopgrad(P),N) Among them, MMD is the maximum mean difference function, and the Stopgrad operation is used to prevent the gradient from propagating backward at a specific location to ensure that some parameters remain unchanged. Finally, the total loss Γ of this model is defined as follows: Measuring the similarity of two representations based on the maximum mean difference loss function reduces the distance between normal data and increases the distance between normal data and abnormal data.
9. A CAN bus anomaly detection system based on a dual attention mechanism, comprising the CAN bus anomaly detection method based on a dual attention mechanism according to any one of claims 1 to 8, characterized in that: It includes vehicle-side CAN signal acquisition module, vehicle-mounted data terminal, CAN signal processing module, cloud module and cloud management module; The vehicle-side CAN signal acquisition module reads data from the vehicle's OBD interface in real time, and the collected data covers engine operating parameters, vehicle speed, brake system status, and readings of other important sensors; The vehicle-mounted data terminal collects vehicle data collected by the vehicle-end CAN signal acquisition module, and the vehicle-mounted data terminal is connected to the vehicle-end CAN signal acquisition module; The CAN signal processing module uses an unsupervised anomaly detection algorithm based on a dual attention mechanism to analyze the data sent by the vehicle data terminal, provide real-time protection for users, and optimize the model using the user's current driving data, and upload the optimized model to the cloud module. Both the vehicle data terminal and the cloud module are connected to the CAN signal processing module; The cloud module is used to receive anomaly detection models from different vehicles, and fuse them using a federated learning method, and regularly send the fused anomaly detection model to the vehicle-side CAN signal processing module to complete system updates; The cloud management module records abnormal and alarm information, provides alarm distribution function for management personnel, and provides data support and interface for remote management and operation and maintenance.
Citation Information
Patent Citations
Vehicle-mounted CAN bus data anomaly detection and identification method
CN113992533A
Multi-site medical data analysis method and system based on federal learning
CN115310130A
Well drilling abnormal working condition diagnosis method and system based on two-stage learning
CN117386344A
Long-time sequence prediction method based on time domain decoupling enhancement
CN117972387A
Internet of Things time series data anomaly detection method and system based on dynamic graph attention
CN118094427A
Cited By
Can bus anomaly detection method and system based on dual attention mechanism
WO2025260995A1
