A vehicle-mounted CAN bus intrusion detection system and method
Through an improved compression network model, depthwise separable convolution and channel attention mechanism, combined with category-balanced focal loss and dynamic learning rate scheduling, the model complexity and real-time problems in vehicle-mounted CAN bus intrusion detection are solved, efficient, stable and lightweight detection is achieved, and the ability to identify rare attacks is improved.
Patent Information
- Application Number
- CN202510925943.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-07
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2045-07-07
AI Technical Summary
Existing technologies for vehicle-mounted CAN bus intrusion detection have complex models and high computational overhead, making it difficult to meet real-time and lightweight requirements, and it is difficult to effectively identify rare attack types.
A lightweight vehicle-mounted CAN bus intrusion detection system is designed by adopting an improved compression network model combined with depthwise separable convolution and channel attention mechanism. Real-time detection is performed through feature extraction and classification output layer, and the model is optimized using category-balanced focal loss and dynamic learning rate scheduling strategy.
It achieves efficient and stable real-time intrusion detection in resource-constrained vehicle environments, with a detection accuracy of 100% and an average batch processing delay of less than 1.9ms, significantly reducing system resource consumption and computational complexity, and improving the ability to identify rare attacks.
Smart Images

Figure CN120434051B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of information security, and more particularly to a vehicle-mounted CAN bus intrusion detection system and method. Background Art
[0002] With the rapid development of smart cars, the number of electronic components integrated into in-vehicle systems has increased significantly to support intelligent features such as autonomous driving and active safety. As the primary communication method between in-vehicle electronic control units (ECUs), the security of the In-Vehicle Network (IVN) has become a core component in ensuring the stable operation of the entire vehicle. Currently, the Controller Area Network (CAN), as the mainstream IVN communication protocol, is widely used in powertrain systems, chassis control systems, and infotainment systems due to its high efficiency, real-time performance, and low cost. However, information security was not fully considered when the CAN bus was initially designed. Its communication mechanism uses an open broadcast mode and lacks authentication mechanisms and data encryption capabilities, making vehicles extremely vulnerable to attacks when exposed to external network environments.
[0003] In recent years, with the growing adoption and implementation of the Internet of Vehicles (IoV), communication between vehicles and the cloud, infrastructure, and other vehicles has become increasingly frequent, significantly expanding the attack surface of these systems. Attackers can intrude into CAN networks through physical interfaces or wireless channels, launching attacks such as denial of service, spoofing, or fuzz testing. These attacks can disrupt normal vehicle communication processes and even cause loss of control signals or malfunctions. These potential threats should not be ignored.
[0004] To address security threats facing CAN networks, intrusion detection systems (IDS) have become a key technology for ensuring in-vehicle communication security. While traditional IDSs offer some security protection through feature matching and rule-based configuration, they lack adaptability and real-time performance, making them incapable of handling complex and dynamic attack scenarios. With the rapid development of deep learning technology, deep learning-based IDSs have become an effective solution. However, existing deep learning models often exhibit high computational complexity and a large number of parameters, making them difficult to run in real time on resource-constrained in-vehicle terminals or edge computing devices.
[0005] Li Yang et al. proposed a vehicle-to-vehicle intrusion detection model that combines transfer learning with optimized convolutional neural networks (CNNs) (L. Yang and A. Shami, "A Transfer Learning and Optimized CNN-Based Intrusion Detection System for Internet of Vehicles," ICC 2022 IEEE International Conference on Communications, Seoul, Korea, Republic of, 2022, pp. 2774–2779). This model, based on typical CNN architectures such as VGG16, VGG19, Xception, Inception, and InceptionResNet, constructs multiple base classifiers and optimizes them using transfer learning and particle swarm optimization (PSO). Furthermore, they employ two ensemble learning strategies, confidence averaging and feature concatenation, to fuse these multiple models to improve the accuracy and stability of intrusion detection. However, the model's complex structure and large parameter size make it difficult to deploy directly on resource-constrained in-vehicle devices (such as ECUs). Furthermore, it still struggles to meet the combined requirements of real-time performance and lightweightness.
[0006] Abdul Rehman Javed et al. proposed a vehicle-mounted intrusion detection system called CANintelliIDS (AR Javed, S. u. Rehman, MU Khan, M. Alazab, and TR G, "CANintelliIDS: Detecting In-Vehicle Intrusion Attacks on a Controller Area Network Using CNN and Attention-Based GRU," IEEE Transactions on Network Science and Engineering, vol. 8, no. 2, pp. 1456–1466, Apr.–Jun. 2021). This system combines a convolutional neural network (CNN) with an attention-guided gated recurrent unit (Attention-GRU). The CNN extracts spatial features, the Attention-GRU captures temporal information, and an attention mechanism is introduced to weight important time steps, enabling the identification of multiple types of attacks. While achieving high detection accuracy on the OTIDS dataset, the system's complex model structure, involving multiple layers of convolution and attention mechanisms, is computationally intensive.
[0007] In summary, existing technologies for CAN bus intrusion detection generally suffer from complex models, high computational overhead, and difficulty meeting the real-time and lightweight requirements of in-vehicle environments. Therefore, there is an urgent need for an efficient and lightweight CAN bus intrusion detection method that can ensure detection accuracy while meeting the stringent requirements of in-vehicle environments for real-time response and low computational overhead. Summary of the Invention
[0008] In order to overcome at least one technical problem existing in the above prior art, the present invention provides a vehicle-mounted CAN bus intrusion detection system and method.
[0009] In order to solve the above technical problems, the technical solutions of the present invention are as follows:
[0010] A vehicle-mounted CAN bus intrusion detection system, the intrusion detection system is obtained based on the training of an improved compression network model, the improved compression network model includes a convolution layer, a pooling layer, multiple dynamic feature extraction modules, a convolutional mapping layer, a global average pooling layer and a classification output layer;
[0011] Each of the dynamic feature extraction modules includes a compression layer and two expansion branches. The compression layer uses 1×1 depth-wise separable convolution for feature compression, and the two expansion branches use 1×1 depth-wise separable convolution and 3×3 depth-wise separable convolution respectively. All convolution operations are connected to batch normalization and rectified linear unit activation functions. The output of the expansion branch is subjected to channel feature fusion through the feature splicing layer and connected to an efficient channel attention module to optimize the channel feature distribution; the classification output layer is used to output the final classification probability distribution as the logit prediction result of the network.
[0012] Furthermore, the improved compression network model includes a convolution layer, a first pooling layer, a second dynamic feature extraction module, a third dynamic feature extraction module, a fourth dynamic feature extraction module, a second pooling layer, a fifth dynamic feature extraction module, a sixth dynamic feature extraction module, a seventh dynamic feature extraction module, an eighth dynamic feature extraction module, a third pooling layer, a ninth dynamic feature extraction module, a convolutional mapping layer, a global average pooling layer and a classification output layer, which are arranged in sequence.
[0013] Furthermore, the number of squeeze and expand output channels increases with the network depth, and the outputs are merged through feature splicing operations. After splicing, the ECA channel attention mechanism is connected to enhance the channel expression ability.
[0014] Furthermore, the convolution layer is a 7×7 standard convolution with a stride of 2, 3 input channels, and 96 output channels, and the convolution operation is followed by a rectified linear unit activation function;
[0015] The convolution mapping layer is a 1×1 convolution, which is used to map the number of output channels of the ninth dynamic feature extraction module to the number of target categories. The convolution operation is preceded by a random dropout layer with a dropout rate of 0.5, and followed by a rectified linear unit activation function.
[0016] Furthermore, the first pooling layer is a maximum pooling operation with a pooling kernel size of 3×3, a stride of 2, and a rounding-up mode;
[0017] The second pooling layer and the third pooling layer are respectively arranged after the fourth dynamic feature extraction module and the eighth dynamic feature extraction module, and both are maximum pooling operations with a pooling kernel size of 3×3 and a step size of 2, for staged downsampling;
[0018] The global average pooling layer is an adaptive average pooling operation with an output size of 1×1, which is used to compress the spatial dimension.
[0019] Furthermore, the step of training the improved compression network model includes:
[0020] S1. Obtain a public dataset, clean and preprocess the data, and convert it into labeled color images after normalization.
[0021] S2. Input the image obtained after S1 processing into the improved compression network model for training. During the training process, the class-balanced focal loss is used as the loss function, the loss weight is dynamically adjusted based on the number of class samples, and a focal modulation term is introduced; the learning rate is optimized through the validation set, and the final model weight is obtained after the training is completed;
[0022] S3: Perform inference verification on the model trained in S2 to evaluate the recognition accuracy, detection latency, and parameter size of the model on the test set.
[0023] Furthermore, the step S1 includes:
[0024] S11. Obtain a public dataset for vehicle intrusion detection;
[0025] S12. Perform field cleaning and format conversion on the original data, including extracting key fields, filling missing values, converting hexadecimal fields to decimal, and adding label columns;
[0026] S13, normalizing the distribution of the extracted field data, and mapping the normalized value to the interval [0, 255];
[0027] S14. Convert the normalized data into a three-channel image by field grouping, where the three channels correspond to fields of different categories, for input to the improved compression network model.
[0028] Furthermore, the step S14 includes:
[0029] The processed CAN message data is divided into groups of 27. Nine fields are selected from each message, including the identifier and data byte 0 to data byte 7, and divided into three channels according to the field function.
[0030] Among them, the identifier, data byte 0 and data byte 1 are mapped to the red channel, data byte 2, data byte 3 and data byte 4 are mapped to the green channel, and data byte 5, data byte 6 and data byte 7 are mapped to the blue channel;
[0031] Each channel field is reconstructed into a 9×9 two-dimensional matrix, and then combined in the channel dimension to form a 9×9×3 color image. The color image is adjusted to a uniform size of 224×224 through interpolation method, and finally saved as a PNG format image file, stored by label classification, and used as input samples of the improved compression network model.
[0032] Further, the step S2 includes:
[0033] S21, divide the data set obtained in S1 into training set, validation set and test set in a ratio of 7:2:1;
[0034] S22. Before model training, normalize and standardize the image data in the training set, validation set, and test set;
[0035] S23. Input the training set data into the constructed improved compression network model for training. The optimizer uses the adaptive moment estimation optimizer, the loss function is the class-balanced focal loss, the number of training rounds is set to 20, the initial learning rate is set to 0.0001, and the batch size is set to 32. During the training process, a dynamic learning rate decay strategy is introduced to dynamically adjust the learning rate to accelerate convergence.
[0036] S24. Use 5-fold cross-validation to test the learning rate and batch size combination. Use the validation set to evaluate the model performance changes after each round of training. Select the optimal hyperparameter configuration based on the average accuracy and loss index of the validation set and save the model weights with the best performance to the specified path.
[0037] Furthermore, in step S2, the loss function is expressed as:
[0038] ,
[0039] in, is the balance factor and , Representation category The number of samples, is the cross entropy loss, is the model’s predicted probability for the correct category, is the focal modulation coefficient, is the feature vector of the input sample, is the true category label of the sample.
[0040] Furthermore, the adjustment rule of ReduceLROnPlateau learning rate scheduling strategy is:
[0041] ,
[0042] in, is the current learning rate, is the learning rate reduction factor (such as 0.1), is the number of tolerance rounds, that is, when the verification loss is continuous When the round is not decreased, the current learning rate will be multiplied by the factor.
[0043] A vehicle-mounted CAN bus intrusion detection method, the intrusion detection method comprising the following steps:
[0044] Receive CAN bus data stream in real time and extract message field information;
[0045] Perform field selection and sample construction on the received CAN data. Select the identifier and data byte 0 to data byte 7, a total of 9 fields, construct a sample for every 27 messages, and map it into a three-channel color image.
[0046] Inputting the converted color image into a vehicle-mounted CAN bus intrusion detection system, wherein the vehicle-mounted CAN bus intrusion detection system adopts the aforementioned vehicle-mounted CAN bus intrusion detection system;
[0047] Use the trained model to perform inference and classification on the real-time received CAN traffic data and output the corresponding classification labels;
[0048] Based on the classification label results, determine whether there is CAN bus intrusion behavior.
[0049] Compared with the prior art, the beneficial effects of the technical solution of the present invention are:
[0050] The present invention provides a vehicle-mounted CAN bus intrusion detection system and method, the beneficial effects of which include at least:
[0051] First, this invention achieved 100% detection accuracy when detecting five typical CAN bus attack types (including DoS, Fuzzy, Gear, RPM, and normal traffic), with an average batch inference latency of approximately 1.9ms per frame and a model parameter size of only 0.25MB, significantly reducing system resource consumption and computational complexity. This design not only significantly reduces resource consumption and computational burden, but also enables efficient and stable real-time intrusion detection on computing-constrained in-vehicle ECUs.
[0052] 2. This paper introduces depthwise separable convolution (DSConv) into the dynamic feature extraction module in the SqueezeNet backbone, decomposing the standard 3×3 convolution into a combination of channel-by-channel convolution and 1×1 convolution, significantly reducing the amount of computation and parameters while maintaining the spatial feature extraction capability. At the same time, an efficient channel attention mechanism (ECA) is introduced after the output of the dynamic feature extraction module, relying only on local inter-channel convolution to enhance attention, further improving the model's ability to perceive attack features and enhancing detection accuracy without significantly increasing the computational burden.
[0053] 3. In the data preprocessing and conversion stage, the present invention designs a multi-channel mapping method based on the characteristics of CAN bus data, converts different message fields into multi-dimensional feature inputs, and enhances the model's perception of complex abnormal features. Compared with the traditional simple splicing or single-channel mapping method, this method better preserves the correlation and feature differences between fields in the data structure, and improves the integrity of the input feature expression. In order to ensure the stability of the data conversion process and the effect of model training, the present invention further normalizes and standardizes the converted data, suppresses the influence of outliers, and ensures the balance of input data and the stable convergence of the training process.
[0054] 4. During the training process, the present invention adopts a class-balanced focal loss, which dynamically adjusts the loss weight based on the statistical information of the class samples, effectively dealing with the class imbalance problem caused by the rarity of attack types in the vehicle CAN bus traffic. In actual scenarios, since network traffic data is usually highly unbalanced data and only contains a small number of attack samples, if the traditional cross-entropy loss is used, the model tends to be biased towards the majority class, resulting in insufficient detection capabilities for rare attacks. After adopting the class-balanced focal loss, by amplifying the gradient of minority class samples and reducing the weight of majority class samples, the model performs more prominently in discriminating minority attack categories, significantly improving the detection accuracy and overall robustness of weak signal anomalies.
[0055] During the model training phase, this paper employs a learning rate scheduling strategy (ReduceLROnPlateau) based on performance stagnation. This strategy automatically reduces the learning rate when validation set performance stagnates, further improving training stability and final convergence. Furthermore, 5-fold cross-validation is used to evaluate the model's training performance, ensuring that the final model maintains high detection accuracy and good generalization across different dataset partitions.
[0056] 6. Model performance evaluation results show that the proposed SEDSNet (SqueezeNet-ECA-DSConv) lightweight model achieved 100% accuracy, precision, recall, and F1 score, demonstrating excellent detection results. This model effectively distinguishes between normal and abnormal traffic and has great potential and practical significance in vehicle network security testing tasks, helping to promptly detect potential abnormal communications and enhance the security protection capabilities of in-vehicle network systems. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 paying any creative work.
[0058] Figure 1 This is a flow chart of a vehicle-mounted CAN bus intrusion detection method provided in one embodiment of the present application;
[0059] Figure 2 This is an architecture diagram of the SEDSNet (SqueezeNet-ECA-DSConv) model provided in one embodiment of the present application;
[0060] Figure 3 This is a sample image diagram, showing the image representation of normal samples and samples of different attack types (normal traffic, DoS, fuzzy, gear spoofing, speed spoofing);
[0061] Figure 4 The confusion matrix diagram of the binary classification task (normal and abnormal) is shown, reflecting the classification results and confusion distribution of the model when distinguishing "normal" and "abnormal" samples;
[0062] Figure 5 The confusion matrix diagram of the multi-classification task (each attack category) is displayed, reflecting the classification results and confusion distribution of the model when distinguishing multiple different attack categories. DETAILED DESCRIPTION
[0063] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein.
[0064] In this application, the SqueezeNet model is a compression network model, the squeeze layer is a compression layer, the expand branch is an expansion branch, the ReLU activation function is a rectified linear unit activation function, the ECA channel attention module is an efficient channel attention module, the SoftMax layer is a classification output layer, the Dropout layer is a random dropout layer, the ceil mode is a rounding-up mode, the Class-Balanced Focal Loss is a class-balanced focal loss, the Car-Hacking dataset is a public dataset for vehicle intrusion detection, Adam is an adaptive moment estimation optimizer, the ReduceLROnPlateau strategy is a dynamic learning rate decay strategy (also known as a performance-stagnation-based learning rate scheduling strategy), ID is an identifier, Data[0]-Data[7] is data byte 0 to data byte 7, the Fire module is a dynamic feature extraction module, Maxpool is maximum pooling, adaptiveAvgpool is adaptive average pooling, and Improved Fire2 to Improved Fire9 are the second dynamic feature extraction module to the ninth dynamic feature extraction module.
[0065] This invention aims to overcome the shortcomings of existing vehicle-to-vehicle (V2X) CAN bus intrusion detection methods, including redundant model structures, low computational efficiency, and poor ability to identify unbalanced attack samples. Existing detection methods often rely on complex deep network structures, which struggle to balance feature expression capabilities with the lightweight and real-time requirements of onboard equipment. Furthermore, the uneven distribution of attack samples can cause the model to favor the primary class during training, compromising overall detection robustness.
[0066] To this end, this paper proposes an in-vehicle CAN bus intrusion detection method based on an improved SqueezeNet network. By constructing an RGB image input method corresponding to field semantics, this method achieves a visual representation of CAN message structure information. Building on the original SqueezeNet architecture, this method improves on its lightweight and feature modeling capabilities. By introducing depthwise separable convolutions to replace standard convolutions in the expansion layer, the model reduces the number of model parameters and computational complexity. Furthermore, a channel attention mechanism (ECA) is embedded after each dynamic feature extraction module output to enhance the model's responsiveness to changes in key fields. Furthermore, the model is trained and optimized using a class-balanced focal loss function, guiding the model's recognition accuracy for minority attack samples. Experimental results demonstrate that this method achieves high detection accuracy and low inference time for multiple CAN attack types, exhibiting excellent lightweight deployment performance and suitability for practical scenarios involving resource-constrained in-vehicle control units.
[0067] Figure 1 This is the overall framework diagram of the method of this embodiment, showing the process from CAN traffic reception, data preprocessing to model training and inference prediction. Figure 1 In
[15] , Class-Balanced Focal Loss is the category-balanced focal loss.
[0068] Figure 2 The improved overall architecture diagram is based on the modularized Fire unit, which uses deep separable convolution decomposition (DWConv+PWConv), dual-path feature expansion (1×1 and 3×3 in parallel), feature concatenation (Contact) and ECA channel attention mechanism to achieve high-precision, low-complexity feature extraction, meeting the dual requirements of real-time and lightweight for vehicle-mounted CAN bus intrusion detection. Figure 2 In the figure, ConV is the convolution layer; Maxpool is the maximum pooling; Improved Fire2 to Improved Fire9 are the second dynamic feature extraction module to the ninth dynamic feature extraction module; PWConV is the point-by-point convolution; DWConV is the depth-wise convolution; Squeeze layer is the compression layer; Expand layer is the expansion layer; Contact is the feature splicing layer; ECA module is the efficient channel attention module.
[0069] Figure 3 The figure is a sample image diagram, showing the image representation of normal samples and samples of different attack types (normal traffic, DoS, fuzzy, gear deception, speed deception). Figure 3 In the Internet, Dos attack is a denial of service attack.
[0070] Figure 4 The confusion matrix diagram of the binary classification task (normal and abnormal) reflects the classification results and confusion distribution of the model when distinguishing "normal" and "abnormal" samples. Figure 4 In the Validation Binary Confusion Matrix, the validation binary confusion matrix is also called the ValidationBinary Confusion Matrix; Normal is normal traffic; Attack is abnormal traffic (attack).
[0071] Figure 5 The confusion matrix diagram of the multi-classification task (each attack category) is shown, which reflects the classification results and confusion distribution of the model when distinguishing multiple different attack categories. Figure 5 In the figure, the validation multi-class confusion matrix is also called the Validation Multi-Class Confusion Matrix; normal is normal traffic; gear is the gear deception attack; RPM is the speed deception attack; fuzzy is the fuzzy attack; Dos is the denial of service attack.
[0072] In this embodiment, the specific steps for training the SEDSNet lightweight model are as follows:
[0073] Step 1: Obtain a public dataset, perform data cleaning on it, and then perform data conversion after cleaning to generate labeled color images.
[0074] Step 1.1: Obtain a public vehicle intrusion detection dataset. This dataset is collected through the CAN bus interface of a real vehicle in an actual operating environment. It covers CAN message data for normal communication traffic and various attack scenarios (DoS, fuzzing, gear spoofing, and speed spoofing).
[0075] Step 1.2: Clean the raw data and convert its format, including extracting key fields, filling missing values, converting hexadecimal fields to decimal, and adding a label column.
[0076] First, key fields are extracted from each CAN message frame as data features, including the CAN identifier (CAN_ID) and data fields (Data[0], Data[1], Data[2], Data[3], Data[4], Data[5], Data[6], Data[7]). Field names are added to the extracted data as column identifiers for these fields. During the field extraction process, if a field is missing in the CAN message (such as the CAN_ID field is less than four bits or the DATA field is less than 8 bytes long), a preset supplementary strategy is used to fill it. Specifically, if the CAN_ID field is missing, "0000" is added to ensure its length reaches 4 bits; for the DATA field, "00" is used to fill the missing bytes until the length reaches 8 bytes. The extracted CAN_ID and DATA fields need to be formatted uniformly, converting them from the original hexadecimal representation to decimal integers. A label field (Label) is added to each CAN message sample to identify its category.
[0077] Step 1.3: Normalize the distribution of the extracted field data and then map the normalized values to the interval [0, 255].
[0078] Because the pixel value range required to generate a color image is limited to [0, 255], the raw data must be normalized before mapping the extracted CAN data fields into an image. This paper employs Z-Score normalization technology to convert the raw data features into a normal distribution with a mean of 0 and a standard deviation of 1 by calculating the mean and standard deviation of each field. This processing method not only effectively balances the numerical scales of the features of different fields but also, to a certain extent, suppresses the interference of abnormal values on the overall distribution, ensuring that the data is evenly distributed and has low volatility in the normalized feature space. The normalized results are further linearly scaled to the interval [0, 255] to meet the pixel value range requirements for subsequent image generation.
[0079] The main calculation steps are as follows:
[0080] Step 1.3.1: Calculate the mean and standard deviation of each field. (including CAN_ID, Data[0] to Data[7]), calculate the mean μ and standard deviation σ of this field in the entire data set. The mean calculation formula is:
[0081] ,
[0082] The formula for calculating standard deviation is:
[0083] .
[0084] Step 1.3.2: Perform Z-Score standardization (standard score transformation). Based on the calculated mean and standard deviation, the field value of each sample is For standardization, the formula is as follows:
[0085] ,
[0086] This step maps the field values to a normal distribution with a mean of 0 and a standard deviation of 1, reducing the impact of differences in value ranges between different fields and outlier interference.
[0087] Step 1.3.3: Linearly scale to the interval [0,255]. Perform linear mapping to ensure that the pixel range requirements for image generation are met. The calculation formula is:
[0088] ,
[0089] in, and They are the minimum and maximum values of the field in all samples after standardization.
[0090] Step 1.3.4: Round the result and store it. After rounding, a normalized feature vector that conforms to the pixel value range [0, 255] is obtained, providing formatted data for subsequent image generation and model input.
[0091] Step 1.4: The normalized data is grouped by field and converted into a three-channel image;
[0092] In the public vehicle intrusion detection dataset, each network traffic record contains nine key fields, including the CAN identifier (CAN ID) and eight data bytes (DATA[0] to DATA[7]). After normalization, each 27 consecutive messages are reorganized into a 27×9 data matrix and divided into three columns, corresponding to the R, G, and B channels of the image. The data of each channel is reshaped (dimensionally restructured) into a 9×9 matrix and then concatenated in the channel dimension to generate a 9×9×3 color image.
[0093] Step 2: Input the image samples generated after the preprocessing in Step 1 into the established improved SqueezeNet network structure for model training. This network model extracts features and classifies the input images. During the training process, key hyperparameters of the model are dynamically adjusted to optimize the network weights, ultimately resulting in a high-performance, lightweight model suitable for CAN bus intrusion detection tasks.
[0094] Step 2.1: The color image processed in Step 1 needs to be resized according to the model input requirements to ensure it is suitable for subsequent deep learning model processing. This method resizes the image to 224×224. The dataset is then divided into three parts: training, validation, and test sets, using a 7:2:1 ratio. The training set is used for model parameter learning, the validation set is used to monitor the training process and hyperparameter adjustment, and the test set is used for final evaluation of model performance.
[0095] Step 2.2: Before model training begins, normalize and standardize the color image samples generated in step 1.
[0096] The normalization operation scales each image pixel value to the [0,1] interval. The calculation formula is:
[0097] ,
[0098] in, is the normalized pixel value, This normalization step eliminates the impact of the original image value range on model training and makes all input features in a unified scale.
[0099] Then, the normalized image samples are normalized. Normalization maps the data to a standard normal distribution with a mean of 0 and a variance of 1 by subtracting the mean of each channel and dividing by the standard deviation (std). The calculation formula is:
[0100] ,
[0101] in, where μ represents the normalized pixel values of the image, and μ and σ represent the mean and standard deviation of each channel, respectively. Based on experience, μ and σ are both set to [0.5, 0.5, 0.5]. This linearly maps the normalized image pixel values from the interval [0, 1] to the range [−1, 1]. This satisfies the input data distribution requirements of deep learning models and further improves training stability.
[0102] Step 2.3: Input the sample data obtained in Step 2.2 into the constructed lightweight SEDSNet model for training. Use the validation set to ensure that the model's hyperparameter configuration is optimal during training. Use cross-validation to optimize key hyperparameters. To avoid overfitting, the training hyperparameters are set as follows:
[0103]
[0104] Step 2.4: After obtaining the model hyperparameter configuration, evaluate it using 5-fold cross-validation. Randomly partition the original dataset into 5 equally proportioned subsets. Each rotation selects one of these subsets for model evaluation. Calculate the corresponding metrics, such as accuracy, loss, and F1 score. Average the results across 5 rounds to obtain the model's overall performance under different partitioning scenarios, thereby verifying the performance of the current hyperparameter combination.
[0105] After determining the optimal hyperparameter combination, we conducted a performance evaluation on the lightweight SEDSNet model. We used accuracy, precision, recall, F1 score, number of parameters, and average processing time as evaluation criteria to measure the model's comprehensive performance across multiple dimensions, ensuring that the trained model maintains stable and reliable recognition capabilities under diverse data conditions. The calculations for accuracy, precision, recall, and F1 score are as follows:
[0106] ,
[0107] ,
[0108] ,
[0109] ,
[0110] Among them, TP means that the attack is correctly identified as an attack, TN means that the normal is correctly identified as normal, FP means that the normal is misclassified as an attack, and FN means that the attack is misclassified as normal.
[0111] This paper conducted comparative tests on a public vehicle intrusion detection dataset with typical lightweight models such as ResNet-18, EfficientNet, ShuffleNetV2, and MobileNetV3. The results are shown in Table 1 below:
[0112] Table 1. Experimental results of various models on Car-hacking:
[0113]
[0114] As can be seen from Table 1, the proposed model achieves 100% accuracy, precision, recall and , comprehensively outperforming four mainstream lightweight models: ResNet-18, EfficientNet, ShuffleNetV2, and MobileNetV3, demonstrating superior classification performance. In terms of inference efficiency, the test time of our model is 1.9ms, which is approximately 78.7% shorter than ResNet-18's 8.9ms and 72.1% shorter than EfficientNet's 6.8ms, resulting in significantly faster inference speed.
[0115] In terms of model size, the proposed model has only 0.25M parameters, a reduction of approximately 97.8% compared to ResNet-18 (11.18M) and 93.8% compared to EfficientNet (4.01M). Furthermore, compared to ShuffleNetV2 (1.26M) and MobileNetV3 (1.52M), the parameters are compressed by 80.2% and 83.6%, respectively. This result demonstrates that the proposed model maintains high accuracy while offering enhanced lightweight features and lower computational overhead.
[0116] In summary, the proposed IoV intrusion detection model, based on a lightweight and efficient architecture, significantly reduces model complexity and response latency while maintaining 100% detection accuracy, effectively addressing malicious traffic attacks in IoV networks. During actual vehicle operation, the model demonstrated excellent real-time performance and deployment adaptability, effectively enhancing the security protection capabilities of onboard systems and ensuring driving safety in intelligent driving environments.
[0117] This embodiment provides a vehicle-mounted CAN bus intrusion detection method based on an improved SqueezeNet lightweight network, which includes the following steps:
[0118] Step 1: Receive CAN bus data stream in real time and extract message field information;
[0119] Step 2: Perform field selection and sample construction on the received CAN data. Select the identifier and data byte 0 to data byte 7, a total of 9 fields, construct a sample for every 27 messages, and map it into a three-channel color image.
[0120] Step 3: Input the converted color image into the lightweight vehicle network intrusion detection system based on the improved SqueezeNet;
[0121] Step 4: Use the trained model to perform inference and classification on the real-time received CAN traffic data and output the corresponding classification label;
[0122] Step 5: Based on the classification label results, determine whether there is CAN bus intrusion behavior.
[0123] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is merely a logical function division. There may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interface, indirect coupling or communication connection of devices or units, which may be electrical, mechanical or other forms.
[0124] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0125] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0126] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely illustrative and are not intended to limit the scope of the present application. Various changes and modifications may be made therein by those skilled in the art without departing from the scope and spirit of the present application. All such changes and modifications are intended to be included within the scope of the present application as required by the appended claims.
[0127] Similarly, it should be understood that in order to streamline the present application and aid in understanding one or more of the various application aspects, in the description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, this approach of the present application should not be interpreted as reflecting the intention that the claimed application requires more features than those explicitly recited in each claim. More precisely, as reflected in the corresponding claims, the point of the application is that the corresponding technical problem can be solved with fewer features than all the features of a single disclosed embodiment. Therefore, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present application.
[0128] Furthermore, those skilled in the art will appreciate that although some embodiments described herein include certain features included in other embodiments but not other features, combinations of features from different embodiments are intended to be within the scope of this application and to form different embodiments. For example, in the claims, any of the claimed embodiments may be used in any combination.
[0129] It should be noted that the above embodiments are illustrative rather than limiting of the present application, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses should not be construed as limiting the claims. The use of the words first, second, and third, etc., does not denote any order. These words may be interpreted as designations.
Claims
1. A vehicle-mounted CAN bus intrusion detection system, characterized in that: The intrusion detection system is obtained based on the training of an improved compression network model, and the compression network model is a SqueezeNet model; The improved compression network model includes a convolution layer, a pooling layer, multiple dynamic feature extraction modules, a convolution mapping layer, a global average pooling layer and a classification output layer; Each dynamic feature extraction module includes a compression layer and two expansion branches. The compression layer uses 1×1 depthwise separable convolution for feature compression. The two expansion branches use 1×1 depthwise separable convolution and 3×3 depthwise separable convolution respectively. All convolution operations are connected to batch normalization and rectified linear unit activation functions. The output of the expansion branch is passed through a feature splicing layer for channel feature fusion and is connected to an efficient channel attention module to optimize the channel feature distribution. The classification output layer is used to output the final classification probability distribution; The steps of training the improved compression network model include: S1. Obtain a public dataset, clean and preprocess the data, and convert it into labeled color images after normalization. S2. Input the image obtained after S1 processing into the improved compression network model for training. During the training process, the class-balanced focal loss is used as the loss function, the loss weight is dynamically adjusted based on the number of class samples, and a focal modulation term is introduced; the learning rate is optimized through the validation set, and the final model weight is obtained after the training is completed; during the model training stage, a learning rate scheduling strategy based on performance stagnation is adopted to improve the stability of the training process and the final convergence effect; The adjustment rules of the learning rate scheduling strategy are: ; in, is the current learning rate, is the learning rate reduction factor, is the number of tolerance rounds, that is, when the verification loss is continuous When the round does not decrease, the current learning rate will be multiplied by the factor; S3: Perform inference verification on the model trained in S2 to evaluate the recognition accuracy, detection latency, and parameter size of the model on the test set; In step S2, the loss function is expressed as: in, is the balance factor and (0,1), Representation category The number of samples, is the cross entropy loss, is the model’s predicted probability for the correct category, is the focal modulation coefficient, is the feature vector of the input sample, is the true category label of the sample; The step S1 comprises: S11. Obtain a public dataset for vehicle intrusion detection; S12. Perform field cleaning and format conversion on the original data, including extracting key fields, filling missing values, converting hexadecimal fields to decimal, and adding label columns; S13, normalizing the distribution of the extracted field data, and mapping the normalized value to the interval [0, 255]; S14, converting the normalized data into three-channel images by field grouping, where the three channels correspond to fields of different categories, for input to the improved compression network model; Wherein, step S13 includes: S131, calculate the mean and standard deviation of each field, for each feature field , calculate the mean μ and standard deviation σ of the field in the entire data set. The mean calculation formula is: ; The formula for calculating standard deviation is: ; S132, perform Z-Score standardization, and calculate the field value of each sample based on the calculated mean and standard deviation. For standardization, the formula is as follows: ; Mapping the field value to a normal distribution with a mean of 0 and a standard deviation of 1 reduces the impact of differences in the value ranges of different fields and outlier interference; S133, linear scaling to the [0,255] interval, normalization results Perform linear mapping to ensure that the pixel range requirements for image generation are met. The calculation formula is: ; and are the minimum and maximum values of the field in all samples after standardization; S134, rounding the result and storing it, and scaling the result After rounding, a normalized feature vector that conforms to the pixel value range [0, 255] is obtained, providing formatted data for subsequent image generation and model input.
2. The vehicle-mounted CAN bus intrusion detection system according to claim 1, characterized in that: The improved compression network model includes a convolution layer, a first pooling layer, a second dynamic feature extraction module, a third dynamic feature extraction module, a fourth dynamic feature extraction module, a second pooling layer, a fifth dynamic feature extraction module, a sixth dynamic feature extraction module, a seventh dynamic feature extraction module, an eighth dynamic feature extraction module, a third pooling layer, a ninth dynamic feature extraction module, a convolutional mapping layer, a global average pooling layer and a classification output layer, which are arranged in sequence.
3. The vehicle-mounted CAN bus intrusion detection system according to claim 2, characterized in that: The convolution layer is a 7×7 standard convolution with a stride of 2, 3 input channels, and 96 output channels. The convolution operation is followed by a rectified linear unit activation function. The convolution mapping layer is a 1×1 convolution, which is used to map the number of output channels of the ninth dynamic feature extraction module to the number of target categories. The convolution operation is preceded by a random dropout layer with a dropout rate of 0.5, and followed by a rectified linear unit activation function.
4. The vehicle-mounted CAN bus intrusion detection system according to claim 2, characterized in that: The first pooling layer is a maximum pooling operation with a pooling kernel size of 3×3, a stride of 2, and a rounding-up mode; The second pooling layer and the third pooling layer are respectively arranged after the fourth dynamic feature extraction module and the eighth dynamic feature extraction module, and both are maximum pooling operations with a pooling kernel size of 3×3 and a step size of 2, for staged downsampling; The global average pooling layer is an adaptive average pooling operation with an output size of 1×1, which is used to compress the spatial dimension.
5. The vehicle-mounted CAN bus intrusion detection system according to claim 1, characterized in that: The step S14 includes: The processed CAN message data is divided into groups of 27. Nine fields are selected from each message, including the identifier and data byte 0 to data byte 7, and divided into three channels according to the field function. Among them, the identifier, data byte 0 and data byte 1 are mapped to the red channel, data byte 2, data byte 3 and data byte 4 are mapped to the green channel, and data byte 5, data byte 6 and data byte 7 are mapped to the blue channel; Each channel field is reconstructed into a 9×9 two-dimensional matrix, and then combined in the channel dimension to form a 9×9×3 color image. The color image is adjusted to a uniform size of 224×224 through interpolation method, and finally saved as a PNG format image file, stored by label classification, and used as input samples of the improved compression network model.
6. The vehicle-mounted CAN bus intrusion detection system according to claim 1, characterized in that: The step S2 comprises: S21, divide the data set obtained in S1 into training set, validation set and test set in a ratio of 7:2:1; S22. Before model training, normalize and standardize the image data in the training set, validation set, and test set; S23. Input the training set data into the constructed improved compression network model for training. The optimizer uses the adaptive moment estimation optimizer, the loss function is the class-balanced focal loss, the number of training rounds is set to 20, the initial learning rate is set to 0.0001, and the batch size is set to 32. During the training process, a dynamic learning rate decay strategy is introduced to dynamically adjust the learning rate to accelerate convergence. S24. Use 5-fold cross-validation to test the learning rate and batch size combination. Use the validation set to evaluate the model performance changes after each round of training. Select the optimal hyperparameter configuration based on the average accuracy and loss index of the validation set and save the model weights with the best performance to the specified path.
7. A vehicle-mounted CAN bus intrusion detection method, characterized in that: The intrusion detection method comprises the following steps: Receive CAN bus data stream in real time and extract message field information; Perform field selection and sample construction on the received CAN data. Select the identifier and data byte 0 to data byte 7, a total of 9 fields, construct a sample for every 27 messages, and map it into a three-channel color image. Inputting the converted color image into a vehicle-mounted CAN bus intrusion detection system, wherein the vehicle-mounted CAN bus intrusion detection system is the vehicle-mounted CAN bus intrusion detection system according to any one of claims 1 to 6; Use the trained model to perform inference and classification on the real-time received CAN traffic data and output the corresponding classification labels; Based on the classification label results, determine whether there is CAN bus intrusion behavior.
Citation Information
Patent Citations
Diabetic retinopathy classification method by using super lightweight SqueezeNet network
CN108537282A
Gradient-based network traffic classification method and system
CN115034284A
Vehicle intrusion detection system and method based on Hybrid OfficientNet model
CN119106712A
Cited By
A vehicle-mounted CAN bus intrusion detection method based on time interval conditional entropy
CN122372288A