A robust vehicle-mounted intrusion detection method and system based on self-supervised contrast learning
By employing self-supervised contrastive learning and a feature pyramid network, a robust vehicle intrusion detection system is constructed. This solves the problems of dependence on labeled data and abnormal data contamination in vehicle intrusion detection systems, achieving efficient and robust detection results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JILIN UNIVERSITY
- Filing Date
- 2026-04-22
- Publication Date
- 2026-07-14
Smart Images

Figure CN122394892A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of automotive information security technology, and in particular to a robust vehicle intrusion detection method and system based on self-supervised comparative learning. Background Technology
[0002] With the rapid development of Internet of Things (IoT) and Internet of Vehicles (IoV) technologies, autonomous vehicles (AVs) and connected vehicles (CVs) have become a new trend in network-controlled automobiles. These autonomous vehicles communicate through interaction with other vehicles. Within the IoV, the Controller Area Network (CAN) serves as the core system facilitating communication between different electronic control units. CAN is currently experiencing a growing demand for in-vehicle intelligent services, but its original design lacked sufficient security measures, allowing attackers to exploit vulnerabilities in the in-vehicle network through interfaces, telematics, infotainment systems, and various sensors.
[0003] Furthermore, the development of machine learning (ML) and deep learning (DL) technologies has brought new opportunities to in-vehicle intrusion detection systems. Analyzing traffic data can effectively distinguish between normal network traffic and various network attacks. However, many supervised learning methods require sufficient labeled data for effective training; however, obtaining manually labeled data is costly and challenging, making mass production in automobiles difficult. A key characteristic of intrusion detection is anomalous data contamination. In ideal intrusion detection, commonly used unsupervised learning methods are typically suitable for clean data as a way to identify anomalous activity. However, in reality, datasets are often mixed with unknown anomalies. This unlabeled anomalous data can mislead the model's learning process, causing decision boundary shifts and thus reducing the performance and reliability of the intrusion detection system. Summary of the Invention
[0004] The purpose of this invention is to provide a robust vehicle intrusion detection method and system based on self-supervised contrastive learning, which minimizes the loss of convolutional information during the feature extraction stage by combining contrastive learning with a Feature Pyramid Network (FPN) strategy.
[0005] To achieve the above objectives, the present invention provides the following solution: A robust vehicle intrusion detection method based on self-supervised contrastive learning includes the following steps: Real-time acquisition of vehicle data, followed by preprocessing and data reconstruction to obtain an image matrix; A random augmentation operation is performed on the image matrix to obtain positive sample pairs; A feature extraction network is constructed based on feature pyramids and autoencoders; Self-supervised comparative learning and model training of the feature extraction network are performed using positive sample pairs; The network parameters of the trained feature extraction network are fixed based on the learned features, and attack detection is performed to obtain the detection results.
[0006] Optionally, vehicle-mounted data is acquired in real time, and preprocessed and reconstructed to obtain an image matrix, including: Real-time acquisition of communication data from the vehicle's controller local area network; the communication data includes: ID field and DATA field; Select the first two bytes of the communication data as feature input, and convert the communication data into binary; Arrange continuous communication data into different matrices and stack the matrices into a tensor image; By performing interval mapping on the matrix, the image matrix is obtained.
[0007] Optionally, random enhancement operations include: random cropping, horizontal or vertical flipping, color jittering, and Gaussian noise addition.
[0008] Optionally, a feature extraction network is constructed based on a feature pyramid and an autoencoder, including: By halving the number of channels in the original network, a lightweight backbone network is obtained; In the lightweight network, lateral connections are established after the output of each residual block, and feature pyramid network fusion is performed through upsampling and convolution operations. The feature extraction network is obtained by compressing and reconstructing features using an encoder-decoder structure and mean square error.
[0009] Optionally, the encoder-decoder structure is expressed as follows: ;in, Input data to the encoder. The data reduced for the encoder This represents the degree of difference between the predicted and actual values.
[0010] Optionally, the feature extraction network is subjected to self-supervised contrastive learning and model training using positive sample pairs, including: The input of the feature extraction network is mapped to a low-dimensional embedding space through a multilayer perceptron to obtain projected features; The projection features are predicted by the prediction layer to obtain the prediction vector, and the cosine similarity between the prediction vector and the projection features is minimized. A loss function is constructed based on reconstruction loss and contrastive loss, and the feature extraction network is jointly trained using the loss function and the stopping gradient mechanism.
[0011] Optionally, the network parameters of the trained feature extraction network are fixed based on the learned features, and attack detection is performed to obtain the detection results, including: By fixing the network parameters of the trained feature extraction network, a frozen network is obtained. The similarity between the input samples of the frozen network and the learned features is calculated using a classifier, and the attack type is determined based on the similarity.
[0012] A robust vehicle intrusion detection system based on self-supervised contrastive learning includes: The data processing module is used to collect vehicle data in real time, and to preprocess and reconstruct the vehicle data to obtain an image matrix; The image enhancement module performs random enhancement operations on the image matrix to obtain positive sample pairs; The network construction module builds a feature extraction network based on feature pyramids and autoencoders; The model training module performs self-supervised comparative learning and model training on the feature extraction network through positive sample pairs; The attack detection module uses the learned features to fix the network parameters of the trained feature extraction network, performs attack detection, and obtains the detection results.
[0013] According to specific embodiments provided by the present invention, the following technical effects are disclosed: The robust vehicle intrusion detection method and system based on self-supervised contrastive learning provided by the present invention includes: real-time acquisition of vehicle data, preprocessing and reconstructing the vehicle data to obtain an image matrix; random enhancement operation on the image matrix to obtain positive sample pairs; construction of a feature extraction network based on feature pyramids and autoencoders; self-supervised contrastive learning and model training of the feature extraction network through positive sample pairs; fixing the network parameters of the trained feature extraction network based on the learned features, and performing attack detection to obtain the detection result. The model training of this method does not rely on labeled data from the vehicle network, nor does it require the construction of negative samples. Learning is completed simply by maximizing the consistency of positive sample features, and the number of channels in the original network is reduced to half, effectively reducing model complexity. Simultaneously, the integration of FPN to enhance multi-scale feature fusion further improves detection accuracy and robustness. Attached Figure Description
[0014] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0015] Figure 1 This is a flowchart of the robust vehicle intrusion detection method based on self-supervised contrastive learning of the present invention; Figure 2 This is a block diagram illustrating the working principle of the feature extraction network in an embodiment of the present invention. Detailed Implementation
[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0017] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0018] like Figure 1 and Figure 2 As shown, this invention provides a robust vehicle intrusion detection method based on self-supervised contrastive learning, comprising the following steps: Step 100: Collect vehicle data in real time, and preprocess and reconstruct the vehicle data to obtain an image matrix; Step 200: Perform random augmentation on the image matrix to obtain positive sample pairs; Step 300: Construct a feature extraction network based on the feature pyramid and autoencoder; Step 400: Perform self-supervised contrastive learning and model training on the feature extraction network using positive sample pairs; Step 500: Based on the learned features, fix the network parameters of the trained feature extraction network, and perform attack detection to obtain the detection results.
[0019] In the specific implementation process, step 100 first collects real-time communication data (i.e., CAN messages) from the vehicle controller's local area network. Each CAN message contains an ID field (used to identify the controller from which the message originates) and a DATA field (used to store the transmitted payload). Then, the first two bytes of the ID and DATA fields in the CAN are selected as feature inputs. The hexadecimal fields are converted to binary and uniformly padded to a 32-bit length to ensure consistent input format. Next, 32 consecutive messages are combined into a sequence, that is, the ID, data0, and data1 fields are arranged into 32×32 matrices respectively, and the three matrices are stacked to form a 32×32×3 tensor image as input to the deep learning network. Finally, the matrix values are mapped to the 0–255 range to obtain the image matrix, which is then normalized to ensure comparability of features of different dimensions during training, thereby avoiding training bias caused by differences in numerical ranges.
[0020] In the specific implementation process, step 200, in order to improve the generalization ability of the model, performs various random augmentation operations on the images generated in step 100, including random cropping, horizontal or vertical flipping, color jittering, and Gaussian noise addition. Each image undergoes two different data augmentation operations to form a pair of positive samples (view1 and view2). The two samples in the positive sample pair share the same semantic features, but their manifestations are different, and both are used for comparative learning.
[0021] In the specific implementation process, step 300, which involves constructing the feature extraction network, includes the following steps: (1) Lightweight backbone network construction: The number of channels of the original ResNet-18 is halved to reduce computational overhead, while maintaining the residual structure to capture effective features at shallower levels and adapt to the limited storage and computing power in the vehicle environment.
[0022] (2) Feature pyramid network fusion: After the output of each residual block of the lightweight ResNet, a horizontal connection is established to fuse the spatial location information of the low layer with the semantic information of the high layer. The multi-layer feature map of the same scale is generated through upsampling and convolution operations, and finally a more complete global feature representation is formed.
[0023] (3) Autoencoder Embedding: The encoder-decoder structure is used to compress and reconstruct the input features of the feature pyramid network. In this embodiment, mean squared error (MSE) is used as the reconstruction loss to maintain consistency between the input and output, which helps to learn a more stable latent feature representation. Specifically, the expression of the encoder-decoder structure is: ; in, Input data to the encoder. The data reduced for the encoder The degree of difference between predicted and actual values is measured by... v and d The difference is measured by summing the squares of the differences, expressed as: .
[0024] In the specific implementation process, step 400 includes the following steps: (1) Projection Head Design: Input features are mapped to a low-dimensional embedding space through a multilayer perceptron (MLP), ensuring that the augmented samples still possess semantic consistency in the embedding space, thus improving the discriminative power of the features while reducing dimensionality. Specifically, the MLP layer has 256 input and output dimensions, expressed as: ; in, W and b This represents the weights and biases of the fully connected layer. "B" refers to the batch normalization layer, which is the activation function. The projection layer of an MLP is used to identify invariants in augmented data, allowing the model to filter out less important features only. It's important to note that without this feature projection process, intrusion detection models may fail because the model would zero out weights and biases to maximize similarity, thus breaking the learning shortcut.
[0025] (2) Prediction Head and Clone Network Design: After feature projection is completed, the core network (i.e., the overall network model) passes the projection vector to the prediction head. The prediction layer is structurally similar to the projection layer, both consisting of two hidden layers and a normalization layer. Once the prediction vector is generated in the core network, the network minimizes the cosine similarity between the prediction vector and the projection vector of the clone network. The goal is to reduce the negative cosine similarity between these vectors, enabling the model to learn better feature representations by more effectively distinguishing different classes. The formula for calculating cosine similarity is: ; in, These are two normalized mean square errors used to optimize the neural network by calculating the similarity between vectors. Minimizing this similarity helps to more accurately identify pattern consistency in the vehicular network data stream. Similarly, the input... v 1 and input v 2. Swap to the core network to obtain the prediction vector .
[0026] (3) Loss function design: First, the reconstruction loss is calculated to ensure the consistency between the input and the reconstruction output. Then, the contrast loss is calculated and the cosine distance between the predicted vector and the contrast vector is minimized. The robustness of the feature representation is achieved through joint optimization.
[0027] (4) Gradient-stopping optimization mechanism: During model training, the core network performs backpropagation for bootstrapping, while the clone network performs a gradient-stopping operation, also known as gradient truncation. Specifically, this operation is crucial to prevent model collapse. If the gradient-stopping mechanism is removed, the optimizer can quickly converge to a degenerate form, minimizing the loss. Gradient truncation effectively ensures that the clone network does not interfere with the core network's learning process and continues to learn robust feature representations. The expression for this optimization mechanism is: ; It should be noted that joint training with the autoencoder and contrast loss significantly optimizes the network, resulting in robust latent representations. Finally, representations from the core and clone networks are fused to create global features, which are then used as input to the classification module. This fusion enhances the model's ability to capture comprehensive features across different scales and contexts, improving classification accuracy. In this embodiment, the loss function is expressed as: .
[0028] In the specific implementation process, step 500, after the model training is completed, fixes the parameters of the feature extraction network to obtain a frozen network, and uses the learned feature representation for classification. In this embodiment, a KNN classifier is used to calculate the similarity between the input sample and known features through Euclidean distance; or a linear classifier is used to directly use the feature vector for discrimination, to suit the real-time requirements of the vehicle system. In the classification module, a linear classifier is trained using the frozen representation from the training set, and its performance is evaluated on the test set. It should be noted that KNN is simple and practical, allowing direct classification using pre-trained representations without additional training. It operates based on the distance to the k nearest neighbors and uses Euclidean distance to measure similarity.
[0029] This invention also provides a robust vehicle intrusion detection system based on self-supervised contrastive learning, comprising: The data processing module is used to collect vehicle data in real time, and to preprocess and reconstruct the vehicle data to obtain an image matrix; The image enhancement module performs random enhancement operations on the image matrix to obtain positive sample pairs; The network construction module builds a feature extraction network based on feature pyramids and autoencoders; The model training module performs self-supervised comparative learning and model training on the feature extraction network through positive sample pairs; The attack detection module uses the learned features to fix the network parameters of the trained feature extraction network, performs attack detection, and obtains the detection results.
[0030] The beneficial effects of this invention are as follows: 1) It adopts a self-supervised contrastive learning paradigm that does not require the construction of negative samples. The model training is completed only by maximizing the consistency of positive sample features. It does not rely on manually labeled data of vehicle networks at all, which solves the problems of high labeling cost, long cycle and difficulty in large-scale mass production of traditional supervised or semi-supervised learning. At the same time, it does not rely on known attack labels, gets rid of the dependence on labeled data, and reduces the cost of mass production and deployment. 2) To address the issue of unknown anomaly contamination in real-world vehicle datasets, we jointly optimize the reconstruction loss and contrastive loss of the autoencoder, and combine this with a stopping gradient mechanism to prevent model training collapse, enabling the model to learn more stable latent feature representations. At the same time, we integrate a feature pyramid network to achieve multi-scale feature fusion, minimize the loss of convolutional information, avoid decision boundary shifts caused by abnormal data, improve detection reliability in complex scenarios, and significantly enhance the model's anti-interference ability and robustness. 3) By making lightweight modifications to the backbone network ResNet-18 and reducing the number of channels to half of the original, the computational load and storage overhead of the model are significantly reduced while retaining the residual structure feature extraction capability. 4) The classification stage uses KNN or linear classifiers with extremely low computational complexity, which can complete inference without additional training. This perfectly adapts to the limited computing power and memory resources on the vehicle side, ensuring the real-time performance of intrusion detection. 5) Positive sample pairs are constructed through various data augmentation operations such as random cropping, flipping, color jittering, and Gaussian noise, which enhances the model's adaptability to data perturbation; and the output features of the core network and clone network are integrated to enhance the model's comprehensive feature capture capability at different scales and under different backgrounds, significantly improving the accuracy of distinguishing between normal traffic and attack traffic.
[0031] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0032] Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this invention. Furthermore, those skilled in the art will recognize that, based on the ideas of this invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of this invention.
Claims
1. A robust vehicle intrusion detection method based on self-supervised contrastive learning, characterized in that, Includes the following steps: Real-time acquisition of vehicle-mounted data, followed by preprocessing and data reconstruction to obtain an image matrix; A random enhancement operation is performed on the image matrix to obtain positive sample pairs; A feature extraction network is constructed based on feature pyramids and autoencoders; The feature extraction network is subjected to self-supervised contrastive learning and model training using the positive sample pairs. Based on the learned features, the network parameters of the trained feature extraction network are fixed, and attack detection is performed to obtain the detection results.
2. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 1, characterized in that, Real-time acquisition of vehicle-mounted data, followed by preprocessing and data reconstruction to obtain an image matrix, including: Real-time acquisition of communication data in the vehicle controller local area network; the communication data includes: ID field and DATA field; The first two bytes of the communication data are selected as feature inputs, and the communication data is converted into binary. The continuous communication data is arranged into different matrices, and the matrices are stacked into a tensor image; The matrix is then subjected to interval mapping to obtain the image matrix.
3. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 1, characterized in that, The random enhancement operations include: random cropping, horizontal or vertical flipping, color jittering, and Gaussian noise addition.
4. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 1, characterized in that, A feature extraction network is constructed based on feature pyramids and autoencoders, including: By halving the number of channels in the original network, a lightweight backbone network is obtained; In the lightweight network, lateral connections are established after the output of each residual block, and feature pyramid network fusion is performed through upsampling and convolution operations. The feature extraction network is obtained by compressing and reconstructing features using an encoder-decoder structure and mean square error.
5. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 4, characterized in that, The expression for the encoder-decoder structure is: ;in, Input data to the encoder. The data reduced for the encoder This represents the degree of difference between the predicted and actual values.
6. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 1, characterized in that, Self-supervised contrastive learning and model training of the feature extraction network using the positive sample pairs include: The input of the feature extraction network is mapped to a low-dimensional embedding space using a multilayer perceptron to obtain projected features; The projection features are predicted by the prediction layer to obtain a prediction vector, and the cosine similarity between the prediction vector and the projection features is minimized. A loss function is constructed based on the reconstruction loss and the contrastive loss, and the feature extraction network is jointly trained using the loss function and the stopping gradient mechanism.
7. The robust vehicle intrusion detection method based on self-supervised contrastive learning according to claim 1, characterized in that, Based on the learned features, the network parameters of the trained feature extraction network are fixed, and attack detection is performed to obtain the detection results, including: The network parameters of the trained feature extraction network are fixed to obtain the frozen network; The similarity between the input samples of the frozen network and the learned features is calculated by a classifier, and the attack type is determined based on the similarity.
8. A robust vehicle-mounted intrusion detection system based on self-supervised contrastive learning, characterized in that, include: The data processing module is used to collect vehicle data in real time, and to preprocess and reconstruct the vehicle data to obtain an image matrix; The image enhancement module performs a random enhancement operation on the image matrix to obtain positive sample pairs; The network construction module builds a feature extraction network based on feature pyramids and autoencoders; The model training module performs self-supervised comparative learning and model training on the feature extraction network using the positive sample pairs; The attack detection module fixes the network parameters of the trained feature extraction network based on the learned features, performs attack detection, and obtains the detection results.