A YOLOv7-tiny lightweight vehicle target detection method and system

By constructing a roadside vehicle dataset of various models and conditions, improving the YOLOv7-tiny network, and applying a pruning strategy, the problem of high computational complexity of YOLOv7 in resource-constrained environments is solved, and efficient vehicle target detection is achieved.

CN119649316BActive Publication Date: 2025-10-03CHANGAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411616286.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-10-03
Estimated Expiration
2044-11-13

AI Technical Summary

Technical Problem

The existing YOLOv7 vehicle target detection algorithm has high computational complexity in resource-constrained environments, making it difficult to maintain high detection accuracy and low computational complexity at the same time.

Method used

A roadside vehicle dataset with various vehicle models, lighting conditions, and weather conditions was constructed. Through image filtering, enhancement, and dataset partitioning, the YOLOv7-tiny network was improved, and a pruning strategy was applied for lightweight processing to design a lightweight vehicle target detection model.

Benefits of technology

It significantly improves the performance and efficiency of vehicle target detection, is suitable for deployment in resource-constrained environments, reduces computational complexity while maintaining high detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119649316B_ABST
    Figure CN119649316B_ABST
Patent Text Reader

Abstract

The present invention provides a YOLOv7-tiny lightweight vehicle target detection method and system, relating to the fields of computer vision and deep learning technology. The method includes: constructing a roadside vehicle dataset; performing image filtering, image enhancement, and dataset partitioning on the roadside vehicle dataset; constructing an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network; applying a pruning strategy to lightweight the initial vehicle target detection model to obtain a lightweight vehicle detection model; inputting the partitioned dataset into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model; and inputting an image to be detected into the final vehicle target detection model to obtain a detection result. The present invention significantly improves the performance and efficiency of vehicle target detection through multiple improvements to YOLOv7-tiny, and reduces computational complexity through lightweight model design, making it suitable for deployment in resource-constrained environments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of computer vision and deep learning technologies, and in particular to a YOLOv7-tiny lightweight vehicle target detection method and system. Background Art

[0002] The vehicle target detection algorithm is the underlying foundation for the implementation of the vehicle target global tracking and trajectory association algorithm for multiple cameras. Accurate and efficient detection results are of great significance for subsequent vehicle target tracking under single camera and vehicle target tracking under multiple cameras.

[0003] With the development of autonomous driving technology, vehicle object detection has become a key technology in intelligent transportation systems. While existing object detection algorithms, such as YOLOv7, offer excellent accuracy, they require high computational resources, making them unsuitable for deployment in resource-constrained environments. Therefore, developing a lightweight detection technology that maintains high detection accuracy while reducing computational complexity is crucial. Summary of the Invention

[0004] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide a YOLOv7-tiny lightweight vehicle target detection method and system, which can improve detection accuracy while reducing computational complexity.

[0005] To achieve the above object, the present invention provides the following solutions:

[0006] A YOLOv7-tiny lightweight vehicle target detection method, including:

[0007] Construct a roadside vehicle dataset containing vehicle images of various models, in different lighting and weather conditions;

[0008] Performing image filtering, image enhancement, and dataset division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set;

[0009] Constructing an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network;

[0010] Applying a pruning strategy to lightweight the initial vehicle target detection model to obtain a lightweight vehicle detection model;

[0011] Inputting the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model;

[0012] The image to be detected is input into the final vehicle target detection model to obtain the detection result.

[0013] Preferably, the target types in the roadside vehicle dataset include: cars, buses, vans and others.

[0014] Preferably, performing image filtering, image enhancement, and data set division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set includes:

[0015] Performing filtering on the image in the roadside vehicle dataset to obtain a filtered image;

[0016] Constructing an image enhancement window, and using the image enhancement window to traverse the filtered image to perform denoising to obtain a denoised image;

[0017] Performing histogram equalization processing on the denoised image to obtain an enhanced image;

[0018] The enhanced images are divided into data sets according to a preset ratio to obtain the training set, the validation set and the test set.

[0019] Preferably, filtering the image in the roadside vehicle dataset to obtain a filtered image comprises:

[0020] Performing wavelet decomposition on the roadside vehicle dataset at multiple scales to obtain corresponding wavelet coefficients;

[0021] A filtering threshold is constructed according to the size and decomposition scale of the roadside vehicle dataset; the formula for the filtering threshold is: Among them, λ j represents the filtering threshold at the jth decomposition scale, σ j represents the noise standard deviation at the jth decomposition scale, N j represents the signal length at the jth decomposition scale, where j represents the decomposition scale;

[0022] The image filtering model is constructed using the filtering threshold; the formula of the image filtering model is: Where sign is the sign function, a is the first preset coefficient, b is the second preset coefficient, ω j,k represents the kth wavelet coefficient at the jth decomposition scale, represents the wavelet coefficients after filtering;

[0023] The image of the roadside vehicle dataset is filtered using the image filtering model to obtain the filtered image.

[0024] Preferably, constructing an image enhancement window and using the image enhancement window to traverse the filtered image to perform denoising to obtain a denoised image includes:

[0025] Detecting the filtered image using an image recognition model to obtain a proportion value under each image enhancement window;

[0026] When the proportion value in the image enhancement window is greater than a preset threshold, median denoising is performed on the image in the corresponding image enhancement window to obtain a median denoised image;

[0027] The image enhancement window is slid until the entire filtered image is traversed to obtain the denoised image.

[0028] Preferably, the filtered image is detected using an image recognition model to obtain a proportion value under each image enhancement window, including:

[0029] Using formula F ij =|x ij -y ij |Get the pixel difference of each pixel under each image enhancement window; where F ij Represents the pixel difference of the image at position (i, j), x ij Represents the pixel value of the image at position (i, j), y ij represents the pixel value of the filtered image at position (i, j);

[0030] Pixels whose pixel difference is greater than the feature threshold are regarded as feature points and the number is recorded;

[0031] The ratio of the feature points to all pixels in the image enhancement window is taken as the proportion value.

[0032] Preferably, the initial vehicle target detection model comprises: an input network, a backbone network, a neck network and a detection head connected in sequence;

[0033] The input network is used to perform data enhancement and image preprocessing operations on the input image set to obtain a preprocessed image; the backbone network is used to extract image features from the preprocessed image based on the ELAN model and the MP model to obtain a feature map; the neck network is used to perform feature fusion and enhancement on the feature map to obtain a fusion map; the detection head is used to perform feature detection based on the fusion map to obtain a detection result.

[0034] Preferably, the backbone network of the backbone network is a MobileNetV3 network.

[0035] Preferably, the pruning strategies include: importance-based layer adaptive pruning, channel weight-based pruning, and growth regularization-based pruning.

[0036] A YOLOv7-tiny lightweight vehicle target detection system, including:

[0037] A dataset construction module is used to construct a roadside vehicle dataset containing vehicle images of various models, under different lighting and weather conditions;

[0038] A data set processing module, configured to perform image filtering, image enhancement, and data set division on the roadside vehicle data set to obtain a training set, a validation set, and a test set;

[0039] A model improvement module is used to build an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network;

[0040] A lightweight module, configured to apply a pruning strategy to perform lightweight processing on the initial vehicle target detection model to obtain a lightweight vehicle detection model;

[0041] A training module, configured to input the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model;

[0042] The detection module is used to input the image to be detected into the final vehicle target detection model to obtain the detection result.

[0043] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0044] The present invention provides a YOLOv7-tiny lightweight vehicle target detection method and system, the method comprising: constructing a roadside vehicle dataset containing vehicle images of various vehicle models and under different lighting and weather conditions; performing image filtering, image enhancement, and dataset partitioning on the roadside vehicle dataset to obtain a training set, a validation set, and a test set; constructing an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on a YOLOv7-tiny network; applying a pruning strategy to lightweight the initial vehicle target detection model to obtain a lightweight vehicle detection model; inputting the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model; and inputting an image to be detected into the final vehicle target detection model to obtain a detection result. The present invention significantly improves the performance and efficiency of vehicle target detection through multiple improvements to YOLOv7-tiny, and reduces computational complexity through lightweight model design, making it suitable for deployment in resource-constrained environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0046] Figure 1 A flow chart of a method provided by an embodiment of the present invention;

[0047] Figure 2 A schematic diagram of a technical route provided by an embodiment of the present invention;

[0048] Figure 3 This is a schematic diagram of an example of the conversion of the Zhiyuan-Wanji roadside dataset provided by an embodiment of the present invention; Figure 3 (a) is the format of the marked file; Figure 3 (b) is the data after conversion;

[0049] Figure 4 Schematic diagram of an example of Rope3D dataset conversion provided by an embodiment of the present invention; Figure 4 (a) is the format of the marked file; Figure 4 (b) is the data after conversion;

[0050] Figure 5 Schematic diagram of an example of UA-DETRAC data set conversion provided by an embodiment of the present invention; Figure 5 (a) is the original .xml tag format information; Figure 5 (b) is the markup format information after conversion;

[0051] Figure 6 A distribution diagram of various types of vehicle samples in the dataset provided by the embodiment of the present invention;

[0052] Figure 7 An improved network model structure diagram provided by an embodiment of the present invention;

[0053] Figure 8 A schematic diagram of a method for calculating the SIoU loss function provided in an embodiment of the present invention;

[0054] Figure 9 A diagram of the pruning process provided by an embodiment of the present invention;

[0055] Figure 10 A schematic diagram of the loss changes during the training process provided by an embodiment of the present invention;

[0056] Figure 11 A schematic diagram comparing the experimental results of the improved network provided by an embodiment of the present invention and YOLOv7-tiny. DETAILED DESCRIPTION

[0057] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.

[0058] The purpose of the present invention is to provide a YOLOv7-tiny lightweight vehicle target detection method and system, which significantly improves the performance and efficiency of vehicle target detection by improving YOLOv7-tiny in many aspects.

[0059] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0060] Figure 1 A flow chart of the method provided in the embodiment of the present invention is shown in FIG. Figure 1 As shown, the present invention provides a YOLOv7-tiny lightweight vehicle target detection method, including:

[0061] Step 100: Construct a roadside vehicle dataset containing vehicle images of various vehicle types and under different lighting and weather conditions;

[0062] Step 200: performing image filtering, image enhancement, and dataset division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set;

[0063] Step 300: Constructing an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network;

[0064] Step 400: Applying a pruning strategy to perform lightweight processing on the initial vehicle target detection model to obtain a lightweight vehicle detection model;

[0065] Step 500: Input the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model;

[0066] Step 600: Input the image to be detected into the final vehicle target detection model to obtain a detection result.

[0067] Preferably, the target types in the roadside vehicle dataset include: cars, buses, vans and others.

[0068] Specifically, in order to improve the accuracy and reliability of traffic target detection, this embodiment requires a large amount of high-quality image data as support, which will be used to train and verify the target detection algorithm. At present, most data sets for traffic scenes are collected by on-board cameras, such as the BDD100K data set, the KITTI data set, and the ApolloScape data set. Due to the differences between on-board cameras and roadside surveillance cameras in terms of viewing angles, lighting conditions, and target distances, these factors may affect the performance of the target detection algorithm. Therefore, this embodiment aims to reduce the impact of these differences on traffic target detection results by collating and annotating data sets from roadside perspectives. By collating different open source data sets and manually annotating, a roadside vehicle target data set with a total of 23,811 images in four categories was produced. The existing open source roadside data sets are mainly processed to meet the needs of this embodiment, including the Zhiyuan-Wanji data set, the Rope3D data set, and the UA-DETRAC data set.

[0069] This embodiment uses 2D image data from the Zhiyuan-Wanji roadside dataset, which is a large-scale roadside dataset designed for vehicle-road collaborative autonomous driving. The dataset contains 2,500 frames of 3D point cloud data and 5,000 frames of 2D image data. The 3D point cloud data is collected by a 32-line mechanical rotating LiDAR (WLR-32R), providing annotation information such as the three-dimensional coordinates of the target center point, target category, length, width, height, and heading angle. The 2D image data is collected by a camera with a resolution of 1080P, providing target frame position and annotation information of different categories. The Zhiyuan-Wanji dataset covers a variety of complex urban traffic environments, including busy intersections, changeable climatic conditions, and rich traffic scenes. These diverse data are crucial for training robust traffic target detection models. It supports 3D point cloud detection, 2D image detection, and lidar and image fusion detection tasks. The data annotation quality is high and meets industry standards. This example focuses on the 2D image-based target detection task. Therefore, only the RGB image data in the dataset is used and analyzed and processed in detail to extract and learn the key features of traffic targets.

[0070] The file format of the labels in the Zhiyuan-Wanji Roadside Dataset is .txt, which is the same file format that can be used for YOLO algorithm training. The annotation file format in this dataset is as follows: Figure 3 As shown in (a), compared with the labels required by the YOLO algorithm, the last column of target ID is added and converted to Figure 3 (b) The five columns of data in the figure are type, horizontal coordinate of the center of the detection frame, vertical coordinate of the center of the detection frame, width of the detection frame, and height of the detection frame.

[0071] Aiming at the research of vehicle target perception tasks from the roadside perspective, Baidu's open-source Rope3D dataset provides large-scale and multi-perspective vehicle target data, which is suitable for a variety of research scenarios. The dataset contains a total of 50,009 frames of images. The dataset has the following characteristics: (1) The dataset is collected by using roadside cameras with different configurations, including varying focal lengths, pitch angles, and installation heights, thus simulating various monitoring conditions in the real world; (2) The dataset contains a variety of different environmental conditions and traffic conditions, such as daytime, nighttime, dusk, and different weather conditions, as well as various traffic conditions from congestion to smooth traffic, from low traffic to high traffic. These rich scenarios help train models to adapt to the changing actual application environment; (3) To protect personal privacy and comply with relevant laws and regulations, sensitive information in the dataset, such as vehicle license plate numbers and human faces, has been effectively desensitized to ensure data security and compliance; (4) The data is complete, including desensitized original images, annotated data, and calibration files. Although the Rope3D dataset was originally designed for 3D and point cloud detection tasks, this embodiment successfully constructed a dataset suitable for 2D detection of roadside vehicle targets by utilizing the detailed annotation information it provides and performing appropriate processing and conversion on the dataset.

[0072] The annotation file format in the Rope3D dataset is as follows Figure 4 As shown in (a), this format does not meet the annotation file requirements used by the YOLO algorithm. YOLO annotation files only need to use Figure 4 The first, fifth, sixth, seventh, and eighth columns of the data shown in (b) are processed to obtain the format required by the YOLO algorithm. Other parameter data can be directly ignored.

[0073] UA-DETRAC is a dataset specifically designed for urban autonomous driving research. It features diverse scenarios, large data size, and high annotation accuracy. The UA-DETRAC dataset consists of 10 hours of video captured at 24 different locations in Beijing and Tianjin. The video recordings were conducted in the urban traffic environments of Beijing and Tianjin, capturing real-world traffic scenes at 25 frames per second and a resolution of 960×540 pixels. The UA-DETRAC dataset manually annotates over 8,250 vehicles, totaling 1.21 million labeled bounding boxes. The annotation files contain detailed vehicle information, such as vehicle speed, type, occlusion, truncation rate, and precise bounding box coordinates, which are crucial for understanding traffic flow and vehicle behavior.

[0074] The UA-DETRAC dataset uses the XML format by default. To make the UA-DETRAC dataset suitable for the YOLO target detection framework, this embodiment converts the original .xml tags to generate .txt format tags suitable for YOLO, as shown in the following example: Figure 5 As shown, Figure 5 (a) is the original .xml tag format information, Figure 5 (b) is the converted label format information. Furthermore, the UA-DETRAC dataset is generated from 25 frames per second video. Therefore, the dataset contains many image frames with identical scenes and minimal changes in target positions. To address this issue and reduce the number of similar frames in the dataset and improve training efficiency, this embodiment uses a frame skipping strategy when processing the UA-DETRAC dataset. This strategy selects an image every certain number of frames to reduce scene repetitiveness, and extracts an image every 10 frames into the final dataset.

[0075] The target categories annotated between different datasets are different, but in order to ensure the consistency and interoperability of different datasets in subsequent tracking algorithms, this embodiment reclassifies and summarizes the integrated dataset according to the category standard defined by the UA-DETRAC dataset. The categories of the final dataset are car, bus, van, and other. In addition, the video data of a tunnel in Wuxi was segmented frame by frame, and the labelme image annotation tool was used to manually annotate according to the category definition of the UA-DETRAC dataset, thereby obtaining the annotation file and the corresponding image file, and then obtaining the final roadside vehicle detection dataset. Then, this embodiment performed image processing on the dataset. After that, in order to achieve good performance evaluation and generalization ability test during the model training process, this embodiment divided the dataset into training set, test set, and validation set according to the common practice method, with the proportions of 70%, 20%, and 10%, respectively. The training set has 16,667 images, the test set has 4,763 images, and the validation set has 2,381 images. The distribution of each label category in the dataset is as follows Figure 6 shown.

[0076] Preferably, performing image filtering, image enhancement, and data set division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set includes:

[0077] Performing filtering on the image in the roadside vehicle dataset to obtain a filtered image;

[0078] Constructing an image enhancement window, and using the image enhancement window to traverse the filtered image to perform denoising to obtain a denoised image;

[0079] Performing histogram equalization processing on the denoised image to obtain an enhanced image;

[0080] The enhanced images are divided into data sets according to a preset ratio to obtain the training set, the validation set and the test set.

[0081] Preferably, filtering the image in the roadside vehicle dataset to obtain a filtered image comprises:

[0082] Performing wavelet decomposition on the roadside vehicle dataset at multiple scales to obtain corresponding wavelet coefficients;

[0083] A filtering threshold is constructed according to the size and decomposition scale of the roadside vehicle dataset; the formula for the filtering threshold is: Among them, λ j represents the filtering threshold at the jth decomposition scale, σ j represents the noise standard deviation at the jth decomposition scale, N j represents the signal length at the jth decomposition scale, where j represents the decomposition scale;

[0084] The image filtering model is constructed using the filtering threshold; the formula of the image filtering model is: Where sign is the sign function, a is the first preset coefficient, b is the second preset coefficient, ω j,k represents the kth wavelet coefficient at the jth decomposition scale, represents the wavelet coefficients after filtering;

[0085] The image of the roadside vehicle dataset is filtered using the image filtering model to obtain the filtered image.

[0086] Specifically, from the above filter threshold formula, it can be seen that as the decomposition scale increases, the threshold of each layer decreases accordingly, which is in line with the law of wavelet denoising, and thus can improve the performance of wavelet denoising.

[0087] Exemplarily, the present invention utilizes an image filtering model to perform self-adjusting threshold transformation on the wavelet coefficients at each scale, thereby highlighting the detailed features of the image at different decomposition levels, suppressing image noise, and enhancing the layering of the image.

[0088] Preferably, constructing an image enhancement window and using the image enhancement window to traverse the filtered image to perform denoising to obtain a denoised image includes:

[0089] Detecting the filtered image using an image recognition model to obtain a proportion value under each image enhancement window;

[0090] When the proportion value in the image enhancement window is greater than a preset threshold, median denoising is performed on the image in the corresponding image enhancement window to obtain a median denoised image;

[0091] The image enhancement window is slid until the entire filtered image is traversed to obtain the denoised image.

[0092] Furthermore, the original filtering algorithm, such as the mean filtering algorithm, performs mean processing on the pixel points in each neighborhood (i.e., the denoising window) on the image (regardless of whether there are noise points), so the image after processing will be distorted. The present invention can find the characteristic noise points on the image by utilizing the image enhancement window, and then process the corresponding characteristic noise points to smooth out the noise points in the image while retaining the original pixel information on the image as much as possible.

[0093] Preferably, the filtered image is detected using an image recognition model to obtain a proportion value under each image enhancement window, including:

[0094] Using formula F ij =|x ij -y ij |Get the pixel difference of each pixel under each image enhancement window; where F ij Represents the pixel difference of the image at position (i, j), x ij Represents the pixel value of the image at position (i, j), y ij represents the pixel value of the filtered image at position (i, j);

[0095] Pixels whose pixel difference is greater than the feature threshold are regarded as feature points and the number is recorded;

[0096] The ratio of the feature points to all pixels in the image enhancement window is taken as the proportion value.

[0097] Optionally, this embodiment performs median denoising on the image within the image enhancement window, alleviating the problem of existing denoising methods (such as mean filtering denoising) causing certain image features to disappear, thereby preserving the original pixel information of the image to the greatest extent possible. Furthermore, this embodiment utilizes histogram equalization to process the image, which can improve image interpretation.

[0098] Preferably, the initial vehicle target detection model comprises: an input network, a backbone network, a neck network and a detection head connected in sequence;

[0099] The input network performs data augmentation and image preprocessing on the input image set to produce preprocessed images. The backbone network extracts image features from the preprocessed images based on the ELAN model and the MP model to produce feature maps. The neck network fuses and enhances the features of the feature maps to produce fused maps. The detection head performs feature detection based on the fused maps to produce detection results. The backbone network is based on the MobileNetV3 network.

[0100] To address the problem of high computing power when deploying the current vehicle target detection algorithm, this embodiment designs an improved YOLOv7-tiny vehicle target detection algorithm. Figure 7 The following diagram shows the improved network model structure of this embodiment. First, the backbone network is replaced with MobileNetV3, and GSConv is used in the neck part to greatly reduce redundant information, reduce the model's computational complexity, and accelerate model reasoning. In the head part, the self-attention dynamic detection head DyHead and the decoupled head DecoupledHead are introduced to improve object detection performance.

[0101] Furthermore, the loss function of this embodiment is designed as follows:

[0102] When the aspect ratio of the detection box and the ground truth box is equal, the aspect ratio penalty is 0. In addition, the width and height in CIoU have opposite gradients relative to the penalty term, that is, the width and height cannot increase or decrease at the same time. To address the above problems, this embodiment uses SIoULoss as the loss function. SIoU further considers the angle between the detection box and the ground truth box, and redefines the calculation method of the penalty term. It mainly consists of four items: angle cost, distance cost, shape cost, and IoU cost. The main calculation method is as follows: Figure 8 shown.

[0103] The calculation formula of SIoULoss is shown below.

[0104]

[0105] Among them, IoU is the intersection over union ratio, Δ is the distance cost after considering the angle cost, and Ω is the shape cost. The calculation formula is shown as follows:

[0106]

[0107] ρ in the formula x , ρ y ,γ,w t and w w The calculation formula is shown below. θ is used to control the attention to the shape cost Ω, which is set to 4 in the experiment.

[0108]

[0109] γ=2-Λ

[0110]

[0111] in, Represents the center point coordinates of the true value frame, Represents the center point coordinate of the detection box, Λ represents the angle cost, and its calculation formula is shown in the following formula.

[0112]

[0113] Among them, σ represents the distance between the centers of the ground-truth box and the detection box, and c h is the height difference between the centers of the ground-truth box and the detection box.

[0114] Preferably, the pruning strategy includes: layer adaptive pruning based on importance, pruning based on channel weights, and pruning based on growth regularization.

[0115] Specifically, these improvements in this embodiment enable the network to improve the algorithm accuracy on the basis of lightweight. To further optimize the efficiency and performance of the network model, in this embodiment, different pruning strategies are used to prune the modified network model, and the unnecessary parameters and connections in the neural network are adjusted through the pruning strategy to better balance the lightweight degree and accuracy of the model. The research in this embodiment is mainly based on the Torch_Pruning library for pruning, and mainly uses the layer adaptive pruning strategy based on importance, the pruning strategy based on channel weights, and the pruning strategy based on growth regularization in this library.

[0116] Furthermore, research shows that selecting good layer-by-layer sparsity can achieve a state-of-the-art balance between sparsity and performance for the importance-based pruning strategy. Similar to the early neural networks that extracted features by manually setting parameters, layer-by-layer sparsity also needs to be manually selected or searched through a large number of search algorithms. Later, a LAMP pruning strategy (Layer-adaptive Sparsity For The Magnitude-Based Pruning, importance-based layer adaptive pruning strategy) was proposed. This algorithm is a rescaled version of the weight importance and does not require any hyperparameters while considering the model distortion problem.

[0117] Consider a feedforward neural network with depth d, whose weight tensors are W (1) ,…,W (d) , and these weight tensors are all related to each fully connected layer or convolutional layer, but their corresponding dimensions are different. For a fully connected layer, the corresponding weight tensor is a two-dimensional matrix, while for a two-dimensional convolutional layer, the corresponding weight tensor is four-dimensional. To unify the scoring of fully connected layers and convolutional layers, assume that each weight tensor is expanded into a one-dimensional tensor. For these expanded tensors, assume that after corresponding them according to the index, the weights are arranged in ascending order, that is, when u < v, |W[u]| ≤ |W[v]|, where |W[u]| represents the entry mapped through index u, and the importance-based layer adaptive pruning score corresponding to it is shown in the following formula.

[0118]

[0119] This measures the importance of the target connection relative to other surviving connections in the same layer, where connections with smaller weight importance in the same layer are pruned. As can be seen from the formula, when two connections with the same weight importance appear in the same layer, the criterion for whether to prune depends on the order of the indexes.

[0120] The above formula is used to calculate the importance-based layer-adaptive pruning score of each connection. Then, a global scan is performed to find the connection with the lowest importance-based layer-adaptive pruning score and prune it until the set global sparsity constraint is met. This method is equivalent to performing importance pruning using automatically selected inter-layer sparsity, as can be seen from the following formula.

[0121]

[0122] For any tensor W and indices u, v, this formula holds. In practice, global pruning using importance-based layer-adaptive pruning scores is different from global pruning using weighted importance scores |W[u]|. When using importance-based layer-adaptive pruning scores for global pruning, if there is a connection with an importance-based layer-adaptive pruning score of 1, then the importance-based layer-adaptive pruning score for this connection is likely to be the largest. This means that the importance-based layer-adaptive pruning score ensures that at least one connection is retained per layer during global pruning, while global pruning using weighted importance scores |W[u]| may prune all connections.

[0123] Furthermore, compared to the original importance-based pruning algorithm, importance-based layer-adaptive pruning scores do not require additional hyperparameter tuning and can be implemented through simple tensor operations. Furthermore, importance-based layer-adaptive pruning scores are computationally very low, saving computing resources to a certain extent.

[0124] Furthermore, as the depth of convolutional neural networks increases, the network's representational capabilities gradually increase, but the computing resources required also gradually increase. For example, a 152-layer residual network requires up to 60 million parameters. The deployment of convolutional neural networks in practical applications is often affected by model size, runtime memory, and the number of computational operations. Other model compression methods can only address one or two of these issues and require specialized software or hardware acceleration. Fine-grained sparsification methods offer greater flexibility and more compact compressed models, but require specialized software or hardware for fast inference. Coarse-grained sparsification methods do not require additional support but are less flexible. The algorithm described in this section leverages channel sparsity to perform model pruning without relying on software or hardware acceleration, minimizing model training overhead. This algorithm automatically identifies unimportant channels during training and subsequently prunes them, resulting in a compact and highly accurate model, achieving a balance between flexibility and implementability. At the output of each layer, the response of each channel is multiplied by its corresponding scaling factor γ to adjust channel importance. During network training, these scaling factors γ are learned together with the network weights to ensure that the model can adaptively adjust the weights of each channel. In order to promote the sparsity of the model and avoid overfitting, sparse regularization is applied to these scaling factors. In this way, the model can identify and retain those channels that are more critical to the final task, while suppressing those channels that contribute less. After the training process is completed, the scaling factors γ are analyzed, and pruning operations are performed on those channels with smaller scaling factors γ. This step effectively reduces the complexity of the model and improves computational efficiency. Finally, the pruned network is fine-tuned to restore and optimize its performance. The specific calculation method of this method is shown in the following formula:

[0125]

[0126] Where (x, y) represents the training input and target; W represents the training weight; ∑ (x,y) l(f(x,W),y) represents the training loss of a convolutional neural network; g(·) represents the penalty of sparsity on the scaling factor γ, which balances these two terms.

[0127] The pruning process involves evaluating the impact of each channel and simplifying the network by removing those channels with smaller contributions. The advantage of this method is that it can achieve network compactness without relying on special software or hardware acceleration techniques, such as Figure 9As shown in Figure 2, the introduction of the scaling factor γ provides an effective metric for channel selection. These factors are jointly optimized with the network weights, allowing the model to automatically identify and retain channels that contribute significantly to the task during training. This ensures that unimportant channels can be safely removed during pruning while maintaining the network's generalization ability.

[0128] The Batch Normalization (BN) layer is a standard method for most CNNs to achieve fast convergence and improve generalization performance. Therefore, the scaling factor on the channel can be integrated during the activation process. The BN layer uses small batch statistics to normalize the internal activations as shown in the following formula. Let z in and z out are the input and output of the BN layer respectively, and B represents the current mini-batch.

[0129]

[0130] Among them, μ B and σ B are the mean and standard deviation of the input activations on B; γ and β are trainable parameters that provide the possibility to linearly transform the normalized activations back to any scale.

[0131] With this strategy, after channel sparsification training is complete, the model will obtain a set of scaling factors close to zero. Based on these factors, channels that contribute less to the model output can be identified and pruned, including their associated input and output connections and weights. To achieve a controlled pruning process, a threshold can be set. For example, if the threshold is set to 70%, the channels ranked in the bottom 70% of the corresponding scaling factors will be pruned, thus forming a more streamlined network structure. It is worth noting that a higher pruning ratio may lead to a decrease in model accuracy.

[0132] Furthermore, regularization has long been used to learn sparsity in deep neural network pruning. However, its effectiveness has been primarily explored within a small penalty strength range. This algorithm proposes a simple yet effective regularization augmentation scheme that transfers model expressiveness to the remaining parts during pruning. Furthermore, by using gradually increasing regularization to implicitly exploit the Hessian matrix, this approach allows for more accurate selection of unimportant weights. The method is easy to implement and scalable to large datasets and networks.

[0133] Pruning can be described as a transformation T(*) whose input is a pre-trained large model w and whose output is a small model w1. Pruning is usually followed by a fine-tuning process F(*), and the final output is w2. The calculation formula of w2 is as follows. F(*) is a standard neural network training process, which does not need to be paid too much attention to. Instead, we should pay more attention to the process of converting w to w1. Pruning can be further converted into two sub-transformations: (1) M = T1(w), which obtains a binary mask vector M that determines which weights will be removed; (2) T2(w) is used to adjust the values ​​of the remaining weights. The calculation formula of the final output w1 is as follows.

[0134] w2=F(w1)

[0135] w1=T(w)=T1(w)⊙T2(w)=M⊙T2(w)

[0136] For one-shot pruning, there is no iterative training in T1, and it depends on the specific algorithm to decide whether to adjust the remaining weights. For learning-based pruning, both T1 and T2 involve iterative training, and the retained weights will always be adjusted.

[0137] The first method in the algorithm is a variant of L1 norm pruning, which obtains the mask M by L1 norm sorting and adjusts the retained weights by regularization. Specifically, given a pre-trained model w and layer pruning ratio γ l , sort the filters according to the L1 norm, set the mask M to 0 for those filters with the smallest norm, and then drive those unimportant weights to 0 through a gradually increasing L2 penalty. The calculation method is as follows.

[0138] λ j =λ j +δλ,j∈{j|,M[j]=0}

[0139] Among them, λ j is the penalty factor for the jth weight; δλ is the granularity of increasing the penalty. Obviously, the smaller δλ is, the smoother the regularization process is. j Only per K u It is updated once in 1 iteration, which is a buffer time to allow the network to adapt to the new regularization. j When the preset upper limit τ is reached, the training is terminated and the weights with the smallest L1 norm are pruned, and then fine-tuning is performed. Pruning has almost no effect on accuracy, and unimportant weights have been compressed to typically less than one thousandth of the remaining weights.

[0140] The second method in the algorithm utilizes a gradual growth regularization method for scoring. Neural network training is prone to overfitting, so regularization techniques are often used. L2 regularization is a standard technique for training deep networks. Given a dataset D and model parameters w, the total loss is defined as follows.

[0141]

[0142] Where L represents the task loss function. When the training converges, the following equation should exist:

[0143]

[0144] in, indicates that the i-th weight is at its minimum value.

[0145] Specifically, to verify the effectiveness of the algorithm proposed in this embodiment, several authoritative evaluation indicators in the field of object detection were used to verify the effectiveness of the algorithm proposed in this embodiment, mainly including mAP, mAP@.5:.95, and model size. Precision and Recall are used to measure the accuracy of the algorithm classification, and their calculation requires four indicators:

[0146] TP (True Positives) indicates that the target of interest is correctly identified during the target detection process; TN (True Negatives) indicates that the target of non-interest is correctly identified; FP (False Positives) indicates that the target of non-interest is identified as the target of interest, resulting in a false detection; FN (False Negatives) indicates that the target of interest is identified as the target of non-interest, resulting in a missed detection.

[0147] Precision represents the ratio of correctly detected targets to the total detected targets, as shown below.

[0148]

[0149] Recall represents the ratio of correctly detected targets to the total detected targets, as shown below.

[0150]

[0151] To better evaluate object detection performance, we use the average precision (AP) and mean average precision (mAP). mAP is calculated by calculating the weighted average of the AP for each detection category. The area of ​​the enclosed region plotted with Recall and Precision as the horizontal and vertical coordinates is the average AP. The mAP calculation formula is as follows.

[0152]

[0153] Among them, C is the number of categories; AP i is the AP value of class i. mAP@.5:95 represents the average mAP under different intersection-over-union thresholds.

[0154] Optionally, the quantitative and qualitative analysis of the object detection results of this embodiment is as follows. The dataset used in this embodiment includes car, bus, van, and other vehicles. The dataset is divided into training, test, and validation sets in a ratio of 7:2:1. The training set contains 16,667 images, the test set contains 4,763 images, and the validation set contains 2,381 images.

[0155] (1) Quantitative analysis of target detection results

[0156] In order to evaluate the performance of the improved algorithm proposed in this study in the vehicle target detection task, this embodiment selected multiple classic models in the field of target detection as benchmarks for comparative analysis. Under the premise of ensuring that all algorithms involved in the comparison use consistent data sets, different network architectures such as Faster RCNN, SSD, YOLOV5, YOLOv8, YOLOv7 and YOLOv7-tiny were thoroughly tested. Through comparative analysis, this embodiment can comprehensively evaluate the performance differences between the improved algorithm and the existing model under the same conditions. The experimental results are summarized in Table 1, which lists in detail the performance indicators of each model in the vehicle target detection task. These indicators not only cover the detection accuracy of the model, but also include other key performance evaluation factors.

[0157] Table 1 Performance comparison of this model with other classic network models

[0158] Model mAP@0.5 / % mAP@.5:.95 / % Model size / M FasterRCNN 84.3 63.4 137.1 SSD 83.3 62.8 26.3 YOLOv5x 84.7 63.9 86.7 YOLOv7 88.1 65.1 72.0 YOLOv7-tiny 85.0 60.8 11.7 This embodiment model 87.0 64.3 8.7

[0159] As can be seen from Table 1, the network models with lower mAP than the algorithm of this embodiment are Faster RCNN, SSD, YOLOv5x, and YOLOv7-tiny. FasterRCNN, as a classic two-stage target detection algorithm, is not much different from the algorithm of this embodiment in terms of accuracy, and its model size is 15.7 times that of the algorithm of this embodiment. SSD, as an early single-stage target detection algorithm, has improved model size and FPS compared to FasterRCNN. Its model size is 3 times that of the algorithm of this embodiment, and its accuracy is 3.7% lower than that of the algorithm proposed in this embodiment. The YOLOv5x network model is a relatively large and highly accurate model in the YOLOv5 algorithm. Its model size is 9.9 times that of the algorithm of this embodiment, and its real-time performance is not much different from that of this embodiment. YOLOv7-tiny is the basic network model of this embodiment, and is slightly lower than the algorithm proposed in this embodiment in terms of accuracy and model size. The network model with a higher mAP than the algorithm in this embodiment is YOLOv7. Compared to the YOLOv7-tiny network model, the base network model in this embodiment, YOLOv7 strives for more stable accuracy, but requires higher computing power. As can be seen from the table, its model accuracy is higher than the algorithm proposed in this embodiment, but the network model is larger, 8.3 times the size of the model proposed in this article. The improved YOLOv7-tiny vehicle target detection algorithm proposed in this embodiment achieves a mAP of 87%, a 2% improvement over the base YOLOv7-tiny mAP. The average mAP under different intersection-over-union ratio thresholds reaches 64.3%, a 3.5% improvement over the base YOLOv7-tiny. In summary, the improved YOLOv7-tiny vehicle target detection algorithm not only maintains the algorithm's detection accuracy, but also reduces the model's parameters, making the model more lightweight. This demonstrates the advantages of the algorithm in the field of roadside vehicle detection and can provide accurate and efficient detection results for subsequent vehicle target tracking in single-camera and multi-camera scenarios. To verify the impact of different pruning strategies on the model, the improved model was pruned using the pruning strategy on the dataset prepared in this example. The results are shown in Table 2. Sparse indicates that sparse training is required, and 2.0x represents a setting of twice the speedup (the same applies to 1.5x). When the model compression reaches the set speed, it will automatically enter the fine-tuning stage.

[0160] Table 2 Comparison of model pruning effects

[0161]

[0162] As can be seen from Table 2, the models obtained by using three different pruning strategies based on the improved algorithm model in this embodiment have all decreased in model size and parameter count, but the corresponding mAP has decreased. The network model parameter count obtained by the importance-based layer adaptive pruning strategy at 1.5 times the speed is 55.9% of the original model parameter count, with a decrease in accuracy of 1.9%; the network model parameter count obtained by the importance-based layer adaptive pruning strategy at 2.0 times the speed is 42.7% of the original model parameter count, with a decrease in accuracy of 3.1%; the network model parameter count obtained by the channel weight-based pruning strategy at 2.0 times the speed is 41.1% of the original model parameter count, with a decrease in accuracy of 2.6%; the network model parameter count obtained by the growth regularization-based pruning strategy is 36.1% of the original model parameter count, with a decrease in accuracy of 1.3%. The corresponding sizes of the network models obtained by different pruning strategies have all decreased. In actual application, different network models can be selected according to the needs of the application.

[0163] (2) Qualitative analysis of target detection results The training is carried out according to the pre-set parameters (as shown in Table 3). The confidence loss (cls_Loss), coordinate regression loss (box_Loss) and target confidence loss (obj_Loss) in the training process are as follows: Figure 10 As shown. The values ​​of the three losses gradually decrease with the increase of epochs, and when the epoch reaches the set threshold, the three losses show a trend of convergence. It can be seen from the figure that the improved detection model converges faster than the YOLOv7-tiny model. In order to verify the effect of the target detection algorithm of this embodiment in practical applications, some frames of road monitoring videos were selected as the input of the algorithm. The obtained detection results show the detection effects on sunny days, rainy days, evenings and nights. It can be seen from the detection results that the improved algorithm can identify all vehicle targets in the current scene in different scenarios, with a high recognition rate and no missed detection problems. In addition, it can be seen from the detection results that the algorithm can adapt to the detection task of vehicle targets under different camera perspectives.

[0164] Table 3 Parameter setting table

[0165] Parameter Type Parameter value Image size 640×640 BatchSize 32 Epoch 300 Weight decay coefficient 0.0005 Momentum Factor 0.937 Initial learning rate 0.01

[0166] To verify whether the pruned model can accurately complete the target detection task, this example selects the model pruned based on the growth regularization pruning strategy with the best performance in Table 2 for qualitative analysis to explore the effectiveness of the pruned model. Images of the same scene as the detection results are selected for detection. It can be seen that the pruned model can still complete vehicle detection and recognition tasks in different scenarios. It performs better for detecting close-up vehicle age targets. For the same vehicle in the same scene, the pruned model has higher accuracy than the unpruned model.

[0167] In order to verify the effectiveness of the various improvements in the algorithm proposed in this embodiment, an ablation experiment was set up. Different models were added to the YOLOv7-tiny one by one, and the performance indicators of the different models were compared. The ablation experiment results are shown in Table 4. In addition, the purpose of the ablation experiment is to explore whether each improved model is effective for the algorithm, so the selected evaluation indicators are mAP, mAP@.5:.95 and the number of parameters. In the table, "√" indicates that the improved model is used in the model, and "×" indicates that the improved model is not used in the model. A indicates that the YOLOv7-tiny backbone is replaced by the lightweight backbone MobileNetV3, B indicates the lightweight model of GSConv and VOV-GSCSP, C indicates the introduction of the self-attention dynamic detection head, and D indicates the addition of the DecoupledHead decoupling head.

[0168] Table 4. Comparison of ablation experiment results

[0169]

[0170] Table 4 shows that in the first set of experiments, replacing the YOLOv7-tiny backbone with MobileNetV3 reduced the model size by 38.9% compared to the original baseline network, while increasing mAP by 0.2%. This demonstrates that MobileNetV3 can achieve model lightweighting while maintaining stable accuracy, thanks to its linear bottleneck inverted residual structure and SE attention mechanism. The second set of experiments, based on the first set of experiments, replaced the network backbone with MobileNetV3 by adding varying numbers of GSConv and VOV-GSCSP models. This reduced the model size by 41.7% compared to the original baseline network, while increasing mAP by 0.1% and decreasing mAP@.5:.95 by 0.1%. This demonstrates that the addition of GSConv and VOV-GSCSP models reduces redundant information, making the model even more lightweight. The third set of experiments added a self-attention dynamic detection head Dyhead to the second set of experiments. The mAP increased by 1.1% compared to the second set of experiments and by 1.4% compared to the original baseline network. The model size was reduced by 32.1% compared to the original baseline network. The increase compared to the second set of experiments was mainly due to the addition of the head model to the original network. However, the accuracy improvement of the self-attention dynamic detection head Dyhead was significant, indicating that the perception ability and feature expression ability were improved after adding the self-attention dynamic detection head Dyhead. The fourth set of experiments added a decoupling head to the third set of experiments. The mAP increased by 0.3% compared to the third set of experiments and by 2% compared to the original baseline network. The model size was reduced by 25.3% compared to the original baseline network. Through analysis and comparison of mAP and parameter counts in multiple sets of experiments, it was found that the improved algorithm performed well. While maintaining a lightweight model, it also had efficient feature extraction capabilities, making it suitable for deployment in applications with limited computing resources. During the training of the baseline algorithm and the improved algorithm, the change curves of mAP@0.5 and mAP@.5:.95 of the two algorithms were compared. Figure 11 shown.

[0171] In summary, the improvement measures of this embodiment have a positive impact on improving the accuracy and lightweightness of the vehicle target detection algorithm, and have demonstrated excellent performance. While the model feature extraction capability does not decrease and is slightly improved, the model meets the lightweight requirements.

[0172] Corresponding to the above method, this embodiment further discloses a YOLOv7-tiny lightweight vehicle target detection system, including:

[0173] A dataset construction module is used to construct a roadside vehicle dataset containing vehicle images of various models, under different lighting and weather conditions;

[0174] A data set processing module, configured to perform image filtering, image enhancement, and data set division on the roadside vehicle data set to obtain a training set, a validation set, and a test set;

[0175] A model improvement module is used to build an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network;

[0176] A lightweight module, configured to apply a pruning strategy to perform lightweight processing on the initial vehicle target detection model to obtain a lightweight vehicle detection model;

[0177] A training module, configured to input the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model;

[0178] The detection module is used to input the image to be detected into the final vehicle target detection model to obtain the detection result.

[0179] The beneficial effects of the present invention are as follows:

[0180] (1) Compared with the classic target detection algorithms in the target detection field, the improved YOLOv7-tiny lightweight vehicle target detection algorithm proposed in this paper has better accuracy, smaller model, and faster speed. Compared with the original YOLOv7-tiny model, the improved algorithm has a mAP increase of 2%, and the average mAP in the IoU threshold range of 0.5 to 0.95 reaches 64.3%, an increase of 3.5%.

[0181] (2) The present invention lightweights the improved model by applying three different pruning strategies. Although the mAP is sacrificed to a certain extent, the size and number of parameters of the model are significantly reduced, making the model more suitable for deployment in resource-constrained environments.

[0182] (3) The algorithm proposed in the present invention can identify vehicle targets in the current scene under various conditions such as sunny days, rainy days, evening and night, with a high recognition rate.

[0183] (4) Through ablation experiments, the present invention effectively verifies that the different improvement strategies proposed are meaningful to a certain extent in terms of lightweight and detection accuracy of vehicle target detection.

[0184] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Reference can be made to the common and similar parts between the various embodiments. For the systems disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method description.

[0185] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The above examples are only intended to help understand the method and core concept of the present invention. At the same time, those skilled in the art will find that the specific implementation methods and application scopes may vary based on the concept of the present invention. In summary, the contents of this specification should not be construed as limiting the present invention.

Claims

1. A YOLOv7-tiny lightweight vehicle target detection method, characterized in that: include: Construct a roadside vehicle dataset containing vehicle images of various models, in different lighting and weather conditions; Performing image filtering, image enhancement, and dataset division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set; Constructing an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network; Applying a pruning strategy to lightweight the initial vehicle target detection model to obtain a lightweight vehicle detection model; Inputting the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model; Inputting the image to be detected into the final vehicle target detection model to obtain a detection result; The pruning strategies include: importance-based layer adaptive pruning, channel weight-based pruning, and growth regularization-based pruning; Pruning is expressed as a transformation T(*), whose input is a pre-trained large model w and output is a small model w1. Pruning is usually followed by a fine-tuning process F(*), and the final output is w2. The calculation formula of w2 is as follows; F(*) is a standard neural network training process, which does not need to be paid too much attention to. More attention should be paid to the process of converting from w to w1; pruning can be further converted into two sub-transformations: (1) M = T1(w), obtaining a binary mask vector M to determine which weights will be removed; (2) T2(w) is used to adjust the value of the remaining weights. The calculation formula of the final output w1 is as follows; w2=F(w1) w1=T(w)=T1(w)⊙T2(w)=M⊙T2(w) For one-shot pruning, there is no iterative training in T1, and it depends on the specific algorithm to decide whether to adjust the remaining weights; for learning-based pruning, both T1 and T2 involve iterative training, and the retained weights will always be adjusted; The first method in the algorithm is a variant of L1 norm pruning, which obtains the mask M by L1 norm sorting and adjusts the retained weights by regularization. Specifically, given a pre-trained model w and layer pruning ratio γ l , sort the filters according to the L1 norm, set the mask M to 0 for those filters with the smallest norm, and then drive those unimportant weights to 0 through a gradually increasing L2 penalty. The calculation method is as follows; l j =λ j +δλ,j∈{j∣,M[j]=0} Among them, λ j is the penalty factor of the jth weight; δλ is the granularity of increasing the penalty. Obviously, the smaller δλ is, the smoother the regularization process is; λ j Only per K u It is updated once in the iteration, which is a buffer time to allow the network to adapt to the new regularization; when λ j When the preset upper limit τ is reached, the training is terminated and the weights with the smallest L1 norm are pruned, and then fine-tuning is performed. Pruning does not affect the accuracy, and the unimportant weights have been compressed to typically less than one thousandth of the remaining weights. The second method in the algorithm uses a gradual growth regularization method for scoring. Neural network training is prone to overfitting, so regularization techniques are often used. L2 regularization is a standard technique for training deep networks. Given a dataset D and model parameters w, the total loss is defined as follows: Where L represents the task loss function; when the training converges, the following formula should exist: in, indicates that the i-th weight is at its minimum value.

2. The YOLOv7-tiny lightweight vehicle target detection method according to claim 1, wherein The target categories in the roadside vehicle dataset include: cars, buses, vans and others.

3. The YOLOv7-tiny lightweight vehicle target detection method according to claim 1, wherein Perform image filtering, image enhancement, and data set division on the roadside vehicle dataset to obtain a training set, a validation set, and a test set, including: Performing filtering on the image in the roadside vehicle dataset to obtain a filtered image; Constructing an image enhancement window, and using the image enhancement window to traverse the filtered image to perform denoising to obtain a denoised image; Performing histogram equalization processing on the denoised image to obtain an enhanced image; The enhanced images are divided into data sets according to a preset ratio to obtain the training set, the validation set and the test set.

4. The YOLOv7-tiny lightweight vehicle target detection method according to claim 3, wherein Filtering the image in the roadside vehicle dataset to obtain a filtered image includes: Performing wavelet decomposition on the roadside vehicle dataset at multiple scales to obtain corresponding wavelet coefficients; A filtering threshold is constructed according to the size and decomposition scale of the roadside vehicle dataset; the formula for the filtering threshold is: Among them, λ j represents the filtering threshold at the jth decomposition scale, σ j represents the noise standard deviation at the jth decomposition scale, N j represents the signal length at the jth decomposition scale, where j represents the decomposition scale; The image filtering model is constructed using the filtering threshold; the formula of the image filtering model is: Where sign is the sign function, a is the first preset coefficient, b is the second preset coefficient, ω j,k represents the kth wavelet coefficient at the jth decomposition scale, represents the wavelet coefficients after filtering; The image of the roadside vehicle dataset is filtered using the image filtering model to obtain the filtered image.

5. The YOLOv7-tiny lightweight vehicle target detection method according to claim 3, wherein Constructing an image enhancement window and traversing the filtered image using the image enhancement window to perform denoising to obtain a denoised image, including: Detecting the filtered image using an image recognition model to obtain a proportion value under each image enhancement window; When the proportion value in the image enhancement window is greater than a preset threshold, median denoising is performed on the image in the corresponding image enhancement window to obtain a median denoised image; The image enhancement window is slid until the entire filtered image is traversed to obtain the denoised image.

6. The YOLOv7-tiny lightweight vehicle target detection method according to claim 5, characterized in that The filtered image is detected using an image recognition model to obtain a ratio value under each image enhancement window, including: Using formula F ij =|x ij -y ij |Get the pixel difference of each pixel under each image enhancement window; where F ij Represents the pixel difference of the image at position (i, j), x ij Represents the pixel value of the image at position (i, j), y ij represents the pixel value of the filtered image at position (i, j); Pixels whose pixel difference is greater than the feature threshold are regarded as feature points and the number is recorded; The ratio of the feature points to all pixels in the image enhancement window is taken as the proportion value.

7. The YOLOv7-tiny lightweight vehicle target detection method according to claim 5, characterized in that The initial vehicle target detection model includes: an input network, a backbone network, a neck network and a detection head connected in sequence; The input network is used to perform data enhancement and image preprocessing operations on the input image set to obtain a preprocessed image; the backbone network is used to extract image features from the preprocessed image based on the ELAN model and the MP model to obtain a feature map; the neck network is used to perform feature fusion and enhancement on the feature map to obtain a fusion map; the detection head is used to perform feature detection based on the fusion map to obtain a detection result.

8. The YOLOv7-tiny lightweight vehicle target detection method according to claim 7, characterized in that The backbone network of the backbone network is the MobileNetV3 network.

9. A YOLOv7-tiny lightweight vehicle target detection system, characterized in that include: A dataset construction module is used to construct a roadside vehicle dataset containing vehicle images of various models, under different lighting and weather conditions; A data set processing module, configured to perform image filtering, image enhancement, and data set division on the roadside vehicle data set to obtain a training set, a validation set, and a test set; A model improvement module is used to build an improved initial vehicle target detection model; the initial vehicle target detection model is designed based on the YOLOv7-tiny network; A lightweight module, configured to apply a pruning strategy to perform lightweight processing on the initial vehicle target detection model to obtain a lightweight vehicle detection model; A training module, configured to input the training set, the validation set, and the test set into the lightweight vehicle detection model for training, testing, and verification to obtain a final vehicle target detection model; A detection module, configured to input the image to be detected into the final vehicle target detection model to obtain a detection result; The pruning strategies include: importance-based layer adaptive pruning, channel weight-based pruning, and growth regularization-based pruning; Pruning is expressed as a transformation T(*), whose input is a pre-trained large model w and output is a small model w1. Pruning is usually followed by a fine-tuning process F(*), and the final output is w2. The calculation formula of w2 is as follows; F(*) is a standard neural network training process, which does not need to be paid too much attention to. More attention should be paid to the process of converting from w to w1; pruning can be further converted into two sub-transformations: (1) M = T1(w), obtaining a binary mask vector M to determine which weights will be removed; (2) T2(w) is used to adjust the value of the remaining weights. The calculation formula of the final output w1 is as follows; w2=F(w1) w1=T(w)=T1(w)⊙T2(w)=M⊙T2(w) For one-shot pruning, there is no iterative training in T1, and it depends on the specific algorithm to decide whether to adjust the remaining weights; for learning-based pruning, both T1 and T2 involve iterative training, and the retained weights will always be adjusted; The first method in the algorithm is a variant of L1 norm pruning, which obtains the mask M by L1 norm sorting and adjusts the retained weights by regularization. Specifically, given a pre-trained model w and layer pruning ratio γ l , sort the filters according to the L1 norm, set the mask M to 0 for those filters with the smallest norm, and then drive those unimportant weights to 0 through a gradually increasing L2 penalty. The calculation method is as follows; l j =λ j +δλ,j∈{j∣,M[j]=0} Among them, λ j is the penalty factor of the jth weight; δλ is the granularity of increasing the penalty. Obviously, the smaller δλ is, the smoother the regularization process is; λ j Only per K u It is updated once in the iteration, which is a buffer time to allow the network to adapt to the new regularization; when λ j When the preset upper limit τ is reached, the training is terminated and the weights with the smallest L1 norm are pruned, and then fine-tuning is performed. Pruning does not affect the accuracy, and the unimportant weights have been compressed to typically less than one thousandth of the remaining weights. The second method in the algorithm uses a gradual growth regularization method for scoring. Neural network training is prone to overfitting, so regularization techniques are often used. L2 regularization is a standard technique for training deep networks. Given a dataset D and model parameters w, the total loss is defined as follows: Where L represents the task loss function; when the training converges, the following formula should exist: in, indicates that the i-th weight is at its minimum value.

Citation Information

Patent Citations

  • Lightweight infrared vehicle target detection method

    CN117253200A

  • Intelligent sweeper target detection method based on YOLOv7

    CN118505973A