Target detection method based on improved YOLOv5n

By introducing RepConv and channel pruning technology into the YOLOv5n model, a lightweight backbone network was designed, which solved the problem of excessive computational complexity and number of parameters in mobile scenarios, and achieved more efficient calculations and better Detection accuracy.

CN119478620AActive Publication Date: 2025-02-18GUANGDONG UNIV OF TECH
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202411019665.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2025-02-18
Estimated Expiration
2044-07-29

AI Technical Summary

Technical Problem

In mobile scenarios, existing object detection models are limited in memory and computing resources due to excessive computational complexity and the number of parameters, making them difficult to deploy on low-power mobile terminals.

Method used

Using the object detection method based on improved YOLOv5n, a lightweight backbone network is designed by replacing PConv in FasterNet with RepConv, and combining channel pruning technology to further compress the model.

Benefits of technology

It effectively reduces the number of network parameters, improves the computing speed, and improves the detection accuracy of the model, making it suitable for mobile device environments with resource-constrained.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119478620A_ABST
    Figure CN119478620A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of target detection algorithms, and particularly relates to a target detection method based on improved YOLOv5n, and the method comprises the following steps: S1, employing RepConv to improve a Faster Net backbone network; the RepConv in the RepVGG is used for replacing the PConv in the Faster Net, and the RepConv in the RepVGG is used for replacing the PConv in S2, replacing an original C3 backbone network; the improved Faster Rep is fused with a C3 module of the original backbone network, and a backbone of the original backbone network is replaced with an improved C3-FR backbone; s3, pruning is carried out on the improved model; by improving the YOLOV5 algorithm, the detection effect of the whole algorithm is optimized. According to the invention, the number of network parameters can be effectively reduced, the operation speed is improved, and the detection precision of the model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of target detection algorithms, and in particular relates to a target detection method based on improved YOLOv5n. Background Art

[0002] Object detection is a part of computer vision. It describes the entire image content and combines the characteristic information of the target object to determine the category and location of the object. Object detection combines the location and recognition of the target into one, and can detect the target in real time and accurately in a specific environment. Object detection technology is commonly used in various fields such as face detection, smart transportation, unmanned driving, remote sensing target detection, pedestrian counting, and security systems.

[0003] When deploying object detection networks in many mobile scenarios, we must not only consider the computational complexity and number of model parameters, but also the detection accuracy of the model. Common practices include network pruning and network parameter quantization, which are all optimizations on the designed network models. In order to be more suitable for mobile scenarios, it is necessary to design a lightweight network to solve the problems of limited memory and limited computing power in mobile scenarios.

[0004] With the development of deep learning, convolutional neural networks (CNN) have been widely used, and target detection technology based on deep learning has pushed target detection to a new high. As detection accuracy standards become increasingly stringent, the challenges of detection tasks have also intensified, prompting the emergence of more complex and large network architectures. Although larger network models and deeper network structures can extract richer deep features, thereby significantly improving detection accuracy, this improvement is also accompanied by a huge amount of parameters and computation, making it difficult to deploy in certain memory-constrained application environments. Therefore, the research on lightweight target detection networks has always attracted much attention from the industry.

[0005] Invention content

[0006] The purpose of the present invention is to provide a target detection method based on improved YOLOv5n, which can effectively reduce the number of network parameters, increase the calculation speed, and improve the detection accuracy of the model.

[0007] The technical solution adopted by the present invention is as follows:

[0008] A target detection method based on improved YOLOv5n, the detection method comprising the following contents:

[0009] S1: Improve FasterNet backbone network using RepConv;

[0010] Use RepConv in RepVGG to replace PConv in FasterNet;

[0011] In S1, the core idea of ​​RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations. For example, a structure containing three branches: a 3×3 convolution, a 1×1 convolution, and an identity mapping;

[0012] The outputs are:

[0013] Y1=W1*X

[0014] Y2=W2*X

[0015] Y3=X

[0016] The three outputs are combined to get the final output:

[0017]

[0018] Y=(W1*X)+(W2*X)+X

[0019] During training, the above multi-branch structure is used, and during the inference phase, the branches are reparameterized into a single convolution kernel; the specific steps are as follows:

[0020] S11: Reparameterization of the identity map: The identity map can be represented as a 1×1 convolution with an identity kernel, namely:

[0021] Y3=X=W3*X

[0022] Among them, W3 is a 1×1 identical convolution kernel;

[0023] S12: Convolution kernel fusion: The convolution kernels of all branches are fused into one convolution kernel. If all convolution kernels have the same size, the fused convolution kernel is:

[0024] W fused =W1+W2+W3

[0025] S13: Single convolution operation in the inference phase: In the inference phase, only a single convolution operation is required using the fused convolution kernel:

[0026] Y=W fused *X.

[0027] S2: replaces the original C3 backbone network;

[0028] The improved Faster_Rep is integrated with the C3 module of the original backbone network, and the backbone of the original backbone network is replaced with the improved C3-FR backbone.

[0029] S3: Prune the improved model;

[0030] By improving the YOLOV5 algorithm, the detection effect of the entire algorithm is optimized.

[0031] In S3, channel pruning determines the importance of different parameters during the training process and removes unimportant channels and their corresponding inputs and outputs. The main process includes:

[0032] The network is trained to be sparse, the importance of different channels is judged, unimportant channels are removed, and finally the pruned network model is obtained. The channel sparse training and pruning process is given, and a scale factor γ is assigned to each channel in the convolutional layer to evaluate its importance.

[0033] Through a large amount of training, some γ distributions are made closer to 0, sorted and a threshold parameter is given according to the distribution, and finally the channels with values ​​less than the threshold are directly eliminated to reduce the amount of calculation and model size.

[0034] In the detection network, each convolutional layer is followed by a batch normalization (BN) layer to accelerate network convergence by normalizing the input data. The corresponding formula is:

[0035]

[0036] Where: y in and out Represents the input and output of the BN layer, μ and σ 2 They represent the mean and variance of the input feature map respectively; β is the bias; ε is the minimum factor to prevent the denominator from being 0.

[0037] During training, the loss function of sparse training is:

[0038]

[0039] Where: the first term represents the loss function of YOLO; the second term uses L1 regularization to constrain the scaling factor γ; α is a sparse parameter used to balance the two losses.

[0040] The technical effects achieved by the present invention are:

[0041] The target detection method based on improved YOLOv5n of the present invention is a lightweight backbone network based on FasterNet and RepVGG. By replacing PConv in FasterNet with RepConv, the improved backbone network has lower computational complexity and a smaller number of parameters than the original C3 backbone network of YOLOv5n.

[0042] The object detection method based on improved YOLOv5n of the present invention integrates the redesigned backbone network into the original C3 backbone network of YOLOv5n to form a C3-FR module, and further compresses the model based on the detection model compression algorithm of channel pruning. The existing object detection model is optimized, and the problem that the detection model has a large amount of calculation, high resource occupation, and is difficult to be deployed on a low-power mobile terminal is solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] Figure 1 is a flow chart of an embodiment of the present invention;

[0044] Figure 2 is a diagram of the improved Faster_Rep network structure in an embodiment of the present invention;

[0045] Figure 3 is a diagram of the improved C3-FR network structure of an embodiment of the present invention;

[0046] Figure 4 It is a schematic diagram of channel sparse training and pruning according to an embodiment of the present invention. DETAILED DESCRIPTION

[0047] In order to make the purpose and advantages of the present invention more clearly understood, the present invention is specifically described below in conjunction with embodiments. It should be understood that the following text is only used to describe one or several specific embodiments of the present invention, and does not strictly limit the scope of protection of the specific claims of the present invention.

[0048] Example:

[0049] like Figure 1-Figure 4 As shown, a target detection method based on improved YOLOv5n, the detection method includes the following contents:

[0050] S1: Improve FasterNet backbone network using RepConv;

[0051] Use RepConv in RepVGG to replace PConv in FasterNet;

[0052] RepConv (Reparameterized Convolutions) is a convolutional neural network structure used for image processing and computer vision tasks. It is designed to improve the efficiency and performance of convolutional neural networks, especially when processing large-scale image data.

[0053] RepConv is a model reparameterization technique that can merge multiple computing modules into one during the inference phase to improve the efficiency and performance of the model. It was originally used for VGG networks, but has since been applied to other network structures such as ResNet and DenseNet. The core idea of ​​RepConv is to reparameterize the convolution kernel to reduce the number of parameters in the network while maintaining the expressiveness of the model. Traditional convolution operations use fixed convolution kernels (such as 3x3 or 5x5), which are fixed throughout the network and require a large number of parameters to store and calculate. In contrast, RepConv allows the network to dynamically adjust the shape and parameters of the convolution kernel at each layer by introducing a learnable transformation on the convolution kernel. This dynamic adjustment allows the network to adaptively select the shape and size of the convolution kernel based on the characteristics of the data, thereby improving the generalization ability and efficiency of the model.

[0054] RepConv (reparameterized convolution) is a method that fuses different convolution operations and reparameterizes them during inference to achieve more efficient computation.

[0055] like Figure 1 As shown in S1, the core idea of ​​RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations. For example, a structure containing three branches: a 3×3 convolution, a 1×1 convolution and an identity mapping;

[0056] The outputs are:

[0057] Y1=W1*X

[0058] Y2=W2*X

[0059] Y3=X

[0060] The three outputs are combined to get the final output:

[0061]

[0062] During training, the above multi-branch structure is used, and during the inference phase, the branches are reparameterized into a single convolution kernel; the specific steps are as follows:

[0063] S11: Reparameterization of the identity map: The identity map can be represented as a 1×1 convolution with an identity kernel, namely:

[0064] Y3=X=W3*X

[0065] Among them, W3 is a 1×1 identical convolution kernel;

[0066] S12: Convolution kernel fusion: The convolution kernels of all branches are fused into one convolution kernel. If all convolution kernels have the same size, the fused convolution kernel is:

[0067] W fused =W1+W2+W3

[0068] S13: Single convolution operation in the inference phase: In the inference phase, only a single convolution operation is required using the fused convolution kernel:

[0069] Y=W fused *X.

[0070] Through the above derivation, we can see that RepConv enhances the expressiveness of the model by using a multi-branch structure during training, and improves computational efficiency by re-parameterizing and merging into a convolution kernel during the inference phase. This re-parameterization idea enables RepConv to significantly reduce computational overhead while maintaining model performance, making it suitable for various computer vision tasks.

[0071] S2: replaces the original C3 backbone network;

[0072] The improved Faster_Rep is integrated with the C3 module of the original backbone network, and the backbone of the original backbone network is replaced with the improved C3-FR backbone.

[0073] S3: Prune the improved model;

[0074] By improving the YOLOV5 algorithm, the detection effect of the entire algorithm is optimized.

[0075] By improving the YOLOV5 algorithm, the detection effect of the entire algorithm is optimized. However, excessive parameters and computational complexity require more video memory to load the model, which places higher demands on the hardware and greatly affects the running speed of the model. In practical applications, it is often necessary to port the algorithm to a portable hardware platform for ease of use. In order to meet the needs of practical applications, the pre-trained detection network model needs to be compressed to reduce the parameters and size of the detection model, thereby shortening the time consumed by model training and testing and improving the detection rate.

[0076] like Figure 4 As shown in Figure 1, in S3, channel pruning determines the importance of different parameters during the training process and removes unimportant channels and their corresponding inputs and outputs. The main process includes:

[0077] The network is trained to be sparse, the importance of different channels is judged, unimportant channels are removed, and finally the pruned network model is obtained. The channel sparse training and pruning process is given, and a scale factor γ is assigned to each channel in the convolutional layer to evaluate its importance.

[0078] Through a large amount of training, some γ distributions are made closer to 0, sorted and a threshold parameter is given according to the distribution, and finally the channels with values ​​less than the threshold are directly eliminated to reduce the amount of calculation and model size.

[0079] In the detection network, each convolutional layer is followed by a batch normalization (BN) layer to accelerate network convergence by normalizing the input data. The corresponding formula is:

[0080]

[0081] Where: y in and out Represents the input and output of the BN layer, μ and σ 2 They represent the mean and variance of the input feature map respectively; β is the bias; ε is the minimum factor to prevent the denominator from being 0.

[0082] During training, the loss function of sparse training is:

[0083]

[0084] Where: the first term represents the loss function of YOLO; the second term uses L1 regularization to constrain the scaling factor γ; α is a sparse parameter used to balance the two losses.

[0085] The comparative test of the model on the CrowdHuman public dataset is shown in Table 1:

[0086] Table 1. Comparison of model performance

[0087] Model Crop rate mAP@0.5 / % <![CDATA[P AR / 10 6 ]]> GFLOPs <![CDATA[M O / MB]]> YOLOv5n / 0.711 1.61 3.7 3.4 Improved model 0.5 0.704(-0.007) 0.4(27.7%) 1.8(48.6%) 1.2(35.3%)

[0088] In order to achieve a more efficient model structure, faster reasoning speed and better computing efficiency without sacrificing accuracy and performance, the present invention designs a lightweight backbone network by replacing the PConv module in FasterNet with RepConv in RepVGG. RepConv is used to optimize the convolution operation inside the network, while RepVGG, characterized by its deep separable convolution and efficient architecture, is integrated with FasterNet to form a lightweight backbone network. This combination takes full advantage of the speed and efficiency advantages of RepVGG and the structural improvements of FasterNet to ensure high accuracy and performance in resource-constrained environments (such as mobile devices).

[0089] In order to optimize the existing target detection model, considering the computational complexity and number of parameters, the present invention integrates the redesigned backbone network into the C3 module of the original YOLOv5n architecture to form the C3-FR module. The C3-FR module integrates the advantages of the redesigned backbone network and balances the model detection accuracy and reduced computational requirements. By replacing or enhancing specific modules (such as C3) with optimized designs in the lightweight backbone network, the performance of the model can be significantly improved while maintaining the accuracy of target detection.

[0090] In order to solve the problem of limited memory and computing resources in mobile scenarios, this paper proposes a detection model compression algorithm based on channel pruning. The algorithm further compresses the model by pruning redundant channels (i.e., unimportant channels in the network), thereby reducing the storage and computing overhead of the model without reducing the performance of the model. This optimization makes the improved model more suitable for mobile devices and other resource-constrained environments, and improves the deployment efficiency and practicality of the model.

[0091] The above is only a preferred embodiment of the present invention. It should be noted that, for those skilled in the art, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention. The structures, devices and operating methods not specifically described and explained in the present invention shall be implemented according to the conventional means in the art unless otherwise specified and limited.

Claims

1. A target detection method based on improved YOLOv5n, characterized in that: The detection method comprises the following contents: S1: Improve FasterNet backbone network using RepConv; Use RepConv in RepVGG to replace PConv in FasterNet; S2: replaces the original C3 backbone network; The improved Faster_Rep is integrated with the C3 module of the original backbone network, and the backbone of the original backbone network is replaced with the improved C3-FR backbone. S3: Prune the improved model; By improving the YOLOV5 algorithm, the detection effect of the entire algorithm is optimized.

2. A target detection method based on improved YOLOv5n according to claim 1, characterized in that: In S1, the core idea of ​​RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations. For example, a structure containing three branches: a 3×3 convolution, a 1×1 convolution, and an identity mapping; The outputs are: Y1=W1*X Y2=W2*X Y3=X The three outputs are combined to get the final output: Y=Y1+Y2+Y3. Y=(W1*X)+(W2*X)+X 3. A target detection method based on improved YOLOv5n according to claim 2, characterized in that: During training, the above multi-branch structure is used, and during the inference phase, the branches are reparameterized into a single convolution kernel; the specific steps are as follows: S11: Reparameterization of the identity map: The identity map can be represented as a 1×1 convolution with an identity kernel, namely: Y3=X=W3*X Among them, W3 is a 1×1 identical convolution kernel; S12: Convolution kernel fusion: The convolution kernels of all branches are fused into one convolution kernel. If all convolution kernels have the same size, the fused convolution kernel is: <h2 style=";text-align:left;direction:ltr">W<h2 style=";text-align:left;direction:ltr"> fused <h2 style=";text-align:left;direction:ltr"> =W1+W2+W3 S13: Single convolution operation in the inference phase: In the inference phase, only a single convolution operation is required using the fused convolution kernel: Y=W fused *X。 4. A target detection method based on improved YOLOv5n according to claim 1, characterized in that: In S3, channel pruning determines the importance of different parameters during the training process and removes unimportant channels and their corresponding inputs and outputs. The main process includes: The network is trained to be sparse, the importance of different channels is judged, unimportant channels are removed, and finally the pruned network model is obtained. The channel sparse training and pruning process is given, and a scale factor γ is assigned to each channel in the convolutional layer to evaluate its importance. Through a large amount of training, some γ distributions are made closer to 0, sorted and a threshold parameter is given according to the distribution, and finally the channels with values ​​less than the threshold are directly eliminated to reduce the amount of calculation and model size.

5. A target detection method based on improved YOLOv5n according to claim 4, characterized in that: In the detection network, each convolutional layer is followed by a batch normalization (BN) layer to accelerate network convergence by normalizing the input data. The corresponding formula is: Where: y in and out Represents the input and output of the BN layer, μ and σ 2 They represent the mean and variance of the input feature map respectively; β is the bias; ε is the minimum factor to prevent the denominator from being 0.

6. A target detection method based on improved YOLOv5n according to claim 4, characterized in that: During training, the loss function of sparse training is: Where: the first term represents the loss function of YOLO; the second term uses L1 regularization to constrain the scaling factor γ; α is a sparse parameter used to balance the two losses.

Citation Information

Patent Citations

  • Lightweight and network optimization method based on YOLOX

    CN116306813A

  • PCB defect detection method adopting lightweight improved YOLOv5 model

    CN116862831A

  • Lightweight meter pointer reading method based on improved YOLOv5

    CN116935183A

  • Method and system for detecting grape clusters in hard core period based on improved YOLOv5s

    CN117392529A

  • Robot pouring control method and device, electronic equipment and storage medium

    CN117620147A