Lightweight target detection method based on YOLOv5
By introducing multi-scale efficient feature reorganization network and bidirectional weighted feature fusion network in YOLOv5, the problem of large amount of computing and feature redundancy in resource-constrained environments is solved, and the complexity and improved detection of lightweight object detection models are reduced. performance.
Patent Information
- Application Number
- CN202411327924.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-12-27
AI Technical Summary
YOLOv5 has a large amount of computing and memory usage in resource-constrained environments, which limits its application in mobile devices and embedded systems, especially the problem of large computing, many parameters and feature redundancy.
Design a multi-scale efficient feature recombination network MEFR-Net and a three-output bidirectional weighted feature fusion network TOBWF-Net to reduce model complexity and improve feature fusion capabilities, and build a lightweight object detection model based on YOLOv5, suitable for resource-constrained environments.
It significantly reduces the complexity and computing volume of the model while maintaining high detection accuracy. It is suitable for mobile devices and embedded systems, improving object detection performance.
Smart Images

Figure CN119206183A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to a lightweight target detection method based on YOLOv5, and belongs to the technical field of lightweight target detection. Technical Background
[0002] With the rapid development of computer vision technology, artificial intelligence technology continues to mature. As one of its core applications, target detection technology is widely used in industries such as foreign object recognition, road inspection, security monitoring, autonomous driving, drone navigation, and military reconnaissance.
[0003] At present, deep convolutional neural networks dominate the field of object detection. Object detection algorithms can be divided into two categories: one is a two-stage object detection algorithm represented by regional convolutional neural networks R-CNN, Fast R-CNN, etc., which first generates candidate boxes and then classifies and locates the candidate boxes. This method has high accuracy but slow speed; the other is a single-stage algorithm represented by SSD, YOLO series, etc. This type of algorithm treats both classification and object positioning as regression problems, and its advantage is fast speed. In recent years, single-stage methods (such as YOLO, RetinaNet, etc.) have been improved, and the overall algorithm performance is better than the two-stage method.
[0004] YOLOv5 is a commonly used single-stage target detection algorithm, providing four different sizes of models: YOLOv5s, YOLOv5m, YOLOv5l and YOLOv5x. Among them, YOLOv5s is the smallest and fastest model, but its computational complexity and memory usage are large for mobile devices, embedded systems and edge computing scenarios, which limits its application in resource-constrained environments. Therefore, it is necessary to design a lightweight network model to meet the use in resource-constrained environments. Summary of the invention
[0005] The problem to be solved by the present invention is to provide a lightweight target detection method based on YOLOv5, and to reduce the number of network parameters and the amount of calculation by proposing a multi-scale efficient feature reorganization network MEFR-Net (Multi-scale Efficient Feature Rearrangement Network), so as to achieve lightweight network. The neck network module of the model is constructed using a three-output bidirectional weighted feature fusion network TOBWF-Net (Tri-Output Bi-Directional Weighted Feature Fusion Network), so that the network can more effectively utilize information of different scales, while reducing the amount of calculation of the model, thereby improving the performance of target detection.
[0006] The technical solution of the present invention is: a lightweight target detection method based on YOLOv5, comprising the following steps:
[0007] Step S1, collecting target detection datasets containing four common target categories: pedestrians, vehicles, drones and ships, including 1000 pedestrian images, 500 ship images, 1000 vehicle images, and 2000 drone images;
[0008] Step S2: Use Mosaic to perform data enhancement operations on the acquired data set, and divide the data set into a training set, a validation set, and a test set in proportion, and finally obtain a data set for model training;
[0009] Step S3, designing a multi-scale efficient feature re-arrangement network MEFR-Net (Multi-scale Efficient Feature Rearrangement Network);
[0010] Step S4, using the multi-scale efficient feature recombination network MEFR-Net obtained in S3 and the three-output bidirectional weighted feature fusion network TOBWF-Net (Tri-Output Bi-Directional Weighted Feature Fusion Network) to build a lightweight target detection model based on YOLOv5, including an input module, a head network module, a neck network module and a detection module;
[0011] Step S5: Use the training set to train the constructed YOLOv5-based lightweight target detection model, and use the verification set to verify the trained model to obtain a trained YOLOv5-based lightweight target detection model;
[0012] Step S6: transplant the trained YOLOv5-based lightweight target detection model into the embedded processor BM1684, and test the performance of the model.
[0013] Compared with the prior art, the present invention adopts the above technical solution and has the following technical effects:
[0014] 1. The lightweight target detection method based on YOLOv5 is proposed in this paper. Aiming at the problems of large computational complexity, multiple parameters and feature redundancy in the feature extraction module of the original YOLOv5, a multi-scale efficient feature reconstruction network MEFR-Net is proposed. This module significantly reduces the complexity of the model while maintaining high accuracy.
[0015] 2. The lightweight target detection method of the present invention is based on YOLOv5. The three-output bidirectional weighted feature fusion network TOBWF-Net is used to construct the neck network module, so that the information in the feature network layer flows in two directions, from top to bottom and from bottom to top. At the same time, the weighted feature fusion module is introduced to enhance the network's ability to fuse features, so that the network can more effectively utilize information of different scales. In addition, while ensuring high detection effect, this method takes into account computational efficiency, thereby improving the performance of target detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 It is the distribution diagram of the number of various targets in the data set;
[0017] Figure 2 (a) is the schematic diagram of PConv structure; Figure 2 (b) is the schematic diagram of the Shuffle structure;
[0018] Figure 3 (a) is the schematic diagram of the SPConv structure; Figure 3 (b) is the schematic diagram of DSPConv structure;
[0019] Figure 4 (a) is the schematic diagram of the CBS structure; Figure 4 (b) is the structural principle diagram of MEFR-Net;
[0020] Figure 5 It is a network structure diagram of the network model of this patent;
[0021] Figure 6 This is a comparison chart of the parameters of MEFR-Net and C3 used in L2, L4, L6, and L8 in the backbone network;
[0022] Figure 7 (a) is a simplified diagram of the YOLOv5s neck network; Figure 7 (b) is a schematic diagram of the neck network of the network model of the present patent;
[0023] Figure 8 (a) is the recall rate graph of the YOLOv5s model; Figure 8 (b) is the recall rate graph of the network model of this patent;
[0024] Fig. 9 (a) is the detection accuracy graph of the YOLOv5s model; Fig. 9 (b) is the detection accuracy graph of the network model of this patent;
[0025] Figure 10(a) and Figure 10(b) are the test results of the model transplanted to the embedded processor BM1684. DETAILED DESCRIPTION
[0026] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the application is further elaborated in detail below in conjunction with the accompanying drawings. The described embodiments are only a part of the embodiments involved in the present invention. All non-innovative embodiments of other researchers in this field on this example belong to the protection scope of the present invention. At the same time, for the step numbering in the embodiment of the present invention, it is only set for the convenience of explanation, and the order between the steps is not limited in any way. The execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.
[0027] The present invention provides a lightweight target detection method based on YOLOv5, which includes the following steps:
[0028] Step S1, collecting target detection datasets containing four common target categories: pedestrians, vehicles, drones and ships, including 1000 pedestrian images, 500 ship images, 1000 vehicle images, and 2000 drone images;
[0029] Step S2: Use Mosaic to perform data enhancement operations on the acquired data set, and divide the data set into a training set, a validation set, and a test set in proportion, and finally obtain a data set for model training;
[0030] Step S3, designing a multi-scale efficient feature re-arrangement network MEFR-Net (Multi-scale Efficient Feature Rearrangement Network);
[0031] Step S4, using the multi-scale efficient feature recombination network MEFR-Net obtained in S3 and the three-output bidirectional weighted feature fusion network TOBWF-Net (Tri-Output Bi-Directional Weighted Feature Fusion Network) to build a lightweight target detection model based on YOLOv5, including an input module, a head network module, a neck network module and a detection module;
[0032] Step S5: Use the training set to train the constructed YOLOv5-based lightweight target detection model, and use the verification set to verify the trained model to obtain a trained YOLOv5-based lightweight target detection model;
[0033] Step S6: transplant the trained YOLOv5-based lightweight target detection model into the embedded processor BM1684, and test the performance of the model.
[0034] As a preferred technical solution of the present invention: in step S2, Mosaic is used to perform data enhancement and data segmentation on the acquired data set, and the steps are as follows:
[0035] Step S21, performing Mosaic data enhancement on the ship dataset and the drone dataset collected in step S1: randomly selecting four images, scaling, cropping, and splicing them;
[0036] Step S22: Mix the pedestrian data set and vehicle data set collected in S1 and the drone data set and ship data set that have undergone data enhancement in step S21, and then perform the same Mosaic data enhancement as step S21 on all data sets. The distribution of the number of each target in the data set after data enhancement is as follows: Figure 1 As shown, there are 2583 drone targets, 2105 vehicle targets, 3980 ship targets and 2080 pedestrian targets;
[0037] Step S23, divide the data set obtained in S22 into a training set, a validation set and a test set according to a ratio of 7:2:1.
[0038] As a preferred technical solution of the present invention: in step S3, the specific steps of designing a multi-scale efficient feature reconstruction network MEFR-Net are as follows:
[0039] Step S31: Figure 2 As shown in (a), PConv (partial convolution) selects the first 1 / λ of the input channels by a partial factor λ (λ can be divided by the number of channels) and applies conventional convolution to extract spatial features, leaving the remaining channels unchanged, and finally concatenates the channels that have undergone conventional convolution with the remaining channels in the original channel order;
[0040] Feature F input ∈R h*w*c Enter the PConv module, first use the partial factor λ to divide the input features into and Where h, w, c represent the input features F input The height, width, and number of channels;
[0041] Secondly, the feature map F 1 Perform conventional convolution to obtain F′ 1 , the feature map after convolution and F 2 For splicing, the calculation process is expressed as:
[0042] PConv(F input )=Concat(Conv 3_1 (F 1 ), F 2 )∈ Rh*w*c (1)
[0043] Among them, PConv(·) means passing through the PConv module, Concat(·) means splicing according to the channel dimension, Conv 3_1 (·) indicates a regular convolution with a kernel of 3*3 and a stride of 1;
[0044] Step S32: Add Shuffle (channel rearrangement) to PConv to obtain a new module SPConv (channel rearrangement partial convolution). The Shuffle principle is as follows: Figure 2 As shown in (b), Shuffle first collects the output of grouped convolution in the original channel order, then shuffles the channel order within each group and redistributes it to all groups to form a new channel arrangement. Shuffle can promote information exchange between different feature groups, increase feature diversity, and help improve the recognition and discrimination capabilities of the model;
[0045] The structure of SPConv is shown in the figure Figure 3 As shown in (a), by rearranging the feature map channels output by PConv, it is possible to promote effective information fusion while reducing the amount of computation and improve the learning ability of the model. inpuut∈ ∈R h*w*c The calculation process is expressed as:
[0046] SPConv(F input )=Shuffle(Pconv(F input ))∈R h*w*c (2)
[0047] Among them, SPConv(·) represents the channel rearrangement of the input features. Its structure is shown in the figure. Shuffle(·) represents the channel rearrangement of the input features.
[0048] Step S33: connect the two SPConv modules to obtain DSPConv (dual channel rearranged partial convolution), the network structure is as follows: Figure 3 As shown in (b), for input F input ∈R h*w*c The calculation process is expressed as:
[0049] DSPConv(F input )=SPConv(SPConv(F input ))∈R h*w*c (3)
[0050] Step S34: Combine the DSPConv module described in S33 with the original CBS module in YOLOv5 to design a multi-scale efficient feature reconstruction network MEFR-Net. input ∈R h*w*c The calculation process is expressed as:
[0051]
[0052] Among them, CBS Figure 4 As shown in (a), it consists of a regular convolution, a normalization layer, and an activation function. CBS 1_1 represents a conventional convolution with a convolution kernel of 1*1 and a stride of 1. MEFR(·) represents the input features after the multi-scale efficient feature reorganization network MEFR-Net. The network structure is as follows Figure 4 (b) as shown.
[0053] As a preferred technical solution of the present invention: in step S4, the steps of constructing a lightweight target detection model based on YOLOv5 are as follows:
[0054] Step S41: After the input module performs Mosaic data enhancement and scaling processing on the input image data, the image data with a size of 640*640*3 is input into the backbone network module Backbone for feature extraction;
[0055] Step S42, the backbone network module Backbone uses the multi-scale efficient feature reconstruction network MEFR-Net to replace the C3 module in the original YOLOv5 backbone network, such as Figure 5 As shown in the Backbone network module in the figure, the specific process is as follows:
[0056] The input image data passes through the CBS modules of L0 and L1, and the feature map is input to the MEFR-Net module of L2. The feature map size of L2 output is 160*160*64, which is used as the P2 layer feature of the head network (the size of the feature map becomes 1 / 4 of the original image) and is input to the neck network at the same time;
[0057] The feature map obtained by L2 is input to the CBS module of L3; the feature map obtained by L3 is input to the MEFR-Net module of L4, and the output feature map size is 80*80*128, which is used as the P3 layer feature of the head network (the size of the feature map becomes 1 / 8 of the original image); the feature map output by L4 is input to the CBS module of L5, and is also input to the neck network for feature fusion;
[0058] The feature map obtained by L5 is input to the MEFR-Net module of L6; the feature map output by L6 is 40*40*256 in size and is used as the P4 layer feature of the head network (the size of the feature map becomes 1 / 16 of the original image); the feature map output by L6 is input to the CBS module of L7 and then to the neck network for feature fusion;
[0059] The feature map obtained by L7 is input to the MEFR-Net module of L8; the feature map obtained by L8 is input to the SPPF module of L9; the feature map output by L9 is 20*20*512 in size and is used as the P5 layer feature of the head network (the size of the feature map becomes 1 / 32 of the original image); the feature map output by L9 is input to the Neck network module, and the feature extraction process of the backbone network module Backbone is completed;
[0060] In the backbone network, L2, L4, L6 and L8 use C3 and the parameters of the multi-scale efficient feature reconstruction network MEFR-Net module respectively. Figure 6 As shown. Among them, the input and output feature map size of L2 is 160*160*64, and the number of MEFR-Net module parameters is 51.0% of the number of C3 parameters; the input and output feature map size of L4 is 80*80*128, and the number of MEFR-Net module parameters is 36.7% of the number of C3 parameters; the input and output feature map size of L6 is 40*40*256, and the number of MEFR-Net module parameters is 30.0% of the number of C3 parameters; the input and output feature map size of L8 is 20*20*512, and the number of MEFR-Net module parameters is 50.7% of the number of C3 parameters;
[0061] Step S43: In the neck network module, MEFR-Net is used to replace the C3 module in the original YOLOv5 neck network, and a three-output bidirectional weighted feature fusion network TOBWF-Net neck network module is used, such as Figure 5 As shown in the Neck network module;
[0062] Step S44: The output module obtains the final frame-selected image data as the prediction result from the input final feature map data and outputs it. Figure 5 As shown in the Detect module in , the size of the feature map output by the L21 layer is 80*80*128, which is used for small target detection; the size of the feature map output by the L24 layer is 40*40*256, which is used for medium target detection; the size of the feature map output by the L27 layer is 20*20*512, which is used for large target detection.
[0063] As a preferred technical solution of the present invention: in step S43, it is characterized in that, in the TOBWF-Net module, in the original feature pyramid network of YOLOv5, all input features are treated equally without distinction, and features of different layers are simply added together without considering their contribution to the output features. TOBWF-Net performs weighted fusion WFF (Weighted Feature Fusion) on the input features and dynamically adjusts the fusion weights to allow the network to learn the importance of each input feature, as shown below:
[0064]
[0065] Among them, I i represents the input feature; w i and w j Represents the input features I i and I j The corresponding weight parameter; ε represents the balance constant to prevent unstable jitter during model training; O represents the output after weighted fusion WFF of the input features;
[0066] Secondly, each bidirectional path (top-down and bottom-up) of TOBWF-Net is regarded as a separate feature network layer, and then these layers can be reused multiple times, which is conducive to the lightweight design of the model. At the same time, TOBWF-Net constitutes a simplified bidirectional network, which enhances the network's ability to fuse features, enabling the network to more effectively utilize information of different scales, thereby improving the performance of target detection;
[0067] The original YOLOv5s neck network is as follows Figure 7 As shown in (a), the neck network improved by TOBWF-Net is shown in Figure 7 (b) shows the input features of the network After weighted calculation, the output feature The calculation method of is shown in formulas (6) to (10):
[0068]
[0069]
[0070]
[0071]
[0072]
[0073] In the above formula: w i is the learnable weight parameter; is the intermediate feature; ε is the equilibrium constant; ResizeO means corresponding upsampling or downsampling; ConvO means convolution operation on the feature; The subscript i in the layer indicates that the feature map size of this layer is the original image.
[0074] As a preferred technical solution of the present invention: in step S5, it is characterized in that the constructed lightweight target detection model based on YOLOv5 is trained in the following steps:
[0075] Step S51, setting model parameters including confidence threshold conf-thres, model file weights, detection image and label path source, image preprocessing size img-size, pre-training weight cfg, and hyperparameter hyp;
[0076] Step S52: scaling and enhancing the txt file converted from the training image of the training subset, and performing pixel padding on the image to ensure that the image size is the set value;
[0077] Step S53: reset the model gradient, send the training images to the YOLOv5-based lightweight target detection model in batches through the iterator, perform forward propagation, and obtain the prediction results;
[0078] Step S54: Calculate the loss function for the prediction result, and perform gradient calculation and back propagation according to the loss function;
[0079] Step S55, using the momentum method and the SGD small batch stochastic gradient descent algorithm to update the model parameters according to the gradient;
[0080] Step S56, repeat steps S53 to S55 to perform a set number of training rounds, set the training rounds to 200, and use the training results of the YOLOv5s model and the network model of this patent as shown in Figure 8 (a) Figure 8 (b) Fig. 9 (a) Fig. 9 (b)
[0081] Table 1 Performance comparison between YOLOv5s and this patented network model
[0082]
[0083] As shown in Table 1, the number of parameters in the network model of this patent is 62.0% of the number of parameters in YOLOv5s, the amount of calculation is reduced by 4.7GFLOPs compared with YOLOv5s, and the accuracy is increased by 0.001 compared with YOLOv5s. In summary, the lightweight target detection model proposed in this patent significantly reduces the demand for computing resources while maintaining the detection performance equivalent to the original YOLOv5s, meeting the demand for lightweight models.
[0084] As a preferred technical solution of the present invention: in step S6, it is characterized in that the trained YOLOv5-based lightweight target detection model is transplanted into the embedded processor BM1684, and the performance of the model is tested, the steps are as follows:
[0085] Step S61, converting the trained YOLOv5-based lightweight target detection model into an FP32 Bmodel model running on the BM1684 platform;
[0086] Step S62: Based on the BM1684 hardware acceleration interface, the pre-processing, post-processing and reasoning algorithms of the converted detection model are transplanted;
[0087] Step S63: Input images containing vehicles, pedestrians, ships and drones to test the transplanted YOLOv5-based lightweight target detection model. The test results are shown in Figures 10(a) and 10(b). According to the number of input images and the total time of target detection, the average time spent on processing one image is 28ms.
[0088] It can be seen from the test results that the present invention can achieve lightweight while maintaining good accuracy, realizing the lightweight design of the model, and is suitable for mobile devices, embedded systems and edge computing scenarios.
[0089] The embodiments of the present invention are described in detail above with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge scope of ordinary technicians in this field without departing from the purpose of the present invention.
Claims
1. A lightweight target detection method based on YOLOv5, characterized in that: The following steps are involved: Step S1, collecting target detection datasets containing four common target categories: pedestrians, vehicles, drones and ships, including 1000 pedestrian images, 500 ship images, 1000 vehicle images, and 2000 drone images; Step S2: Use Mosaic to perform data enhancement operations on the acquired data set, and divide the data set into a training set, a validation set, and a test set in proportion, and finally obtain a data set for model training; Step S3, designing a multi-scale efficient feature rearrangement network MEFR-Net (Multi-scale Efficient Feature Rearrangement Network); Step S4, using the multi-scale efficient feature recombination network MEFR-Net obtained in S3 and the three-output bidirectional weighted feature fusion network TOB WF-Net (Tri-Output Bi-Directional Weighted Feature Fusion Network) to build a lightweight target detection model based on YOLOv5, including an input module, a head network module, a neck network module and a detection module; Step S5: Use the training set to train the constructed YOLOv5-based lightweight target detection model, and use the verification set to verify the trained model to obtain a trained YOLOv5-based lightweight target detection model; Step S6: transplant the trained YOLOv5-based lightweight target detection model into the embedded processor BM1684, and test the performance of the model.
2. The lightweight target detection method based on YOLOv5 according to claim 1, characterized in that: In step S2, Mosaic is used to perform data enhancement and data segmentation on the acquired data set. The steps are as follows: Step S21, performing Mosaic data enhancement on the ship dataset and the drone dataset collected in step S1: randomly selecting four images, scaling, cropping, and splicing them; Step S22: Mix the pedestrian dataset and vehicle dataset collected in S1 and the dataset enhanced in step S21, and then perform the same Mosaic data enhancement as step S21 on all datasets. The final dataset contains 2583 drone targets, 2105 vehicle targets, 3980 ship targets, and 2080 pedestrian targets; Step S23, divide the data set obtained in S22 into a training set, a validation set and a test set according to a ratio of 7:2:
1.
3. The lightweight target detection method based on YOLOv5 according to claim 1, characterized in that: In step S3, a multi-scale efficient feature reconstruction network MEFR-Net is designed. The steps are as follows: Step S31, PConv (partial convolution) selects the first 1 / λ of the input channel by the partial factor λ (λ can be divided by the number of channels) and applies conventional convolution to extract spatial features, leaving the remaining channels unchanged, and finally concatenates the channels that have undergone conventional convolution with the remaining channels in the original channel order; Feature F input ∈R h*w*c Enter the PConv module, first use the partial factor λ to divide the input features into and Where h, w, c represent the input features F input The height, width, and number of channels; Secondly, perform conventional convolution on the feature map F1 to obtain F′1, and concatenate F′1 with F2. The calculation process is expressed as: PConv(F input )=Concat(Conv 3_1 (F1),F2)∈R h*w*c (1) Among them, PConv(·) means passing through the PConv module, Concat(·) means splicing according to the channel dimension, Conv 3_1 (·) indicates a regular convolution with a kernel of 3*3 and a stride of 1; Step S32: Add Shuffle (channel rearrangement) to PConv to obtain a new module SPConv (channel rearrangement partial convolution). Channel rearrangement can rearrange features from different sources by channel. By performing Shuffle operation on the feature channels output by PConv, it is possible to promote effective fusion of information while ensuring the reduction of computational complexity, and improve the learning ability of the model. input∈ ∈R h*w*c The calculation process is expressed as: SPConv(F input )=Shuffle(Pconv(F input ))∈R h*w*c (2) Among them, SPConv(·) represents the channel rearrangement of the input features, and Shuffle(·) represents the channel rearrangement of the input features; Step S33: Connect two SPConv modules to obtain DSPConv (dual channel rearranged partial convolution). input ∈R h*w*c The calculation process is expressed as: DSPConv(F input )=SPConv(SPConv(F input ))∈R h*w*c (3) Among them, DSPConv(·) represents the double channel rearrangement partial convolution of the input features; Step S34: Combine the DSPConv module described in S33 with the original CBS module in YOLOv5 to design a multi-scale efficient feature reconstruction network MEFR-Net. input ∈R h*w*c The calculation process is expressed as: Among them, CBS consists of a regular convolution, a normalization layer and an activation function. 1_1 represents a conventional convolution with a kernel of 1*1 and a stride of 1, and MEFR(·) represents the input features after the multi-scale efficient feature reconstruction network MEFR-Net.
4. The lightweight target detection method based on YOLOv5 according to claim 1, characterized in that: In step S4, a lightweight target detection model based on YOLOv5 is constructed, including an input module, a head network module, a neck network module, and a detection module. The steps are as follows: Step S41: The input module performs Mosaic data enhancement and scaling processing on the input image data, and the processed image data with a size of 640*640*3 is input into the backbone network module Backbone; Step S42, the backbone network module Backbone uses the multi-scale efficient feature reconstruction network MEFR-Net to replace the C3 module in the original YOLOv5 backbone network; Step S43: In the neck network module Neck network, MEFR-Net is used to replace the C3 module in the original YOLOv5 neck network, and a three-output bidirectional weighted feature fusion network TOBWF-Net is used to construct a neck feature fusion network; Step S44: The detection module obtains the final frame-selected image data as a prediction result from the input final feature map data and outputs it.
5. The lightweight target detection method based on YOLOv5 according to claim 4, characterized in that: In step S43, the three-output bidirectional weighted feature fusion network TOBWF-Net, in the original feature pyramid network of YOLOv5, all input features are treated equally without distinction, and features of different layers are simply added together without considering their contribution to the output features. TOBWF-Net performs weighted fusion WFF (Weighted Feature Fusion) on the input features and dynamically adjusts the fusion weights to allow the network to learn the importance of each input feature, as shown below: Where i represents the index of the input feature, I i represents the input feature, w i and w j Represents the input features I i and I j The corresponding weight parameter, ∈ represents the equilibrium constant, and O represents the output after weighted fusion WFF; Secondly, each bidirectional path (top-down and bottom-up) of TOBWF-Net is regarded as a separate feature network layer, which can be reused multiple times, which is conducive to the lightweight design of the model. At the same time, TOBWF-Net constitutes a simplified bidirectional network, which enhances the network's ability to fuse features, enabling the network to more effectively utilize information of different scales, thereby improving the performance of target detection.
6. The lightweight target detection method based on YOLOv5 according to claim 1, characterized in that: In step S5, the constructed YOLOv5-based lightweight target detection model is trained as follows: Step S51, setting model parameters including confidence threshold conf-thres, model file weights, detection image and label path source, image preprocessing size img-size, pre-training weight cfg, and hyperparameter hyp; Step S52: scaling and enhancing the txt file converted from the training image of the training subset, and performing pixel padding on the image to ensure that the image size is the set value; Step S53: reset the model gradient, send the training images to the YOLOv5-based lightweight target detection model in batches through the iterator, perform forward propagation, and obtain the prediction results; Step S54: Calculate the loss function for the prediction result, and perform gradient calculation and back propagation according to the loss function; Step S55, using the momentum method and the SGD small batch stochastic gradient descent algorithm to update the model parameters according to the gradient; Step S56, repeat steps S53 to S55 to perform the set number of trainings.
7. The lightweight target detection method based on YOLOv5 according to claim 1, characterized in that: In step S6, the trained YOLOv5-based lightweight target detection model is transplanted into the embedded processor BM1684, and the performance of the model is tested. The steps are as follows: Step S61, converting the trained YOLOv5-based lightweight target detection model into an FP32 Bmodel model running on the BM1684 platform; Step S62: Based on the BM1684 hardware acceleration interface, the pre-processing, post-processing and reasoning algorithms of the converted detection model are transplanted; Step S63: input images containing vehicles, pedestrians, ships and drone targets to test the transplanted YOLOv5-based lightweight target detection model.
