A target detection method based on improved YOLOv5n

By improving the object detection method of YOLOv5n and optimizing the network structure using RepConv and channel pruning techniques, the problems of high computational cost and high resource consumption in mobile scenarios are solved, and a lightweight object detection model can be deployed.

CN119478620BActive Publication Date: 2025-11-28GUANGDONG UNIV OF TECH
View PDF 2 Cites 0 Cited by

Patent Information

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

Smart Images

  • Figure CN119478620B_ABST
    Figure CN119478620B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of target detection algorithm, and particularly relates to a target detection method based on an improved YOLOv5n, which comprises the following contents: S1: improving a FasterNet backbone network by using RepConv; replacing PConv in the FasterNet with RepConv in the RepVGG; S2: replacing an original C3 backbone network; fusing the improved Faster_Rep with the C3 module of the original backbone network, and replacing the backbone of the original backbone network with the improved C3-FR backbone; S3: pruning the improved model; and improving the YOLOV5 algorithm to optimize the detection effect of the whole algorithm. The application can effectively reduce the number of network parameters, improve the operation speed, and improve the detection accuracy of the model.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of target detection algorithm, and particularly relates to a target detection method based on improved YOLOv5n. BACKGROUND

[0002] Target detection is a part of computer vision, which describes the content of the whole image and determines the category and position of the object by combining the feature information of the target object. Target detection combines target positioning and recognition into one, and can detect targets in real time and accurately in a specific environment. Target detection technology is commonly used in various fields such as face detection, intelligent transportation, unmanned driving, remote sensing target detection, pedestrian counting, and safety systems.

[0003] In many mobile scenarios, deploying a target detection network not only needs to consider the computational complexity and parameter quantity of the model, but also needs to consider the detection accuracy of the model. A common method is network pruning and network parameter quantization, which are optimizations of the already designed network model. In order to be more suitable for mobile scenarios, a lightweight network needs to be specially designed to solve the problem of limited memory and computing power in mobile scenarios.

[0004] With the development of deep learning, convolutional neural networks (CNN) are widely used, and target detection technology based on deep learning has pushed target detection to a new high. With the increasing strictness of detection accuracy standards, the challenge of detection tasks has also intensified, prompting the emergence of more complex and massive network architectures. Although larger network models and deeper network structures can extract more rich deep features, thereby significantly improving detection accuracy, this improvement is accompanied by huge parameter quantity and computation, which is difficult to deploy in some memory-limited application environments. Therefore, the research on lightweight target detection network has always been concerned by the industry.

[0005] Invention content

[0006] The purpose of the present application is to provide a target detection method based on improved YOLOv5n, which can effectively reduce the parameter quantity of the network, improve the operation speed, and at the same time improve the detection accuracy of the model.

[0007] The technical scheme adopted by the present application is as follows:

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

[0009] S1: obtaining an entire image; improving the FasterNet backbone network by using RepConv;

[0010] Replace PConv in FasterNet with RepConv in RepVGG;

[0011] The core idea of RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations. If a structure containing three branches is used: a 3x3 convolution, a 1x1 convolution and an identity mapping;

[0012] The outputs are respectively:

[0013] Y1=W1*X

[0014] Y2=W2*X

[0015] Y3=X

[0016] Fuse the three outputs to get the final output:

[0017] Y=Y1+Y2+Y3

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

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

[0020] S11: Re-parameterization of identity mapping: the identity mapping can be represented as a 1x1 convolution with an identity convolution kernel, that is:

[0021] Y3=X=W3*X

[0022] Where W3 is a 1x1 identity convolution kernel;

[0023] S12: Convolution kernel fusion: fuse the convolution kernels of all branches into a convolution kernel, if all convolution kernels are of the same size, then the fused convolution kernel is:

[0024] W fused =W1+W2+W3

[0025] S13: Single convolution operation in inference stage: in the inference stage, only a single convolution operation is needed using the fused convolution kernel:

[0026] Y=W fused *X.

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

[0028] Fuse the improved Faster_Rep with the C3 module of the original backbone network, and replace the original backbone network with the improved C3-FR backbone;

[0029] S3: pruning the improved model; and using the above model to process the obtained whole image, describing the whole image content, combining the feature information of the target object, determining the category and position of the object, and completing the detection of the target;

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

[0031] In the S3, the channel pruning judges the importance of different parameters in the training process, and removes the unimportant channels and the corresponding inputs and outputs, and the main process includes:

[0032] The network is subjected to sparse training, the importance of different channels is judged, the unimportant channels are removed, finally the pruned network model is obtained, and the channel sparse training and pruning process are given, and each channel in the convolution layer is allocated a scale factor gamma for evaluating the importance thereof;

[0033] Through a large amount of training, some gamma distributions are continuously close to 0, and the channels smaller than the threshold value are directly removed according to the distribution given threshold parameter, so that the calculation amount and model size are reduced.

[0034] In the detection network, there is a batch normalization BN layer after each convolution layer, which accelerates the network convergence by normalizing the input data, and the corresponding formula is:

[0035]

[0036] In the formula: y in And y out Indicate the input and output of the BN layer, and mu and sigma 2 Indicate the mean and variance of the input feature map respectively; beta is the bias; epsilon is a small factor to prevent the denominator from being 0.

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

[0038]

[0039] In the formula: the first term indicates the loss function of YOLO; the second term uses L1 regularization to constrain the scaling factor gamma; alpha is a sparse parameter used to balance the two losses.

[0040] The technical effects obtained by the application are:

[0041] The target detection method based on the improved YOLOv5n is a lightweight backbone network based on FasterNet and RepVGG, wherein the PConv in the FasterNet is replaced by RepConv, so that the improved backbone network has lower calculation complexity and smaller parameter quantity compared with the original C3 backbone network of YOLOv5n.

[0042] The target detection method based on the improved YOLOv5n 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 a channel pruning detection model compression algorithm, thereby optimizing the existing target detection model and solving the problems of large calculation amount, high resource occupation and difficulty in deploying on a low-power mobile terminal. BRIEF DESCRIPTION OF DRAWINGS

[0043] Figure 1 is a flowchart of an embodiment of the present application;

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

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

[0046] Figure 4 is a schematic diagram of channel sparsification training and pruning of an embodiment of the present application. DETAILED DESCRIPTION

[0047] In order to make the objects and advantages of the present application clearer and more apparent, the present application will be specifically described below in combination with embodiments. It should be understood that the following text is only used to describe one or several specific embodiments of the present application, and does not strictly limit the specific protection scope of the present application.

[0048] Embodiment:

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

[0050] S1: obtaining an entire image; improving a FasterNet backbone network by using RepConv;

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

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

[0053] RepConv is a model reparameterization technique that combines multiple computational modules into one during inference, improving the efficiency and performance of the model. It was initially developed for VGG networks but has since been applied to other network architectures such as ResNet and DenseNet. The core idea behind RepConv is to reparameterize the convolutional kernels to reduce the number of parameters in the network while maintaining the model's expressive power. Traditional convolutional operations use fixed convolutional kernels (e.g., 3x3 or 5x5) that are fixed throughout the network, requiring a large number of parameters to store and compute. In contrast, RepConv allows the network to dynamically adjust the shape and parameters of the convolutional kernels at each layer by introducing learnable transformations on the convolutional kernels. This dynamic adjustment enables the network to adaptively choose the shape and size of the convolutional kernels based on the characteristics of the data, improving the model's generalization ability and efficiency.

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

[0055] As shown in Figure 1 , in S1, the core idea of RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations. If a structure contains three branches: a 3x3 convolution, a 1x1 convolution, and an identity mapping;

[0056] The outputs are:

[0057] Y1 = W1 * X

[0058] Y2 = W2 * X

[0059] Y3 = X

[0060] Fusing these three outputs, we get the final output:

[0061]

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

[0063] S11: Reparameterization of the identity mapping: The identity mapping can be represented as a 1x1 convolution with an identity kernel, i.e.,

[0064] Y3 = X = W3 * X

[0065] where W3 is a 1x1 identity convolution kernel;

[0066] S12: Convolution kernel fusion: fuse the convolution kernels of all branches into one convolution kernel, if all convolution kernels are of the same size, then the fused convolution kernel is:

[0067] W fused = W1 + W2 + W3

[0068] S13: Single convolution operation in inference stage: in the inference stage, only a single convolution operation is needed using the fused convolution kernel:

[0069] Y = W fused *X.

[0070] Through the above derivation, it can be seen that RepConv enhances the representation ability of the model by using a multi-branch structure during training, and in the inference stage, it is fused into a convolution kernel through re-parameterization, thereby improving the computational efficiency. This re-parameterization idea enables RepConv to significantly reduce the computational overhead while maintaining the performance of the model, making it suitable for various computer vision tasks.

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

[0072] Fuse the improved Faster_Rep with the C3 module of the original backbone network, and use the improved C3-FR backbone to replace the original backbone network;

[0073] S3: Prune the improved model; and use the above model to process the obtained whole image, describe the content of the whole image, and determine the class and position of the object according to the feature information of the target object, to complete the detection of the target;

[0074] Through the improvement of YOLOV5 algorithm, the detection effect of the whole algorithm is optimized.

[0075] Through the improvement of YOLOV5 algorithm, the detection effect of the whole algorithm is optimized. However, excessive parameters and computational load require more video memory to load the model, which requires higher hardware, and greatly affects the running speed of the model. In practical applications, algorithms often need to be transplanted to portable hardware platforms for ease of use. In order to meet the needs of practical applications, it is necessary to compress the pre-trained detection network model to reduce the parameters and volume of the detection model, thereby shortening the time consumed by model training and testing, and improving the detection rate.

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

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

[0078] Through a large amount of training, some γ distributions are constantly close to 0. They are sorted and given a threshold parameter according to the distribution. Finally, channels less than the threshold are directly removed to reduce their calculation amount and model size.

[0079] In the detection network, there is a batch normalization BN layer after each convolution layer, which normalizes the input data to speed up network convergence. The corresponding formula is:

[0080]

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

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

[0083]

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

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

[0086] Table 1 Model performance comparison

[0087] Model Crop rate mAP@0.5 / % P AR / 10 6 ]]> GFLOPs 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 more efficient model structure, faster inference speed and better computing efficiency without sacrificing accuracy and performance, the present application designs a lightweight backbone network by using RepConv in RepVGG to replace PConv module in FasterNet. RepConv is used to optimize the convolution operation inside the network, while RepVGG is characterized by its depthwise separable convolution and efficient architecture, integrated with FasterNet to form a lightweight backbone network. This combination fully utilizes the speed and efficiency advantages of RepVGG and the structural improvements of FasterNet, ensuring 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 the number of parameters, the present application integrates the redesigned backbone network into the C3 module of the original YOLOv5n architecture to form a C3-FR module. The C3-FR module integrates the advantages of the redesigned backbone network, balancing the model detection accuracy and reduced computational demand. By replacing or enhancing specific modules (such as C3) with optimized designs in lightweight backbone networks, 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, the present application proposes a detection model compression algorithm based on channel pruning. This 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 sacrificing its performance. This optimization makes the improved model more suitable for mobile devices and other resource-constrained environments, improving the deployment efficiency and practicality of the model.

[0091] The above is only the preferred embodiment of the present application, it should be pointed out that, for those skilled in the art, without departing from the principles of the present application, can make several improvements and refinements, these improvements and refinements should also be considered as the protection scope of the present application. The structures, devices and operation methods not specifically described and explained in the present application, such as no special description and limitation, are implemented according to the conventional means in the art.

Claims

1. An improved YOLOv5n-based target detection method, characterized in that: The detection method comprises the following contents: S1: obtaining an entire image; using RepConv to improve the FasterNet backbone network; Using RepConv in RepVGG to replace PConv in FasterNet; In the S1, the core idea of RepConv is to use a multi-branch structure to combine multiple convolution kernels and other operations, and if a structure containing three branches is used: a 3*3 convolution, a 1*1 convolution and an identity mapping; The outputs are respectively: Y1=W1*X Y2=W2*X Y3=X The three outputs are fused to obtain the final output: Y=Y1+Y2+Y3 Y=(W1*X)+(W2*X)+X During training, the above multi-branch structure is used, and during inference, the branches are re-parameterized into a single convolution kernel; the specific steps are as follows: S11: re-parameterization of the identity mapping: the identity mapping is represented as a 1*1 convolution with an identity convolution kernel, that is: Y3=X=W3*X Where W3 is a 1*1 identity convolution kernel; S12: convolution kernel fusion: the convolution kernels of all branches are fused into a convolution kernel, and if all the convolution kernels are of the same size, the fused convolution kernel is: W fused = W1 + W2 + W3 S13: single convolution operation in the inference stage: in the inference stage, only a single convolution operation is needed using the fused convolution kernel: Y = W fused *X; S2: replace the original C3 backbone network; Fuse the improved Faster_Rep with the original C3 module of the backbone network, and replace the original backbone network with the improved C3-FR backbone; S3: prune the improved model; and use the above model to process the obtained entire image, describe the entire image content, and determine the category and position of the object according to the feature information of the object, to complete the detection of the target; Through the improvement of the YOLOV5 algorithm, the detection effect of the entire algorithm is optimized.

2. The target detection method based on improved YOLOv5n according to claim 1, wherein: In the S3, the channel pruning judges the importance of different parameters in the training process, and removes the unimportant channels and their corresponding inputs and outputs, and the main process comprises: Sparse training of the network is performed to judge the importance of different channels, and unimportant channels are removed, and finally a pruned network model is obtained, and the channel sparse training and pruning process is given, and each channel in the convolution layer is allocated a scale factor γ to evaluate its importance; Through a large amount of training, some γ distributions are continuously close to 0, and the channels smaller than the threshold value are directly removed according to the distribution given threshold parameter, which is used to reduce the calculation amount and model size.

3. The target detection method based on improved YOLOv5n according to claim 2, characterized in that: In the detection network, there is a batch normalization BN layer after each convolution layer, which normalizes the input data to speed up the network convergence, and the corresponding formula is: where: y in and y out denote the input and output of the BN layer, μ and σ 2 denote the mean and variance of the input feature map, respectively; β is the bias; ε is a small factor to prevent the denominator from being 0.

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

Citation Information

Patent Citations

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

    CN117620147A

  • Network model rarefaction method fusing attention weight pruning

    CN117669665A