A method for vehicle safety detection
The convolutional neural network model and Google Net model built through TensorFlow, combined with edge computing and Internet of Vehicles technologies, solve the problem of low vehicle safety detection accuracy, achieve more accurate vehicle behavior and status recognition, and improve the robustness of detection. and adaptability.
Patent Information
- Application Number
- CN202410198663.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-22
- Publication Date
- 2024-10-25
- Estimated Expiration
- 2044-02-22
AI Technical Summary
Existing vehicle safety detection technology has low accuracy, especially in complex traffic scenarios, it is difficult to accurately capture vehicle behavior and status, resulting in insufficient detection accuracy and robustness.
A convolutional neural network model based on TensorFlow is used, combined with the Google Net model, to extract feature data of vehicle images through edge computing, determine the vehicle's driving direction and lane departure distance, and transmit the data to the cloud analysis platform through the Internet of Vehicles secure data transmission protocol. Perform deep learning analysis.
It significantly improves the accuracy and robustness of vehicle safety detection, can more accurately identify vehicle behavior and status, enhances the adaptability and generalization ability of the detection model, and effectively solves the problem of low vehicle safety detection accuracy.
Smart Images

Figure CN117911964B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of vehicle detection, and in particular to a method for vehicle safety detection. Background Art
[0002] With the increasing number of vehicles and traffic complexity, vehicle safety has become an important concern. However, traditional vehicle safety detection technology faces challenges such as low accuracy and poor real-time performance, especially in complex traffic scenarios. Therefore, there is an urgent need for an advanced vehicle safety detection method that comprehensively utilizes deep learning and optimization technology to improve accuracy and real-time performance, so as to effectively respond to the increasing traffic safety hazards.
[0003] At present, a common problem in vehicle safety detection technology is insufficient accuracy, especially when it comes to key features such as driving direction and lane departure distance. Traditional methods are difficult to fully capture vehicle behavior and status, and cannot effectively cope with the challenges of complex traffic environments.
[0004] In the related art, for example, Chinese patent document CN114987551A provides a lane departure warning method based on a dual-stream convolutional neural network, which includes the following steps: dividing a video containing lane information collected by a camera into multiple equal-length non-overlapping segments, and sparsely sampling each segment; inputting the static frame image and optical flow image obtained by sampling each segment into the spatial stream convolutional neural network and the temporal stream convolutional neural network for feature extraction; fusing the spatial features and temporal features extracted from each segment; integrating the fused temporal features and spatial features; inputting the integrated features into the classifier to obtain the classification result; judging the lane departure situation and performing lane departure warning based on the classification result. However, the scheme is based on the optical flow method to calculate the temporal features, which is sensitive to video quality and vehicle motion changes. However, the optical flow method needs to calculate the motion and pixel changes between two frames of images, which is very sensitive to video quality and vehicle motion changes, has poor stability, and is prone to introduce noise, resulting in inaccurate subsequent temporal feature extraction, thereby reducing the detection accuracy and robustness of the model. Summary of the invention
[0005] 1. Technical issues to be solved
[0006] In response to the problem of low vehicle safety detection accuracy in the prior art, the present application provides a vehicle safety detection method, which improves the accuracy of vehicle safety detection by collecting vehicle images and extracting features using a convolutional neural network model built based on TensorFlow, and combining it with the Google Net model for deep learning analysis.
[0007] 2. Technical solution
[0008] The purpose of this application is achieved through the following technical solutions.
[0009] The embodiments of the present specification provide a method for vehicle safety detection, including: collecting vehicle images; extracting feature data of the vehicle images through edge computing, the feature data including the vehicle's driving direction and lane deviation distance; transmitting the extracted feature data to a cloud analysis platform through a vehicle network security data transmission protocol; analyzing the extracted feature data through a pre-trained convolutional neural network, and outputting a vehicle safety detection result.
[0010] Among them, edge computing is an image processing method that extracts the contours and features of an image by detecting edge information in the image. The edge reflects the rapid changes in the intensity of image pixels and can characterize the specific objects and scene structures of the image. In this application, edge computing is used to extract the edge contours of the vehicle from the collected vehicle images, and then analyze and determine the vehicle's driving direction and lane deviation distance. Commonly used edge detection algorithms include Sobel, Canny, etc.
[0011] The vehicle driving direction refers to the direction in which the vehicle is moving. In this application, it is necessary to determine whether the vehicle is in different driving direction states such as driving forward, turning left, turning right, etc. The vehicle driving direction judgment is set as an image classification task, and the image features are multi-classified through a convolutional neural network to output the judgment results of different directions.
[0012] The lane departure distance refers to the horizontal distance between the center line of the vehicle and the center line of the lane. This technical solution requires quantitative judgment of the lateral distance of the vehicle from the center of the lane. In this application, the lane departure distance is regarded as a regression problem, and a convolutional neural network is used to perform regression analysis on the image features to output a specific numerical result of the departure distance.
[0013] Among them, the Internet of Vehicles is a network system that connects vehicles to the Internet to realize information exchange and communication between vehicles and between vehicles and infrastructure. The Internet of Vehicles Secure Data Transmission Protocol is a series of communication interface specifications and algorithms that ensure the security of Internet of Vehicles data transmission. In this application, the Internet of Vehicles Secure Data Transmission Protocol is used to upload vehicle image feature data securely and reliably to the cloud server for analysis. Typical secure transmission protocols in the field of Internet of Vehicles, such as 5G-V2X, are usually used. The cloud analysis platform is a platform system hosted on a cloud server cluster that can store, manage and intelligently analyze massive amounts of data. In this application, the cloud analysis platform refers to a vehicle safety detection service platform built on the cloud. It can receive securely transmitted vehicle feature data, use GPU-accelerated high-performance computing resources, and perform vehicle safety analysis and judgment through pre-trained deep learning models.
[0014] Among them, convolutional neural network is a type of artificial neural network containing convolutional layers, which automatically learns feature representation through operations such as convolution and pooling, and is good at processing visual tasks such as image recognition. In this application, a pre-trained convolutional neural network model is used to analyze the features of vehicle images to determine the direction of the vehicle and lane deviation. Pre-trained models such as Google Net all contain a convolutional network structure composed of convolutional layers and pooling layers. The vehicle safety detection result refers to the judgment output result of the collected vehicle driving image after the deep learning analysis model, which can determine whether the vehicle is currently driving safely. In this application, the vehicle safety detection result includes the classification result of the vehicle's direction of travel, and the regression result of the vehicle's deviation distance from the center line of the lane. These results can evaluate the driving safety and potential risks of the vehicle.
[0015] Furthermore, edge computing uses the TensorFlow framework to build a neural network and extract feature data from vehicle images. Among them, TensorFlow is an open source artificial intelligence algorithm framework that can build and train deep learning models using data flow graphs. It provides a variety of tool components to help users efficiently develop machine learning applications. In this application, the TensorFlow framework is used to build a convolutional neural network to achieve vehicle image feature extraction. TensorFlow can quickly build and train CNN models with its flexible programming model.
[0016] Among them, feature data refers to the data representation that reflects the key attributes of the sample input to the machine learning model. Image feature data usually refers to the image pixel information extracted by the image processing algorithm, which has a distinguishing representation function for the target shape, texture, etc. In this application, feature data refers to the digital vector data that can represent the vehicle direction and lane position information obtained after edge detection and other processing on the vehicle image. These feature data are further analyzed as input to the CNN model.
[0017] Furthermore, the collected vehicle images are used as training sets; a convolutional neural network model based on the TensorFlow framework is constructed, including an input layer, a convolutional layer, a pooling layer and a fully connected layer, the input layer is used to receive vehicle images, the convolutional layer and the pooling layer are used for feature extraction, and the fully connected layer is used to output detection results; the driving direction is set as a classification label, and the lane deviation distance is set as a regression label; the constructed convolutional neural network model is trained by the back propagation algorithm using the training set; and the trained convolutional neural network model is used to extract feature data of the collected vehicle images.
[0018] Specifically, the training set is a sample data set used to train machine learning or deep learning models. The training set contains representative input data and corresponding output labels. Through model training, the mapping relationship between input and output can be learned. The collected vehicle driving images can be used as a training set to train the convolutional neural network model. These images contain rich vehicle feature information as input data. These images are labeled, including the vehicle's driving direction (left, right, straight, etc.) as a classification label, and the vehicle's deviation distance from the center of the lane as a regression label. The labeled images and their labels constitute a training set for training the convolutional neural network model. The model parameters are gradually adjusted through the back-propagation algorithm so that the model can extract features from the image, determine the direction and predict the deviation distance. After training, the model learns the ability to understand the vehicle's driving status from the image. Then, this trained model can be used to perform safety detection on the newly input vehicle image to complete direction classification and deviation prediction.
[0019] Specifically, the network structure of the convolutional neural network model is constructed using the TensorFlow framework, which includes an input layer, a convolution layer, a pooling layer, and a fully connected layer. The input layer is used to receive the collected vehicle image as the input data of the model. The convolution layer contains multiple sets of convolution kernels (filters), each of which has a certain receptive field. During forward propagation, the convolution kernel slides on the input feature map and performs convolution operations with the pixels in the receptive field to obtain an output feature map. Different convolution kernels can extract different features of the input image, such as low-level features such as lines, edges, and corners. By constructing multiple sets of convolution layers, the convolution kernels of the latter layers can learn more complex and abstract feature representations based on the output of the previous layers, forming a hierarchical feature extraction structure. The convolution kernels of the initial layer extract low-level features such as edges and textures, the middle layer extracts local shape features, and the high layer can extract higher-level semantic features such as global shape and object category. Through convolution operations, the convolution layer can automatically learn different levels of feature representations of the input image, realizing the feature mapping process from pixel level to semantic level. Finally, the convolutional network obtains high-level semantic features of the image through end-to-end feature level extraction for complex visual tasks.
[0020] Specifically, the pooling layer is usually behind the convolution layer and is used to compress the width and height of the feature map. Common pooling operations include maximum pooling and average pooling. Maximum pooling is the most commonly used pooling operation. It uses a sliding window to slide on the feature map in steps, and takes the maximum value in the window as the output. This can greatly reduce the aspect ratio of the feature map and compress the parameter scale of the model. At the same time, it retains the maximum value of the strong response area in the feature map and realizes feature selection. Average pooling takes the average of the pixel values in the window as the output, which can smooth the feature map and enhance the generalization ability of the model. By setting the window size and step size parameters of the pooling layer, the degree of feature map compression can be controlled to achieve variable-size feature representation. The pooling layer can reduce the number of parameters and control overfitting while compressing the feature map; retain the main features and enhance the robustness of the model to rotation and movement. In CNN, pooling layers and convolution layers appear alternately to achieve a dynamic balance between feature extraction and compression.
[0021] Specifically, the fully connected layer is usually at the end of the network, and it accepts the multi-dimensional feature map output by the pooling layer as input. The fully connected layer multiplies each element in the feature map by the corresponding weight, and then adds them to convert them into a one-dimensional vector. This one-dimensional vector integrates the global information extracted from the feature map and can represent the high-level semantic features of the corresponding vehicle image. By adjusting the parameters of the fully connected layer, the feature vectors in different vehicle states can produce distinguishing patterns. For the classification task of determining the direction of the vehicle, the Softmax classification layer can be used to determine whether the feature vector belongs to different categories such as left turn and right turn. For the regression task of lane deviation distance, a deviation distance value can be directly regressed from the feature vector. In this way, the fully connected layer forms a semantic feature vector representing the vehicle state based on the feature extraction of the pooling layer, which serves as the basis for model judgment and prediction. The entire convolutional neural network realizes a machine learning model for intelligently determining the driving state of the vehicle through layer-by-layer feature extraction, compression and full connection. By adjusting the parameters of the fully connected layer, the model can be trained to learn the mapping relationship between the feature vector and the output results (direction and deviation distance) under different vehicle states. The final model can receive vehicle image input end-to-end, automatically extract and analyze features through convolution and full connection calculations, determine direction and predict deviation distance. This convolutional neural network model reuses the hierarchical feature extraction capability of the convolutional network and realizes intelligent analysis of vehicle safety detection.
[0022] Specifically, the classification label refers to the category label corresponding to each sample data in the classification task, such as left turn, right turn, etc., which belong to the category label of the driving direction classification task. The regression label refers to the data label corresponding to each sample in the regression task, such as the specific lane deviation distance value, which belongs to the annotation label of the regression task. When constructing the convolutional neural network model, its output is divided into two parts: the classification judgment of the driving direction and the regression prediction of the lane deviation distance. Therefore, when annotating the training set samples, it is necessary to annotate each vehicle image with its corresponding driving direction classification label, such as "left turn", "right turn", etc. At the same time, according to the vehicle position in the image, the specific deviation distance of the vehicle relative to the lane centerline is measured and annotated as a regression label. In this way, during the training process, the network model can gradually learn the mapping relationship between image features and driving direction classification and deviation distance regression through the optimization of classification and regression loss functions. The final model can automatically determine the driving direction category and predict the deviation distance value based on the new input image.
[0023] Specifically, after the convolutional neural network model is constructed, it is necessary to use the labeled image training set to train the model. The training process iteratively updates the network parameters according to the back propagation algorithm. The loss function calculates the difference between the output result of the model for the current training sample and the true label. Through back propagation, the gradient of the loss function with respect to the network parameters can be propagated back from the output layer to the input layer in sequence. The gradient descent method updates the parameters of each layer according to the gradient direction, so that the loss function gradually decreases and the model prediction approaches the true label. The network repeats the forward calculation and back propagation process and performs multiple iterations on the entire training set. Through back propagation training guided by the loss function gradient parameter update, the convolutional neural network model can gradually learn the mapping relationship between features and image classification and regression tasks. When the performance of the model on the training set and the validation set converges, the training is completed, and the convolutional neural network model that can be used for detection is finally obtained. The training process follows the standard back propagation algorithm and iterative optimization strategy in the field of deep learning, so that the model acquires the ability to detect vehicle direction and deviation.
[0024] Specifically, after the convolutional neural network model is trained with the training set, its parameters have been adjusted to a state that can achieve vehicle detection. At this time, the trained model can be used to process new vehicle image inputs to complete feature extraction. The new vehicle image input passes through the convolution layer and pooling layer of the network, and the features of the image are gradually extracted from low to high levels. After layer-by-layer calculations of the convolutional network, the image will eventually be converted into a one-dimensional feature vector of a cascade of fully connected layers. This feature vector carries the high-level semantic information of the input image and is the most critical feature representation of the image. In other words, the trained convolutional neural network model has learned how to automatically extract features from the newly input vehicle image. Finally, these feature data can be input into the subsequent classification / regression layer to determine the vehicle's driving direction and deviation distance. In this way, the feature extraction calculation of the pre-trained model is used to achieve intelligent analysis and processing of new images.
[0025] Furthermore, the convolutional neural network model constructed by back propagation algorithm training includes: setting a convolutional layer optimizer and a fully connected layer optimizer, the convolutional layer optimizer is used to adjust the convolutional layer parameters, and the fully connected layer optimizer is used to adjust the fully connected layer parameters; using forward propagation, extracting the spatial features of the input data through the convolutional layer; according to the extracted spatial features, outputting the prediction result y of the convolutional neural network model through the fully connected layer 1 and 2 ; Calculate the measurement result y 1 Cross entropy loss function Loss with the direction label 1 , calculate the measurement result y 2 Mean square error loss function Loss of lane deviation distance 2 ; Apply the chain rule to calculate the weight matrix W in the fully connected layer relative to the cross entropy loss function Loss 1 Gradient Apply the chain rule to calculate the bias vector b in the fully connected layer relative to the mean square error loss function Loss 2 Gradient Using Gradients Update the weight matrix W using the gradient Update the bias vector b; repeat the forward propagation and fully connected layer parameter update steps until the number of fully connected layer training rounds reaches the preset maximum number of rounds.
[0026] Among them, in the training process of the convolutional neural network, the convolutional layer optimizer is an optimization algorithm used to iteratively adjust the convolutional layer parameters (convolution kernel weights, etc.) to minimize the loss function. Commonly used algorithms include SGD, Momentum, Adam, etc. In this application, an independent convolutional layer optimizer is set to specifically optimize the convolutional layer parameters and accelerate network training.
[0027] Among them, the fully connected layer optimizer also refers to the optimization algorithm used to iteratively update the weight parameters of the fully connected layer during the training process, so that the output of the fully connected layer can approach the expected minimum value of the loss function. In this application, an independent optimizer for the fully connected layer is set up, so that the training of the fully connected layer and the convolutional layer can obtain their respective optimal optimization effects. Setting different layer optimizers can select the most appropriate optimization method according to the characteristics of the layer parameters, improve the efficiency of network training, and obtain a better model.
[0028] Among them, in the training process of the neural network, forward propagation refers to the calculation process in which the input data passes through each hidden layer from the input layer, layer by layer, and is calculated and passed to the output layer. In this application, forward propagation is used to pass the input vehicle image data through the convolution layer, pooling layer, etc. in the network in turn to realize the layer-by-layer extraction of features. Spatial features refer to the feature map or feature vector that reflects the spatial information of the input data extracted after the neural network performs convolution, pooling and other operations on the input data. In this application, spatial features of different levels are extracted from the input vehicle image through the forward propagation calculation of the convolution layer, such as spatial information such as edges, textures, and shapes. The convolution layer is calculated through forward propagation to learn effective features from the image spatial information, providing a basis for subsequent detection tasks.
[0029] Specifically, the convolutional layer extracts the spatial feature map of the input image through forward propagation, which contains visual features at different levels. The fully connected layer flattens the spatial feature map output by the convolutional layer into a one-dimensional feature vector and integrates its spatial information. The one-dimensional feature vector is input into the two branch structures corresponding to the fully connected layer. The first branch structure is responsible for determining the direction of the vehicle, and its output result is the predicted direction classification result y 1 The second branch structure is responsible for predicting the vehicle deviation distance, and its output is the predicted deviation distance value y 2 In this way, the fully connected layer integrates the spatial feature information extracted by the convolutional layer and outputs two prediction results of the vehicle state judgment model based on this. 1 and 2 Together, they reflect the detection status of the current input vehicle image and realize end-to-end detection prediction.
[0030] Specifically, 1 is the vehicle driving direction classification result predicted by the model, which corresponds to the direction classification label of the sample. 1 The cross entropy between the classification label and the classification label is used as the loss function Loss for the classification task 1 The cross entropy measures the difference in the distribution of the two. 2 is the lane departure distance regression result predicted by the model, which corresponds to the deviation distance label of the sample. 2 The mean square error between the regression label and the regression label is used as the loss function Loss of the regression task2 The mean square error measures the difference between the two values. 2 It reflects the effect of the model in judging the driving direction classification. 2 It reflects the effect of the model in predicting deviation distance regression. The loss functions of the two parts are calculated separately to constrain the classification and regression capabilities of the model so that it can optimize these two tasks at the same time. 1 and Loss 2 The calculation results can be used to update the model parameters through the back-propagation algorithm to minimize the loss function and improve the joint effect of the model on the two tasks.
[0031] Specifically, the chain rule is a method used to find the derivative of a composite function. According to this rule, the derivative of a composite function is equal to the product of the derivatives of the inner and outer functions. 1 is the cross entropy loss function between the model prediction y1 and the true label, which is related to the fully connected layer weight matrix W through the intermediate variables of the model. According to the chain rule, Loss 1 The derivative of W is decomposed into Loss 1 About y 1 The derivative of y 1 The product of the derivatives of W is the step-by-step derivation. here and All of them can be obtained through layer-by-layer conduction calculation of the model. In this way, the gradient of Loss1 to weight W can be smoothly calculated and used for back propagation optimization of the network.
[0032] Specifically, Loss 2 is the model prediction result y 2 And the mean square error loss function between the actual deviation distance label. According to the chain rule, Loss 2 The derivative with respect to b decomposes into the following product: in, Loss 2 Relative prediction output y 2 The derivative of can be directly obtained. The predicted output y 2 The derivative of the relative bias vector b can be obtained by layer-by-layer conduction calculation. Multiplying the derivative values of the two parts can get the final Loss 2 The gradient with respect to the bias b This way you can use To update the fully connected layer bias b, Loss 2 Minimize and improve the model's lane departure distance prediction effect. This process uses the chain rule to implement the gradient calculation of the composite function and obtain the loss function gradient information required for back propagation.
[0033] Specifically, after getting Loss 1 The gradient of the weight W and Loss 2 The gradient of bias b After that. According to the gradient descent method, using Update the fully connected layer weight matrix W so that Loss 1 Reduce and improve classification effect. At the same time, use Update the fully connected layer bias vector b so that Loss 2 Reduce and improve the regression effect. Repeat the forward propagation calculation and gradient descent parameter update process to complete a training round of model optimization. For each batch of data, repeat the training round iteration to gradually optimize the parameters of the fully connected layer. For the entire training data set, the number of training rounds for calculating gradients and updating parameters continues to accumulate. When the number of training rounds reaches the preset maximum number of training rounds, the parameter training of the fully connected layer ends. So far, by repeating forward and backward propagation training, the fully connected layer has learned to judge and predict the vehicle state based on convolutional features.
[0034] Furthermore, the convolutional neural network model constructed by back-propagation algorithm training also includes: after the full connection layer training is completed, setting the momentum factor γ in the convolution layer optimizer to 0.9, wherein the momentum factor is used to control the influence ratio of the previous round of gradients in the current iteration; using the convolution layer optimizer with a momentum factor γ of 0.9, and using the Loss function to perform momentum optimization on the convolution layer parameters; for the convolution kernel after momentum optimization, selecting the convolution kernel whose absolute value of the convolution layer weight ranks in the top P, and performing L2 regularization.
[0035] Specifically, momentum optimization is an improvement of SGD, which combines the gradient of the current batch and the moving average of the gradient of the previous round. The momentum factor γ is used to control the influence ratio of the previous round of gradient in the current iteration, and its value is usually set to about 0.9. When the fully connected layer training is completed and the convolution layer training begins, γ is set to 0.9. This means that in the current iteration, the moving average of the previous round of gradients will participate in about 90% of the proportion and affect the current gradient direction. This can smooth gradient changes, accelerate network convergence, and help reduce the impact of directional jitter on training. By setting the momentum factor, convolution layer training can utilize historical gradient information to achieve a more stable and efficient model optimization process.
[0036] Specifically, the momentum factor γ is set to 0.9 in the convolutional layer optimizer. Calculate the parameter gradient of the loss function of the current batch with respect to the convolutional layer weights / biases. Perform an exponentially weighted moving average of the current gradient and the previous gradient at a ratio of 0.9 and 0.1. After obtaining the smoothed gradient direction, use the gradient to update the convolutional layer parameters. The convolutional layer weights are calculated as: W' = W-η* Smooth gradients are iteratively optimized. The convolutional layer bias is: b' = b-η * Smooth gradients for iterative optimization. η is the learning rate, which controls the update step size. Repeat the parameter update process and iterate multiple epochs on the training data set. The momentum mechanism combines current and historical gradient information, accelerates model convergence, and improves the training efficiency of the convolutional layer.
[0037] Specifically, after momentum optimization training is performed on the convolution layer, a set of optimized convolution kernel weights is obtained. The absolute value of each convolution kernel weight parameter is calculated, and the convolution kernels with the top P absolute values are sorted and selected. Only the parameters of this part of the main convolution kernels are L2 regularized. Regularization-sensitive main feature extractor. L2 regularization is achieved by adding the sum of squares of the convolution kernel weight parameters as a penalty term in the loss function. The main convolution kernel weights are offset to zero to prevent overfitting. Only the main convolution kernels are L2 regularized, which not only compresses the model size but also retains the learning ability of weaker features. By combining momentum optimization and regularization, better convolution kernel parameters can be obtained and the generalization performance of the model can be improved.
[0038] Furthermore, using a convolutional layer optimizer with a momentum factor of N, the convolutional layer parameters are optimized using the Loss function, including: calculating the loss function of the current iteration of the i-th layer convolution kernel weight w: Loss i (w) = ∑(y i -t i ) 2 +λ||w|| 2 , where y i is the output feature map of the i-th convolution kernel, t i is the corresponding label, ||w|| 2 is the L2 regularization term of the convolution kernel weight vector of the i-th layer, and λ is the regularization coefficient; calculate Loss i Gradient relative to the convolution kernel weight w of the i-th layer: Use the preset momentum factor γ = 0.9 to adjust the current gradient of the i-th layer: Among them, v i is the velocity vector in the update process of the i-th layer convolution kernel weight vector, γ is the momentum optimization factor; using the velocity vector v i Update the convolution kernel weight of the i-th layer: w'=wv i , repeat the above steps until the weights of each convolution kernel converge.
[0039] Specifically, i It indicates that the feature map output is extracted after the i-th layer convolution kernel is forward propagated. i is the true label corresponding to the feature map, such as image category, etc. i -ti ) 2 Calculate the feature map output y i With the true label t i The mean square error between ||w|| 2 Represents the L2 norm of the weight parameter vector of the i-th convolution kernel, that is, the sum of the squares of the weight parameters. λ is a manually set regularization coefficient that controls the strength of the regularization term. λ||w|| 2 is the L2 regularization term of the convolution kernel weight. The final loss function consists of the true loss and the regularization term, which is used to optimize the convolution kernel parameter w. By minimizing this loss function that incorporates regularization, the convolution kernel weight that prevents overfitting can be obtained.
[0040] Specifically, according to the loss function Loss i The definition of , its gradient relative to the convolution kernel weight w can be obtained as: The first term 2(y i -t i ) corresponds to the derivative of the true loss with respect to w, and the second term 2λw corresponds to the derivative of the L2 regularization term with respect to w. Based on the gradient calculation, momentum optimization is performed. i Represents the speed vector in the process of updating the weight of the i-th layer convolution kernel. γ is the preset momentum optimization factor, such as 0.9. According to the momentum formula, the exponential weighted average of the current gradient and the historical speed is calculated to obtain the updated speed vector v i . Then based on the updated v i Update the convolution kernel weight w according to the direction and step size. By integrating gradient calculation, L2 regularization and momentum optimization, the convolution kernel weight after regularization and momentum optimization can be obtained to prevent overfitting.
[0041] Specifically, the loss function gradient of the convolution kernel weight w of the i-th layer is calculated After that, the momentum mechanism is used to obtain the updated speed v i After that. According to w'=wv i The convolution kernel weights are updated using the formula. i The direction of indicates the direction in which w needs to be updated this time, and its modulus indicates the step size of the update. By iteratively updating w, the loss function Loss i Gradually reduce, the convolution kernel weight approaches the optimized value. Repeat the above update process for each training batch until the training round is over. Check the weight update amplitude. If the change is small for several consecutive rounds, it can be considered that the convolution kernel weight of this layer has converged. When all the convolution kernel weights in the model converge, the training process of the entire convolution layer is completed. By repeating the update process to reach convergence, the optimized convolution kernel weight is obtained.
[0042] Furthermore, for the momentum-optimized convolution kernels, select the top P convolution kernels in terms of absolute weight value of the convolution layer and perform L2 regularization, including: calculating the absolute value |w_k| of the weight vector w_k of each convolution kernel k in the jth layer; selecting the top P convolution kernel sets S according to the ranking from large to small |w_k|; for each convolution kernel k in S, calculate the loss function after L2 regularization: Loss j (w k )=∑(y k -t k ) 2 +λ||w k || 2 , where y k is the output of convolution kernel k, t k is the corresponding label, ||w k || 2 is the L2 regularization term of the weight vector, λ is the regularization coefficient; calculate Loss j Relative to the weight w k The gradient is: use Update the weight w in the convolution kernel k k ; Determine the weight vector w of each convolution kernel after the current iteration k and the weight vector w' after the previous iteration k Is the mean square error lower than the preset threshold ε? If the mean square error is less than ε, it means that the convolution kernel converges and the iteration is skipped.
[0043] Specifically, assume that the jth layer has m convolution kernels, that is, k = 1, 2, ..., m. The parameters of each convolution kernel k are composed of a weight matrix, which is expanded into a vector w k .w k Represents the parameter weight vector of the kth convolution kernel. Calculate the absolute value of each element of the weight vector w_k to obtain the vector |w_k|. That is, for each weight parameter wi in w_k, calculate |wi|. The vector |w_k| reflects the parameter weight intensity distribution of the kth convolution kernel. Repeat this calculation to obtain the absolute value of the weight vector of all convolution kernels in the jth layer. These absolute values will be used to evaluate the importance of different convolution kernels and select the main feature extractor.
[0044] Specifically, the absolute value of the weight vector of each convolution kernel k in the jth layer is calculated |w k |. For all convolution kernels |w k To sort, |w k The larger the | is, the more important the features extracted by the corresponding convolution kernel k are. k| values are sorted from large to small. The top P convolution kernels are selected and recorded as set S. Here P is a predetermined hyperparameter, such as selecting the top-10 convolution kernels. The set S contains the P convolution kernels with the largest absolute value of the j-th layer weight vector. These convolution kernels contribute the most to feature extraction and will be the focus of model compression.
[0045] Specifically, the loss function Loss after L2 regularization is calculated for the convolution kernel in the set S j (w k ): S contains the P important convolution kernels with the largest absolute value of the weight vector of the jth layer. For each convolution kernel k in S, calculate its regularized loss function. k Represents the feature map output of convolution kernel k. k is the true label corresponding to the feature map. ∑(y k -t k ) 2 Calculate the true loss of convolution kernel k. ||w k || 2 Represents the L2 norm of the convolution kernel k weight vector, which is a regularization term. λ is a manually set regularization coefficient. Loss j (w k ) consists of the true loss and the L2 regularization term, which is used to optimize the convolution kernel k. Minimizing this loss function can improve the generalization ability of important convolution kernels.
[0046] Specifically, according to the regularized loss function Loss j The definition of , can calculate its relative weight w k The gradient of is: The first term 2(y k -t k ) corresponds to the actual loss w k The derivative of k Corresponding to the L2 regularization term on w k The derivative of . After that, it can be used to update the weight parameter w of the convolution kernel k. k The update formula is: Where η is the learning rate, which controls the step size of the update. By iteratively using the gradient of the regularized loss function Update weight w k , we can get the convolution kernel weights to prevent overfitting. Repeat this process to optimize all parameters in the important convolution kernel set S.
[0047] Specifically, in the iterative optimization of the convolution kernel weight w k After that, calculate the w obtained in the current iteration k and w' from the previous iteration kThe mean square error between the two. The mean square error formula is: mean square error = ∑(w k -w' k ) 2 / n, where n is the weight vector w k The dimension of ∑(w k -w' k ) 2 Calculate the sum of the square differences of the elements corresponding to the weights. Compare the calculated mean square error with the set threshold ε. If the mean square error is less than ε, it means that the weight change between two iterations is very small, and it can be considered that the convolution kernel has converged. When all selected important convolution kernels have converged, the regularization optimization of the convolution kernel of this layer is completed. Convergence is determined by the mean square error, which avoids unnecessary iterative calculations and improves the efficiency of the algorithm.
[0048] Furthermore, the Internet of Vehicles secure data transmission protocol adopts the 5G communication protocol for data exchange between vehicles and between vehicles and infrastructure. Specifically, the Internet of Vehicles requires real-time and efficient data interaction between vehicles and between vehicles and roadside infrastructure. The 5G communication network has the characteristics of high bandwidth, low latency and high reliability, which is suitable for the access requirements of the Internet of Vehicles. 5G New Radio is used as the wireless access technology of the Internet of Vehicles, supporting service features such as eMBB and URLLC. It supports quality-differentiated transmission based on network slicing, and vehicle-connected safety services have a higher priority. Using 5G network edge computing technology, edge storage and computing of vehicle data are realized to reduce latency. Support 5G-based vehicle location services for precise positioning and map construction of vehicles. Using the 5G communication protocol stack, dense connections between vehicles and base stations are realized, supporting large-scale Internet of Vehicles deployment. 5G technology is used to implement end-to-end security mechanisms to ensure reliable communication of the Internet of Vehicles.
[0049] Furthermore, the pre-trained convolutional neural network is a Google Net model. Among them, the Google Net model is a convolutional neural network structure proposed by the Google team in 2014. Google Net introduced the inception module, which can connect multiple convolution kernels and pooling layers of different sizes in parallel in the network. In this application, the module uses 1x1 convolution for dimensionality reduction, reduces the number of parameters, and connects multiple parallel convolution paths to extract different features. Google Net also has structures such as auxiliary classifiers and global average pooling to further improve the effect. In this solution, a pre-trained Google Net model is used as a feature extractor. The low-level features extracted from the first few layers of the model are used to represent the feature information of the vehicle video frame. Then the classification and regression branches are connected to complete the model training. The use of a pre-trained model can accelerate training and extract significant image features.
[0050] Furthermore, the Google Net model is composed of multiple Inception modules and global average pooling layers in series, and each Inception module contains convolution kernels of different sizes. Specifically, Google Net is composed of multiple stacked Inception modules in series to form a deep network structure. The Inception module contains multiple parallel convolution branches, and each branch uses convolution kernels of different sizes to extract features of different scales. A typical Inception module contains four parallel branches: 1x1, 3x3, 5x5 convolution and 3x3 maximum pooling. 1x1 convolution is used for dimensionality reduction, reducing the number of parameters and the amount of calculation. The output features of each branch are spliced together to form the output features of the Inception module. Repeatedly stacking multiple Inception modules can extract multi-scale feature information. Finally, the features are integrated through the global average pooling layer to form the model output. This structural design expands the width and depth of the network and improves the feature learning ability under the premise of controlling the number of parameters.
[0051] 3. Beneficial effects
[0052] Compared with the prior art, the advantages of this application are:
[0053] (1) By building a convolutional neural network model customized for direction and lane departure tasks, it can better adapt to specific detection tasks. This customized model can capture task-specific features, thereby improving the adaptability and effectiveness of detection performance. The structure and parameter design of the model are targeted at specific tasks, which helps to accurately identify vehicle behavior and status;
[0054] (2) The application of momentum optimization algorithm and L2 regularization technology can accelerate the convergence speed of the model during the training process and effectively reduce the overfitting phenomenon of the model. The momentum optimization algorithm helps to find the global optimal solution faster, while the L2 regularization technology can effectively control the complexity of the model and prevent the model from overfitting on the training data, thereby improving the robustness and generalization ability of the detection model;
[0055] (3) Using the Google Net pre-trained model for feature extraction can fully utilize the feature extraction capabilities that have been pre-trained on large-scale data sets. Such pre-trained models have strong generalization capabilities and can extract richer and more abstract features, which helps improve the model's adaptability to different data sets and scenarios. This feature extraction method can effectively improve the generalization ability of the model, thereby enhancing the performance and reliability of the model;
[0056] In summary, by collecting vehicle images and extracting features using a convolutional neural network model built on TensorFlow, combined with the Google Net model for deep learning analysis, this method significantly improves the accuracy of vehicle safety detection. Through the training and optimization process, the accurate extraction of key features such as driving direction and lane departure distance is achieved, thus effectively solving the problem of low vehicle safety detection accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] This specification will be further described in the form of exemplary embodiments, which will be described in detail by the accompanying drawings. These embodiments are not restrictive, and in these embodiments, the same number represents the same structure, wherein:
[0058] Figure 1 is an exemplary flow chart of a vehicle safety detection method according to some embodiments of this specification;
[0059] Figure 2 is an exemplary flow chart for building a neural network using a TensorFlow framework as shown in some embodiments of this specification;
[0060] Figure 3 is an exemplary flowchart of optimizing a fully connected layer according to some embodiments of the present specification. DETAILED DESCRIPTION
[0061] The method and system provided in the embodiments of this specification are described in detail below with reference to the accompanying drawings.
[0062] Figure 1 This is an exemplary flow chart of a vehicle safety detection method shown in some embodiments of this specification, data acquisition: collect images during vehicle driving as input data. Install a camera in the vehicle to collect images of the road conditions ahead while driving. The camera is installed on the top of the vehicle windshield, and the shooting direction is consistent with the driving perspective. The camera's acquisition frame rate is set to 20FPS and the resolution is 1280x720. The image and video data collected by the camera are saved in real time to the on-board storage device. The storage device can choose an SSD solid-state hard drive with a capacity of 1TB to ensure sufficient storage space. The image data in the storage device is sent to the on-board computer through the vehicle's internal network. In the computer, image processing libraries such as Open CV are used to extract image frames and implement data format conversion as input data for the neural network model. The entire data acquisition process runs automatically to ensure that image input can be continuously and stably obtained during driving. The collected image data can be processed locally on the on-board computer or uploaded to the cloud server for processing through the Internet of Vehicles.
[0063] Figure 2This is an exemplary flowchart of building a neural network based on the TensorFlow framework as shown in some embodiments of this specification. Edge computing: Use a convolutional neural network model built based on the TensorFlow framework, including structures such as convolutional layers and pooling layers, to extract features from the input image, and output vehicle driving direction classification results and lane departure distance regression results. Construct a convolutional neural network model in the TensorFlow framework, including modules such as convolutional layers, maximum pooling layers, and fully connected layers. The convolutional layer uses a filter size of 3x3, a step size of 1, and an activation function ReLU. The number of filters in the first convolutional layer is set to 32. Use TensorFlow's kerasAPI to build a convolutional layer. The first convolutional layer is defined as follows:
[0064] Conv2D(filters=32, kernel_size=3, strides=1, padding='same', activation='relu')
[0065] Filters indicates the number of filters in this layer, which is set to 32 here. Kernel_size indicates the kernel size, which is set to 3x3. Strides indicates the step size, which is set to 1. Padding is set to 'same', which means that zero padding is used and the output image is the same size as the input image. Activation is set to the ReLU activation function. The expression of the ReLU activation function is: f(x) = max(0, x), which can effectively introduce nonlinearity and maintain network sparsity. Subsequent convolutional layers can continue to refer to the example of the first layer and adjust parameters such as the number of filters.
[0066] The pooling layer uses 2x2 maximum pooling with a step size of 2. The number of nodes in the fully connected layer is 256 and 128 respectively, and the activation function uses ReLU. The pooling layer is implemented using MaxPool2D of TensorFlow:
[0067] MaxPool2D(pool_size=2, strides=2)
[0068] Pool_size represents the pooling window size, which is set to 2x2. Strides represents the step size, which is set to 2. This can halve the size of the input feature map. The number of nodes in the fully connected layer is set to 256 and 128:
[0069] Dense(256, activation='relu')
[0070] Dense(128, activation='relu')
[0071] Figure 3This is an exemplary flow chart for optimizing the fully connected layer shown in some embodiments of this specification. Both fully connected layers use the ReLU activation function. The expression of the ReLU function is: f(x) = max(0, x), which can introduce nonlinearity, and is simple to calculate and fast to train. By adjusting the number of nodes, the network complexity can be controlled to avoid overfitting. The final output layer is a dense layer, which contains two output nodes, which represent the direction classification result and the deviation distance regression result respectively. The output layer is implemented using a fully connected layer (dense layer). In TensorFlow, it can be defined as follows: Dense (2); where 2 means that this layer contains 2 nodes. These two nodes represent the two output results of the model respectively. The output of the first node represents the direction classification result. It can take an integer from 1 to 4, indicating 4 directions such as left turn and right turn. The output of the second node represents the lane deviation distance, which is a continuous value. During training, the output of the first node is softmax classified with the one-hot label of the direction. The mean square error of the output of the second node and the actual deviation distance of the regression label is calculated as the loss function. In this way, two output nodes are used to implement classification and regression tasks.
[0072] The model is trained using the Adam optimizer, with a learning rate of 0.001 and a batch size of 128. A training set is constructed, containing 20,000 vehicle driving images of size 320x240. In TensorFlow, the optimizer selects the Adam algorithm: opt = tf.keras.optimizers.Adam(learning_rate = 0.001).
[0073] The learning rate of the Adam optimizer is set to 0.001. The batch size during training is set to 128. A training set is constructed, which contains 20,000 vehicle driving images. The image size is unified to 320x240 pixels. The image source can be a simulated CG image or a real vehicle driving video frame. The image contains vehicles in different directions and lane deviations of different degrees. Each image is labeled with classification and regression labels. After randomly breaking up the data set, batches of size 128 are taken out for model training. The amount of training data can be expanded through data set enhancement to improve the robustness of the model.
[0074] The number of training iterations is set to 30, and the validation set is used to evaluate the model training effect. After obtaining the best model, the newly input vehicle image is loaded, and the model forward propagation is used to extract features. The two sets of results predicted by the model output are the detection features of driving direction and deviation distance. The number of training iterations (epochs) is set to 30. The model parameters are trained through the training set in each iteration. At the same time, the validation set is set, and the data set ratio is training set: validation set = 8:2. After each training round, the model effect is evaluated on the validation set. The loss function value on the validation set is recorded, and the model with the minimum value is selected as the best model. After obtaining the best model, the model parameters are saved. In the test phase, the newly input vehicle driving image is loaded. The image is input into the saved model, and the forward propagation is run to extract the feature vector. The model output layer gives two sets of results, the first set is the driving direction classification result. The second set is the regression result of the lane deviation distance. These two sets of results are the final detection features.
[0075] Data transmission: The feature data extracted by the neural network is securely transmitted to the cloud analysis platform using the Internet of Vehicles technology in the 5G communication protocol. The vehicle is equipped with a 5G communication module and uses 5GNR standard radio access. Using network slicing technology, a dedicated logical subnetwork is established for Vehicle to Cloud (V2C) communication. V2C services have high priority, and operators ensure priority scheduling of resources. The network slice has high speed, low latency, and high reliability performance guarantees. The network slice uses the MEC edge computing platform to achieve low-latency transmission from the vehicle to the edge node. The edge node is connected to the cloud platform, and the transmission from the edge to the cloud has a higher bandwidth. Using 5G advanced security mechanisms, such as AKA authentication and encryption algorithms, the confidentiality and integrity of the uploaded data are guaranteed. The vehicle assembles the feature data according to the message encapsulation format in the transmission protocol and uploads it to the cloud platform through the 5G network. The cloud platform parses the received message and obtains the vehicle feature data for subsequent analysis.
[0076] Cloud analysis: In the cloud platform, use the pre-trained Google Net convolutional neural network model to perform in-depth analysis on the input feature data. Google Net contains multiple Inception modules, each with convolution kernels of different sizes. Finally, the vehicle safety detection results are output. Deploy the pre-trained Google Net model in the cloud server. Google Net contains multiple Inception modules, each with 1x1, 3x3, and 5x5 convolutions. Use Keras or TensorFlow to load the structure and weight parameters of the pre-trained model. Load the Google Net model in Keras:
[0077] From keras.applications.inception_v3importInceptionV3
[0078] pre_trained_model=InceptionV3(weights='image net', include_top=False)
[0079] include_top=False means that the top fully connected layer is not included. Load the model in TensorFlow:
[0080] Import tensor flow as tf
[0081] pre_trained_model=tf.keras.applications.InceptionV3(weights='imagenet', include_top=False)
[0082] Define the model input layer as:
[0083] input_tensor=Input(shape=(n, 240, 320, 3))
[0084] The shape parameter indicates the shape of the input tensor. n is the batch size, 320x240 is the image size, and 3 indicates RGB 3 color channels. The input layer can be connected to the pre-trained model to build a new model. Define an input tensor of shape (n, 320, 240, 3) for the model input layer. n is the batch size, 320x240 is the input image size, and 3 indicates RGB 3 channels.
[0085] Connect the output layer of the Google Net model to the custom fully connected layer and output layer. Freeze the parameters of all layers of the pre-trained model and only train the custom part. Pack the feature data transmitted by the vehicle into batches and input them into the GoogleNet model. Use CUDA on the GPU server to accelerate the model reasoning and analysis process. The final output layer gives the vehicle safety detection results, such as danger warnings. The output of the pre-trained layer of the Google Net model is used as the input layer of the custom model. Customize two fully connected layers with 256 and 128 nodes respectively. The output layer is a dense layer with numerodeclases of nodes, such as 2. Freeze all layer parameters of Google Net and set trainable = False. Only train the custom fully connected layer and output layer, and set trainable = True. Compile the model with the loss function as cross entropy and the optimizer as Adam. Combine the vehicle feature data into batches of size 32. Feed the model in batches for training. Use CUDA on the GPU server to accelerate model reasoning. The output layer gives prediction results, such as the probability of danger level, to achieve safety detection.
[0086] Model training: The convolutional neural network model built based on TensorFlow needs to obtain the best parameters through batch training of the training set. The training process includes steps such as forward propagation to extract features, calculate loss, back propagation to find gradients, and update weights. Momentum optimization and L2 regularization are used to improve generalization capabilities. A convolutional neural network containing convolutional layers, pooling layers, and fully connected layers is built through the tf.keras interface:
[0087] Build a convolutional neural network model based on TensorFlow, including convolutional layers, pooling layers, fully connected layers, etc. import tensor flow as tf
[0088] model = tf.keras.Sequential()
[0089] #The first convolutional layer
[0090] model.add(tf.keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)))
[0091] #First pooling layer
[0092] model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
[0093] #The second convolutional layer
[0094] model.add(tf.keras.layers.Conv2D(64, (3, 3), activation='relu'))
[0095] #The second pooling layer
[0096] model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2)))
[0097] #Flatten layer, converts the two-dimensional feature map into one-dimensional
[0098] model.add(tf.keras.layers.Flatten())
[0099] #Fully connected layer
[0100] model.add(tf.keras.layers.Dense(512, activation='relu'))
[0101] model.add(tf.keras.layers.Dense(10, activation='softmax'))
[0102] Configure an optimizer, such as the Adam optimizer, and a loss function, such as the cross entropy loss.
[0103] The batch size is 128, and the training set is traversed for model training.
[0104] Forward propagation: Input batch data and extract features through convolution and pooling layers.
[0105] Calculate loss: Calculate the cross entropy loss function between the model output and the true label.
[0106] Back propagation: Use the chain rule to calculate the gradient and update the network parameters.
[0107] A momentum optimizer is used to introduce momentum terms to smooth the network update process.
[0108] Add L2 regularization term to the loss function to reduce model overfitting.
[0109] Repeat multiple rounds of training until the model loss function meets the requirements.
[0110] Finally, a set of optimized model parameters is obtained, which has good generalization performance.
[0111] Configure the optimizer and loss function:
[0112] #Configure the optimizer
[0113] optimizer=tf.keras.optimizers.Adam(learning_rate=0.001)
[0114] #Configure loss function
[0115] loss_fn=tf.keras.losses.Categorical Cross entropy()
[0116] #Model compilation
[0117] model.compile(optimizer=optimizer,
[0118] loss = loss_fn,
[0119] metrics = ['accuracy'])
[0120] The optimizer uses the Adam algorithm and sets the learning rate to 0.001. The loss function loss_fn uses the cross entropy loss commonly used in classification tasks. Specify the optimizer and loss function when compiling the model. Also set the metrics to calculate the accuracy.
[0121] Code examples for batch processing, forward propagation, and loss calculation during model training:
[0122] #Set the batch size to 128
[0123] batch size = 128
[0124] #Traverse the training set and perform training
[0125] for images, labels in train_data set:
[0126] #Forward propagation, extract features
[0127] features = model(images)
[0128] #Calculate loss
[0129] loss=loss_fn(labels, features)
[0130] #Back propagation, model training
[0131] loss.backward()
[0132] #Update parameters
[0133] optimizer.step()
[0134] optimizer.zero_grad()
[0135] #At the end of each epoch, print loss
[0136] print('Epoch loss:',loss.item())
[0137] Set the batch size to 128 and sample batches from the training set. Perform forward propagation and input the batch of images to extract features. Calculate the cross entropy loss. Perform back propagation to update the parameters. Print the loss for each epoch.
[0138] Back propagation for gradients, momentum optimizer, regularization, and multiple rounds of training:
[0139] #Calculate gradients
[0140] gradients=tf.gradients(loss, model.trainable_variables)
[0141] #Update parameters
[0142] optimizer.apply_gradients(zip(gradients, model.trainable_variables))
[0143] #Momentum Optimizer
[0144] optimizer=tf.keras.optimizers.SGD(momentum=0.9)
[0145] #L2 Regularization
[0146] loss=loss+lambda*tf.reduce_sum(model.kernel**2)
[0147] #Cycle training:
[0148] for epoch in range(num_epochs):
[0149] for images, labels in data set:
[0150] #Forward propagation
[0151] output = model(images)
[0152] #Calculate loss
[0153] loss=loss_fn(labels,output)
[0154] #Backward Propagation
[0155] gradients=tape.gradient(loss, model.variables)
[0156] optimizer.apply_gradients(zip(gradients, model.variables))
[0157] #Evaluate model accuracy
[0158] test_acc=evaluate(model, test_data set)
[0159] print("Epoch{},testacc:{:.4f}".format(epoch+1,test_acc))
[0160] #Finally get the optimized model parameters
[0161] optimal_weights=model.get_weights()
[0162] Result output: After the Google Net model in the cloud platform completes the feature analysis, it outputs the current safety status detection results of the vehicle and feeds them back to the vehicle or monitoring platform to achieve real-time monitoring of vehicle safety. Import the Google Net model:
[0163] from tensor flow.keras.applications import Google Net
[0164] model=Google Net(weights='image net',include_top=False)
[0165] Define the model input layer to receive image feature data:
[0166] input_tensor=Input(shape=(224, 224, 3))
[0167] Connect the classification output layer:
[0168] output=Dense(2, activation='softmax')(model.output)
[0169] Assemble the complete model:
[0170] full_model=Model(inputs=input_tensor, outputs=output)
[0171] Make predictions:
[0172] feature_data=...#Feature data from the vehicle
[0173] result=full_model.predict(feature_data)
[0174] ifresult[0][1]>0.8:
[0175] print('Dangerous state detected')
[0176] Determine the dangerous state:
[0177] danger_threshold = 0.8
[0178] ifresult[0][1]>danger_threshold:
[0179] danger_state = True
[0180] else:
[0181] danger_state=False
[0182] Encapsulate JSON data packet:
[0183] data={'danger':danger_state,
[0184] 'prob': result[0][1]}
[0185] json_data = json.dumps(data)
[0186] Sent via 5G network:
[0187] importsocket
[0188] #Establish TCP connection
[0189] client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)client.connect(("VEHICLE_IP",8888))
[0190] #Send JSON data
[0191] client.send(json_data.encode('utf-8'))
[0192] client.close()
[0193] The vehicle-side server receives and parses the JSON data packet:
[0194] data = json.loads(recv_data)
[0195] danger=data['danger']
[0196] Determine dangerous conditions and respond:
[0197] ifdanger:
[0198] #Send an alert
[0199] play_alarm_sound()
[0200] #Control vehicle deceleration
[0201] control_module.reduce_speed(15)
[0202] Send the results to the monitoring center: #Upload the monitoring video stream in real time via 4G network
[0203] upload_video_stream()
[0204] #Show the results on the monitoring screen
[0205] display_on_screen(danger)
[0206] By continuously receiving and responding to results, real-time monitoring and early warning of the vehicle's safety status can be achieved.
[0207] The invention of the present application and its implementation methods are described schematically above. The description is not restrictive. Without departing from the spirit or basic features of the present application, the present application can be implemented in other specific forms. What is shown in the accompanying drawings is only one of the implementation methods of the invention of the present application. The actual structure is not limited to this, and any figure mark in the claims should not limit the claims involved. Therefore, if ordinary technicians in this field are inspired by it, without departing from the purpose of the present invention, they can creatively design structural methods and embodiments similar to the technical solution, which should all belong to the scope of protection of the present application. In addition, the word "including" does not exclude other elements or steps, and the word "one" before the element does not exclude the inclusion of "multiple" elements. The multiple elements stated in the product claim can also be implemented by one element through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any specific order.
Claims
1. A method for vehicle safety detection, include: Collect vehicle images; Through edge computing, feature data of vehicle images are extracted, including the vehicle's driving direction and lane deviation distance; The extracted feature data is transmitted to the cloud analysis platform through the Internet of Vehicles secure data transmission protocol; Through the pre-trained convolutional neural network, the extracted feature data is analyzed and the vehicle safety detection results are output; Edge computing uses the TensorFlow framework to build a neural network and extract feature data from vehicle images; The collected vehicle images are used as training sets; Build a convolutional neural network model based on the TensorFlow framework, which includes an input layer, a convolution layer, a pooling layer, and a fully connected layer. The input layer is used to receive vehicle images, the convolution layer and the pooling layer are used for feature extraction, and the fully connected layer is used to output detection results. Set driving direction as classification label and lane departure distance as regression label; Using the training set, the convolutional neural network model is constructed through back propagation algorithm training; Using the trained convolutional neural network model, feature data of the collected vehicle images are extracted; The feature data of the vehicle image is extracted, including: The edge detection algorithm Sobel is used to extract the edge contour of the vehicle from the collected vehicle image; According to the extracted edge contours, the driving direction of the vehicle is determined through a convolutional neural network; the driving direction includes driving forward, turning left or turning right; According to the extracted edge contours, regression analysis is performed through a convolutional neural network to output the vehicle's lane deviation distance.
2. The vehicle safety detection method according to claim 1, Features: The convolutional neural network model constructed by back-propagation algorithm training includes: Set the convolutional layer optimizer and the fully connected layer optimizer. The convolutional layer optimizer is used to adjust the convolutional layer parameters, and the fully connected layer optimizer is used to adjust the fully connected layer parameters. Use forward propagation to extract the spatial features of the input data through the convolutional layer; According to the extracted spatial features, the prediction result y of the convolutional neural network model is output through the fully connected layer 1 and 2 ; Calculation result y 1 Cross entropy loss function Loss with the direction label 1 , calculate the measurement result y 2 Mean square error loss function Loss of lane deviation distance 2 ; Apply the chain rule to calculate the weight matrix W in the fully connected layer relative to the cross entropy loss function Loss 1 Gradient Apply the chain rule to calculate the bias vector b in the fully connected layer relative to the mean square error loss function Loss 2 Gradient Using Gradients Update the weight matrix W using the gradient Update the bias vector b; Repeat the forward propagation and fully connected layer parameter update steps until the number of fully connected layer training rounds reaches the preset maximum number of rounds.
3. The vehicle safety detection method according to claim 2, Features: The convolutional neural network model constructed by back-propagation algorithm training also includes: After the fully connected layer training is completed, the momentum factor γ in the convolutional layer optimizer is set to 0.9, where the momentum factor is used to control the influence ratio of the previous round of gradients on the current iteration; Using the convolutional layer optimizer with a momentum factor γ of 0.9, the Loss function is used to perform momentum optimization on the convolutional layer parameters; For the momentum-optimized convolution kernels, select the convolution kernels with the top P absolute values of the weights of the convolution layer and perform L2 regularization.
4. The vehicle safety detection method according to claim 3, Features: Using the convolutional layer optimizer with a momentum factor of N, the convolutional layer parameters are optimized using the Loss function, including: Calculate the loss function of the current iteration of the i-th layer convolution kernel weight w: Loss i (w)=∑(y i -t i ) 2 +λ||w|| 2 Among them, y i is the output feature map of the i-th convolution kernel, t i is the corresponding label, ||w|| 2 is the L2 regularization term of the convolution kernel weight vector of the i-th layer, and λ is the regularization coefficient; Calculate Loss i Gradient relative to the convolution kernel weight w of the i-th layer: Use the preset momentum factor γ to adjust the current gradient of the i-th layer: Among them, v i is the velocity vector in the update process of the i-th layer convolution kernel weight vector, and is the γ momentum optimization factor; Using the velocity vector v i Update the convolution kernel weights of the i-th layer: w′=w-v i Repeat the above steps until the weights of each convolution kernel converge.
5. The vehicle safety detection method according to claim 3, Features: For the momentum-optimized convolution kernels, select the convolution kernels with the top P absolute values of the weights of the convolution layer and perform L2 regularization, including: Calculate the weight vector w for each convolution kernel k in the jth layer k The absolute value of |w k |; According to |w k |Rank from largest to smallest and select the top P convolution kernel sets S; For each convolution kernel k in S, calculate the loss function after L2 regularization: Loss j (w k )=∑(y k -t k ) 2 +λ||w k || 2 Among them, y k is the output of convolution kernel k, t k is the corresponding label, ||w k || 2 is the L2 regularization term of the weight vector, and λ is the regularization coefficient; Calculate Loss j Relative to the weight w k The gradient is: use Update the weight w in the convolution kernel k k ; Determine the weight vector w of each convolution kernel after the current iteration k and the weight vector w' after the previous iteration k Is the mean square error lower than the preset threshold ε? If the mean square error is less than ε, it means that the convolution kernel converges and the iteration is skipped.
6. The vehicle safety detection method according to any one of claims 1 to 5, Features: The Internet of Vehicles secure data transmission protocol uses the 5G communication protocol for data exchange between vehicles and between vehicles and infrastructure.
7. The vehicle safety detection method according to claim 6, Features: The pre-trained convolutional neural network is the Google Net model.
8. The vehicle safety detection method according to claim 7, Features: The Google Net model consists of multiple Inception modules and global average pooling layers connected in series, and each Inception module contains convolution kernels of different sizes.
