Vehicle detection method and device with scene adaptive function

By using the lightweight vehicle detection model Yolo-nano and knowledge distillation technology on edge-side devices, the problem of unstable vehicle detection accuracy in complex traffic scenarios is solved, real-time adaptation and efficient detection of the model are achieved, and detection accuracy is improved. and generalization ability.

CN114022425BActive Publication Date: 2024-10-01LIANYUNGANG JARI ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111241891.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-25
Publication Date
2024-10-01
Estimated Expiration
2041-10-25

AI Technical Summary

Technical Problem

Existing vehicle detection models based on deep learning have unstable detection accuracy in complex traffic scenes, making it difficult to implement edge-side real-time video analysis, and fixed models cannot be updated in real time to adapt to scene changes.

Method used

A lightweight vehicle detection model, Yolo-nano, is designed. It uses knowledge distillation technology to transfer the characteristics of complex network models to simple network models to achieve real-time iterative update and scene adaptation of the model, using multi-task training and feature pyramid structure improvement. Detection accuracy and efficiency.

Benefits of technology

It achieves efficient vehicle detection in edge-side devices, automatically updates the model to adapt to different scenarios, improves detection accuracy and generalization capabilities, and reduces the cost of manual annotation and model deployment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114022425B_ABST
    Figure CN114022425B_ABST
Patent Text Reader

Abstract

The present invention discloses a vehicle detection method and device with scene adaptation function. The method adopts a deep learning model, and can automatically adjust the model parameters in real time according to the changes in the scene to realize the scene adaptation function. The method includes: a video processing module and a model update module. The video processing module obtains the image frame through the video acquisition device, pre-processes the image, and then loads the vehicle detection model to detect the vehicle in the image. The vehicle detection model loaded here is a dynamic model updated in real time by the model update module; the model update module stores the latest image, and uses the knowledge distillation technology to pass the features learned by the complex network model on the latest image to the simple model to realize the update of the simple model, and then evaluates the accuracy of the simple model, selects the optimal model for model deployment, and applies it to the video processing model. This method can effectively solve the problems of poor computational efficiency of complex models and insufficient generalization ability of simple models, and significantly improve the speed and accuracy of vehicle detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of intelligent transportation and machine vision, and in particular relates to a vehicle detection method and device with scene adaptation function. Background Art

[0002] Vehicle detection algorithms can be roughly divided into three categories: moving target detection algorithms based on inter-frame differences or background modeling, traditional machine learning algorithms based on feature extraction and vehicle classification, and end-to-end vehicle detection algorithms based on deep learning. With the continuous improvement of computer computing power and the continuous expansion of data scale, vehicle detection algorithms based on deep learning have become more and more advantageous than traditional algorithms, with high detection accuracy and strong scene adaptability.

[0003] End-to-end object detection based on deep learning can be divided into two methods: one-stage and two-stage. The two-stage method follows the traditional object detection process, which includes three parts: candidate region selection, feature extraction, and classification / regression. Among them, the more classic algorithm is the Region-based CNN (R-CNN) series of networks, which has undergone continuous improvements from R-CNN to Fast R-CNN to Faster R-CNN. The one-stage algorithm simplifies the two-stage steps, converts the object detection problem into a classification and regression problem, introduces a unified framework, and directly maps the input image pixels to the target box and target category, which greatly improves the speed. The more classic ones are the Single Shot MultiBox Detector (SSD) and You Only Look Once (YOLO) series.

[0004] The YOLO series algorithm system is relatively comprehensive, and has proposed a series of algorithm models for different detection accuracy and detection efficiency. Among them, YOLOv3-Tiny and YOLOv4-Tiny have very fast detection speeds, but low detection accuracy. The newly proposed YOLOv4-P7 model has the highest detection accuracy in academia. However, this type of model also has high requirements on computing power, making it difficult to achieve real-time video processing on edge devices.

[0005] Actual traffic scenes are complex and changeable. The height of the camera, the angle, and the weather changes will affect the detection accuracy of the deep learning model. Complex deep neural network models (such as YOLOv4-P7) have strong scene adaptability, but the amount of calculation is large, and it is difficult to achieve real-time edge video analysis. Simple shallow neural network models (such as YOLOv3-Tiny) have small calculations and are suitable for real-time edge video analysis, but they have weak scene adaptability and can only achieve relatively ideal detection results for a single application scenario.

[0006] Previous deep learning-based vehicle detection model deployment solutions generally use fixed models. First, data is collected for application scenarios, the data set is annotated, and then the vehicle detection model is trained in the data center to obtain model parameters. Finally, the trained model is deployed to edge devices for vehicle detection. In this type of deployment solution, the vehicle detection model is fixed and cannot be updated in real time. Due to the generalization ability of the model, when the scene changes, the detection effect of the model will be greatly reduced. Summary of the invention

[0007] The technical problem to be solved by the present invention is to propose a vehicle detection method and device with scene adaptation function in response to the shortcomings of the existing technology, and to design a lightweight simple network model that can run efficiently in edge-side devices. With the help of knowledge distillation technology, real-time information transmission from complex network models to simple network models is realized, and real-time iterative upgrades of the model are realized to achieve scene adaptation effects.

[0008] The technical problem to be solved by the present invention is achieved through the following technical solution: a vehicle detection method with scene adaptation function, the method comprising the following steps:

[0009] Read the real-time video stream, decode the video, and obtain the image frame;

[0010] Preprocess the image frames, including: color space conversion (YUV2RGB), image scaling, and image normalization;

[0011] Loading the first vehicle detection model, performing vehicle detection on the preprocessed image frame, and obtaining vehicle position and category information;

[0012] Store the preprocessed images and build a temporary training data set;

[0013] Based on the temporary training data set, the features learned by the second vehicle detection model are transferred to the first vehicle detection model by using the knowledge distillation method, so as to update the parameters of the first vehicle detection model; the second vehicle detection model is more complex than the first vehicle detection model;

[0014] The performance of the updated first vehicle detection model is evaluated, and the model that meets the performance requirements is screened out, and the model is deployed for loading and use by the vehicle detection module.

[0015] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution. The first vehicle detection model adopts the Yolo-nano model, which is improved based on Yolov3-tiny, replaces the traditional convolution with 1x1 convolution and depth convolution, adds a residual unit, and adopts a two-layer feature pyramid structure for multi-scale vehicle detection. The size of anchors is given by a clustering algorithm; specifically:

[0016] The first layer of the model uses a normal convolution layer with a convolution kernel size of 3x3 and 8 features, followed by a layer of 1x1 convolution and 3x3 depth convolution. The feature number of the 1x1 convolution is 16, and the depth convolution is implemented using group convolution. The number of groups is equal to the number of input features, and the feature number of the depth convolution is 16; then three CSP modules are connected, each CSP module is followed by a maximum pooling operation, and the kernel size and stride of the pooling layer are both 2; each CSP module first converts the input into two outputs through a 1x1 convolution, and the feature number of each output is half of the input feature number, and then the second output is connected to a residual module and a 1x1 convolution layer to obtain the third output, and then these three outputs are merged to obtain the output of each CSP module. The number of output channels of the CSP module is twice the number of input channels.

[0017] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution, wherein the temporary training data set is composed of a real-time video database, a historical video database and an invalid database, and the specific construction process includes:

[0018] Step 1-1, collect a real-time video image every second, and put the pre-processed result into the real-time video database;

[0019] Step 1-2, set the latest video duration, remove the video images exceeding this duration from the real-time video database, and put them into the historical video database;

[0020] Step 1-3, setting the maximum capacity of the historical video database, and removing the historical video images exceeding the capacity from the historical video database;

[0021] Step 1-4, establishing a failure database, and putting the video images in which the first vehicle detection model fails to detect into the database.

[0022] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution. The specific process of establishing the failure database described in steps 1-4 includes:

[0023] Step 1-4-1, randomly select a video image from the real-time video database;

[0024] Step 1-4-2, using the first vehicle detection model and the second vehicle detection model to perform vehicle detection on the video image respectively, using the vehicle label detected by the second vehicle detection model as the true label, and calculating the precision and recall rate of the detection result of the first vehicle detection model;

[0025] In step 1-4-3, images with precision or recall below a given threshold are placed into the failure database.

[0026] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution: the second vehicle detection model adopts the Yolov3 network model, and multi-task training is performed on open source data sets and self-built data sets to obtain the model parameters. The selected open source data sets include COCO, UA-DETRAC, BDD100K and MIO-TCD. The self-built data sets are obtained by collecting video data of different scenes and manually annotating them;

[0027] The multi-task training is implemented based on a multi-task network model. The structure of the multi-task network model is as follows: the Darknet53 network of Yolov3 is used as a common feature extraction network, placed at the forefront of the network, the original image is input, and the image features are output; then a Yolov3 multi-scale detection branch head is added, and the detection branch head is formed in the following manner: the original three detection branch heads of Yolov3 are expanded to 3*n detection branch heads, wherein n is the number of selected data sets (n is 5 in the present invention), the size of the anchors of the Yolo layer in each branch is obtained by performing a clustering algorithm on the corresponding data set, and the loss function is defined by using GIOU instead of the original MSE.

[0028] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution: multi-task training is performed on the Yolov3 network model, and the specific process includes:

[0029] Step 2-1: Collect open source datasets such as COCO, UA-DETRAC, BDD100K, and MIO-TCD, collect video data for different traffic scenes, manually annotate the detection target location and target category, and build a self-built dataset;

[0030] Step 2-2, expanding the data set and randomly dividing the data set into a training set, a validation set and a test set; the expansion method includes: rotating, translating, scaling and mirroring the data set, adding random white noise, and changing brightness, chroma and saturation;

[0031] Step 2-3: In each iteration cycle of model training, a Yolov3 network model branch corresponding to a data set is randomly selected, and then a batch of data is randomly read from the training data corresponding to the corresponding branch, and sent to the network model for forward and backward reasoning, and the loss function corresponding to the branch is calculated, and the model parameters are updated using the stochastic gradient method;

[0032] Step 2-4, repeat steps 2-3 until the Yolov3 network model converges.

[0033] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution, which is based on the temporary training data set and uses the knowledge distillation method to pass the features learned by the second vehicle detection model to the first vehicle detection model to achieve parameter update of the first vehicle detection model. The specific process includes:

[0034] Step 3-1, using the second vehicle detection model to detect the video images in each database of the temporary training data set, and storing the obtained vehicle position and category as a label;

[0035] Step 3-2, randomly selecting annotated video images from the real-time video database, the historical video database, and the invalid video database in a ratio of 6:2:2 as a training data set for knowledge distillation;

[0036] Step 3-3: Use the training data set obtained in step 3-2 to train the first vehicle detection model and update the model parameters of the model.

[0037] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution, wherein the performance of the updated first vehicle detection model is evaluated to select a model that meets the performance requirements, and the specific process includes:

[0038] Step 4-1, randomly select N pictures from the real-time video database;

[0039] Step 4-2: for each image, use the first vehicle detection model and the second vehicle detection model to perform vehicle detection on the image;

[0040] Step 4-3: Use the detection results of the second vehicle detection model as labels to calculate the average precision and average recall of the first vehicle detection model; the precision and recall calculation formulas are as follows:

[0041] In step 4-4, if the average precision or average recall is lower than the given threshold, the model accuracy is considered to not meet the requirements and the model is discarded.

[0042] The technical problem to be solved by the present invention is achieved through the following technical solution: a vehicle detection device with scene adaptation function, the device comprising:

[0043] A video decoding unit, used for decoding the acquired video stream to obtain an image frame;

[0044] An image preprocessing unit, used for performing preprocessing operations on the image;

[0045] A vehicle detection unit, used to detect vehicles in images and obtain vehicle location and category information;

[0046] Knowledge distillation unit, used to transfer features learned by complex network models to relatively simple network models;

[0047] The storage unit is used to store the video image frames and the vehicle detection results.

[0048] Furthermore, the technical problem to be solved by the present invention can also be achieved through the following technical solution, wherein the vehicle detection unit is capable of performing forward reasoning on the convolutional neural network and post-processing the network data results to obtain vehicle location and category information.

[0049] Furthermore, the technical problem to be solved by the present invention can also be achieved by the following technical solution, wherein the knowledge distillation unit comprises:

[0050] Neural network inference unit, used for forward inference of complex network models and simple network models;

[0051] The neural network training unit is used to train simple network models.

[0052] For the specific definition of the vehicle detection device with scene adaptive function, please refer to the definition of the vehicle detection method with scene adaptive function mentioned above, which will not be repeated here. Each module in the above-mentioned vehicle detection device with scene adaptive function can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0053] Compared with the prior art, the present invention has the following significant advantages:

[0054] 1. The present invention proposes a scene-adaptive vehicle detection method, which can realize automatic updating of vehicle detection models for different application scenarios without human intervention (collecting on-site image data, performing manual annotation, using a central server to train the model, and deploying the trained model on the side). Traditional vehicle detection algorithms are often trained on specific data sets, and the detection effect can achieve very high accuracy on this data set, but it cannot adapt to complex and changeable actual traffic scenes. In order to improve the generalization ability of the model, we need to build a complex deep network model and use enough data for training. While the generalization ability of the model is improved, the efficiency of model detection is reduced, making it difficult to realize real-time video analysis on the edge side. Simple shallow network models have low computational complexity and are easy to realize real-time analysis on the edge side. However, their model generalization ability is weak and their scene adaptability is poor. In order to improve the detection accuracy of the model in different scenarios, the present invention fully combines the advantages of complex deep network models and simple shallow network models, and proposes a scene-adaptive vehicle detection method. First, a scene dataset is constructed using a video acquisition unit. Then, knowledge distillation is performed on the dataset to pass the features learned by the complex deep network model to a simple shallow network model to update the parameters of the simple shallow network model. Then, the performance of the updated model is evaluated, the high-precision model is retained, and the models that do not meet the requirements are eliminated. Finally, the retained model is passed to the video stream analysis module to achieve scene adaptation of the model.

[0055] 2. The present invention proposes a new multi-task training method for vehicle detection models, which can make full use of existing annotated data resources and improve the accuracy of model training. Different data sets have different labels, although the scenarios in which they are applied may be similar. For example, there are both vehicles and pedestrians in traffic scenarios. Some data sets only annotate vehicles, and some data sets only annotate pedestrians. Even the vehicle category labels of the data sets annotated with vehicles are not exactly the same. Due to these differences between data sets, it is difficult to simply merge them to train the model. In order to make full use of existing data sets and self-built data sets, the present invention proposes a multi-task training method, which realizes the joint training of different data sets, expands the data set scale for model training, and improves the detection accuracy and generalization ability of the model.

[0056] 3. The Yolo-nano model proposed in the present invention improves Yolov3-tiny by replacing traditional convolution with 1x1 convolution and depth convolution. At the same time, a residual module is added and a two-layer feature pyramid structure is used for multi-scale vehicle detection. The model size and inference speed are greatly improved, which is suitable for real-time inference of multiple videos in embedded ARM CPU.

[0057] The present invention is further described in detail below in conjunction with the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 The present invention is a flow chart of a vehicle detection method with scene adaptation function in one embodiment.

[0059] Figure 2 FIG. 4 is a diagram of a Yolo-nano network structure in one embodiment.

[0060] Figure 3 Schematic diagram of Yolov3 multi-task training framework in one embodiment.

[0061] Figure 4 A schematic diagram of a vehicle detection device with scene adaptation function in one embodiment.

[0062] Figure 5 This is a comparison chart of offline training results of Yolov3-tiny and Yolo-nano in one embodiment.

[0063] Figure 6 This is a graph of Yolo-nano online training results in one embodiment. DETAILED DESCRIPTION

[0064] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0065] In one embodiment, a vehicle detection method with scene adaptation function is provided, which uses knowledge distillation and model evaluation to continuously and automatically improve model parameters, improve model detection accuracy, and achieve scene adaptation. Figure 1 As shown, the method includes a video processing module and a model updating module.

[0066] The video processing module includes the following steps:

[0067] Step 1: Read the real-time video stream, decode the video, and obtain the image frame

[0068] The real-time video stream obtains the original encoded NALU unit data through the rtsp protocol, and then passes the NALU data to the software or hardware decoder for video decoding to obtain the image frame. This method supports both H264 and H265 encoding methods.

[0069] Step 2: Preprocess the image frame, including color space conversion, image scaling, image normalization, etc.

[0070] If the image frame obtained by decoding is not RGB encoded, it needs to be converted to RGB space. The most common conversion is from YUV color space to RGB color space. The size of the decoded image is often different from the input image size of the vehicle detection network model. For example, the output video image size of a high-definition camera is 1920x1080, and the input image size of Yolov3-nan is 416x416. At this time, the obtained image needs to be scaled to 416x416. The value range of each component in the RGB image is 0-255. Before the RGB image is input into the neural network, it needs to be normalized so that the range of each component becomes 0-1. Here, the RGB value of each pixel in the image needs to be divided by 255.

[0071] Step 3: Perform vehicle detection on the preprocessed image frames

[0072] This step first requires loading a predefined network model, namely the first vehicle detection model, performing forward reasoning on the preprocessed image frames, and then post-processing the output results of the deep learning network model to obtain information such as vehicle location and category.

[0073] The vehicle detection model loaded here uses the Yolo-nano model, and its structure is as follows Figure 2 As shown in the figure, the model is specially developed for low-power devices and can realize single-core real-time vehicle detection on ARM CPU. The model is improved based on Yolov3-tiny, replacing the traditional convolution with 1x1 convolution and depth convolution. At the same time, residual units are added, and a two-layer feature pyramid structure is used for multi-scale vehicle detection. The size of anchors is given by the clustering algorithm.

[0074] The first layer of the model uses a normal convolution layer with a convolution kernel size of 3x3 and a feature number of 8, followed by a layer of 1x1 convolution and a 3x3 depth convolution. The feature number of the 1x1 convolution is 16, and the depth convolution is implemented by group convolution. The number of groups is equal to the number of input features, and the feature number of the depth convolution is 16. Then three CSP modules are connected, and each CSP module is followed by a maximum pooling operation. The kernel size and stride of the pooling layer are both 2. Each CSP module first converts the input into two outputs through a 1x1 convolution. The number of features of each output is half of the number of input features. The purpose of this process is to reduce the number of features and reduce the amount of calculation. Then, the second output is connected to a residual module and a 1x1 convolution layer to obtain the third output. Then, these three outputs are combined to obtain the output of each CSP module. The number of output channels of the CSP module is twice the number of input channels.

[0075] The preprocessing step uses the classic NMS operation to filter out repeated vehicle boxes.

[0076] The model update module contains the following steps:

[0077] Step 1: Store preprocessed images and build a temporary training dataset

[0078] Temporary data uses a frequency of one frame per second to collect video images in real time, and saves the preprocessed results into the real-time video database. At the same time, the latest video duration is set to control the total size of the stored images. Historical images that exceed this duration are regularly removed from the database and placed in the historical video database. In order to control the total size of the historical database, the maximum capacity of the historical database is set, and historical video images that exceed this capacity are removed from the historical video database. At the same time, an invalid database is established, and video images that fail to be detected by the simple model are placed in the database. The temporary training data set is composed of images that have been randomly selected from the real-time video database, the historical video database, and the invalid video database in a ratio of 6:2:2.

[0079] Step 2: Perform knowledge distillation training on the temporary training dataset

[0080] Knowledge distillation training is to transfer the features learned by the complex vehicle detection network model to the simple vehicle detection network model. First, the complex vehicle detection network model is used to annotate the images in the database, then the results of the complex network model annotation are used as labels to construct a training data set, and finally, the simple vehicle detection network model is trained on the training data set.

[0081] The complex vehicle detection network model uses the Yolov3 model and uses multi-task training to train the model. The data sets used for multi-task training include COCO, UA-DETRAC, BDD100K, MIO-TCD and self-built data sets. The basic process is as follows: Figure 3 As shown in the figure, this multi-task training model uses the Darknet53 network of Yolov3 as a shared feature extraction network and expands the original three detection branch heads of Yolov3 to 3*n detection branch heads, where n is the number of selected data sets, and the size of the anchors of the Yolo layer in each branch is given by the clustering algorithm on the corresponding data set.

[0082] When training the model, we first need to collect the corresponding data set, unify the data annotation method to the darknet method, and then rotate, translate, scale and mirror the training data set, add random white noise, brightness, chroma and saturation changes, expand the data set, and randomly divide the data set into training set, validation set and test set. During training, in each iteration cycle, a Yolov3 branch corresponding to a data set is randomly selected, and then a batch of data is randomly read from the data set corresponding to the corresponding branch, and sent to the network model for forward and backward reasoning, and the loss function corresponding to the branch is calculated, and the model parameters are updated using the stochastic gradient method.

[0083] Step 3: Evaluate the performance of the updated model to implement model screening

[0084] First, N pictures are randomly selected from the real-time database. Then, the complex model and the simple model are used to detect vehicles in each picture. The detection results of the complex model are used as labels to calculate the average precision and recall rate of the simple model. Finally, the models are screened according to the average precision and recall rate. If the average precision or the average recall rate is lower than the given threshold, the model accuracy is considered to not meet the requirements and the model is discarded.

[0085] In one embodiment, a vehicle detection device with scene adaptation function is provided, such as Figure 4 As shown, it includes a video decoding unit, an image preprocessing unit, a vehicle detection unit, a knowledge distillation unit and a storage unit. The video decoding unit is used to decode the received real-time compressed video stream to obtain image frames, and supports both H264 and H265 formats. The image preprocessing unit is used to preprocess the decoded image frames and convert them into the image format and size required by the vehicle detection network. The vehicle detection network is used to detect vehicles on the input images and supports the forward reasoning function of the deep convolutional neural network. The knowledge distillation unit is used to pass the features learned by the complex model to the simple model. The unit must support both the forward and backward reasoning functions of the deep convolutional neural network and support model training. The storage unit is used to store video image frames and vehicle detection results.

[0086] Figure 5 A comparison chart of offline training results of Yolov3-tiny and Yolo-nano is given. It can be seen that although the reasoning speed of Yolo-nano is greatly improved after lightweighting, the model generalization ability and detection accuracy are greatly reduced. Compared with Yolov3-tiny, mAP is reduced by about 10%.

[0087] Figure 6An example of using the scene-adaptive vehicle detection method and device of the embodiment of the present disclosure to perform multi-scene vehicle detection is given, in which the Yolov3-tiny model is obtained by offline training, and the Yolo-nano is trained in a scene-adaptive manner. The test video in this example is spliced ​​from video clips of different scenes at multiple intersections. Figure 5 and Figure 6 It can be seen that although the detection accuracy of Yolo-nano is much lower than that of Yolov3-tiny in the offline training mode, with the help of the scene adaptive vehicle detection method proposed in the embodiment of the present disclosure, the detection accuracy of Yolo-nano is greatly improved, and the average accuracy is higher than that of Yolov3-tiny. At the same time, the scene adaptation ability is also much better than the Yolov3-tiny model obtained by offline training.

[0088] The scene-adaptive vehicle detection method and device provided by the above-mentioned embodiments of the present invention have greatly improved the detection accuracy and generalization ability of the traditional vehicle detection model. It has a scene-adaptive function and can automatically adjust its own model parameters according to different application scenarios to achieve real-time scene adaptation. It does not need to collect data for different application scenarios, manually label, and perform background training as in traditional methods, which greatly reduces the difficulty of deploying the model in different scenarios and the consumption of manpower and time costs.

[0089] The above shows and describes the basic principles, main features and advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A vehicle detection method with scene adaptation function, characterized in that: The method comprises the following steps: Read the real-time video stream, decode the video, and obtain the image frame; Preprocess the image frames, including: color space conversion, image scaling, and image normalization; Loading the first vehicle detection model, performing vehicle detection on the preprocessed image frame, and obtaining vehicle position and category information; Store the preprocessed images and build a temporary training data set; Based on the temporary training data set, the features learned by the second vehicle detection model are transferred to the first vehicle detection model by using the knowledge distillation method, so as to update the parameters of the first vehicle detection model; the second vehicle detection model is more complex than the first vehicle detection model; The performance of the updated first vehicle detection model is evaluated, and the model that meets the performance requirements is screened out, and the model is deployed for loading and use by the vehicle detection module.

2. The vehicle detection method with scene adaptation function according to claim 1, characterized in that: The first vehicle detection model adopts the Yolo-nano model, which is improved based on Yolov3-tiny. The traditional convolution is replaced by 1x1 convolution and depth convolution. At the same time, a residual unit is added, and a two-layer feature pyramid structure is used for multi-scale vehicle detection. The size of anchors is given by a clustering algorithm. Specifically: The first layer of the model uses a normal convolution layer with a convolution kernel size of 3x3 and 8 features, followed by a layer of 1x1 convolution and 3x3 depth convolution. The feature number of the 1x1 convolution is 16, and the depth convolution is implemented using group convolution. The number of groups is equal to the number of input features, and the feature number of the depth convolution is 16; then three CSP modules are connected, each CSP module is followed by a maximum pooling operation, and the kernel size and stride of the pooling layer are both 2; each CSP module first converts the input into two outputs through a 1x1 convolution, and the feature number of each output is half of the input feature number, and then the second output is connected to a residual module and a 1x1 convolution layer to obtain the third output, and then these three outputs are merged to obtain the output of each CSP module. The number of output channels of the CSP module is twice the number of input channels.

3. The vehicle detection method with scene adaptive function according to claim 1 or 2, characterized in that: The temporary training data set is composed of a real-time video database, a historical video database and an invalid database. The specific construction process includes: Step 1-1, collect a real-time video image every second, and put the pre-processed result into the real-time video database; Step 1-2, set the latest video duration, remove the video images exceeding this duration from the real-time video database, and put them into the historical video database; Step 1-3, setting the maximum capacity of the historical video database, and removing the historical video images exceeding the capacity from the historical video database; Step 1-4, establishing a failure database, and putting the video images in which the first vehicle detection model fails to detect into the database.

4. The vehicle detection method with scene adaptation function according to claim 3, characterized in that: The failure database is established as described in steps 1-4. The specific process includes: Step 1-4-1, randomly select a video image from the real-time video database; Step 1-4-2, using the first vehicle detection model and the second vehicle detection model to perform vehicle detection on the video image respectively, using the vehicle label detected by the second vehicle detection model as the true label, and calculating the precision and recall rate of the detection result of the first vehicle detection model; In step 1-4-3, images with precision or recall below a given threshold are placed into the failure database.

5. The vehicle detection method with scene adaptation function according to claim 1, characterized in that: The second vehicle detection model adopts the Yolov3 network model, and multi-task training is performed on open source datasets and self-built datasets to obtain the model parameters. The selected open source datasets include COCO, UA-DETRAC, BDD100K and MIO-TCD. The self-built dataset is obtained by collecting video data of different scenes and manually annotating them. The multi-task training is implemented based on a multi-task network model. The structure of the multi-task network model is: the Darknet53 network of Yolov3 is used as a common feature extraction network, placed at the forefront of the network, the original image is input, and the image features are output; then the Yolov3 multi-scale detection branch head is added, and the detection branch head is formed in the following way: the original three detection branch heads of Yolov3 are expanded to 3*n detection branch heads, wherein n is the number of selected data sets, the size of the anchors of the Yolo layer in each branch is obtained by performing a clustering algorithm on the corresponding data set, and the loss function is defined by using GIOU instead of the original MSE.

6. The vehicle detection method with scene adaptation function according to claim 5, characterized in that: The Yolov3 network model is trained with multiple tasks, and the specific process includes: Step 2-1: Collect open source datasets such as COCO, UA-DETRAC, BDD100K, and MIO-TCD, collect video data for different traffic scenes, manually annotate the detection target location and target category, and build a self-built dataset; Step 2-2, expanding the data set and randomly dividing the data set into a training set, a validation set and a test set; the expansion method includes: rotating, translating, scaling and mirroring the data set, adding random white noise, and changing brightness, chroma and saturation; Step 2-3: In each iteration cycle of model training, a Yolov3 network model branch corresponding to a data set is randomly selected, and then a batch of data is randomly read from the training data corresponding to the corresponding branch, and sent to the network model for forward and backward reasoning, and the loss function corresponding to the branch is calculated, and the model parameters are updated using the stochastic gradient method; Step 2-4, repeat steps 2-3 until the Yolov3 network model converges.

7. The vehicle detection method with scene adaptation function according to claim 3, characterized in that: Based on the temporary training data set, the knowledge distillation method is used to transfer the features learned by the second vehicle detection model to the first vehicle detection model to update the parameters of the first vehicle detection model. The specific process includes: Step 3-1, using the second vehicle detection model to detect the video images in each database of the temporary training data set, and storing the obtained vehicle position and category as a label; Step 3-2, randomly selecting annotated video images from the real-time video database, the historical video database, and the invalid video database in a ratio of 6:2:2 as a training data set for knowledge distillation; Step 3-3: Use the training data set obtained in step 3-2 to train the first vehicle detection model and update the model parameters of the model.

8. The vehicle detection method with scene adaptation function according to claim 7, characterized in that: The performance evaluation of the updated first vehicle detection model is performed to select a model that meets the performance requirements. The specific process includes: Step 4-1, randomly select N pictures from the real-time video database; Step 4-2: for each image, use the first vehicle detection model and the second vehicle detection model to perform vehicle detection on the image; Step 4-3, using the detection result of the second vehicle detection model as a label, calculating the average precision and average recall of the first vehicle detection model; In step 4-4, if the average precision or average recall is lower than the given threshold, the model accuracy is considered to not meet the requirements and the model is discarded.

9. A vehicle detection device with scene adaptation function, characterized in that: The device comprises: A video decoding unit, used for decoding the acquired video stream to obtain an image frame; An image preprocessing unit, used for performing preprocessing operations on the image; A vehicle detection unit, used to detect vehicles in images and obtain vehicle location and category information; Knowledge distillation unit, used to transfer features learned by complex network models to relatively simple network models; The storage unit is used to store the video image frames and the vehicle detection results.

10. The vehicle detection device with scene adaptation function according to claim 9, characterized in that: The vehicle detection unit can perform forward reasoning on the convolutional neural network and post-process the network data results to obtain vehicle location and category information; The knowledge distillation unit comprises: Neural network inference unit, used for forward inference of complex network models and simple network models; The neural network training unit is used to train simple network models.