A multi-target garbage detection method based on an improved YOLOv5 model
By improving the YOLOv5 model and introducing lightweight networks and feature reuse techniques, the problems of low detection efficiency and high resource consumption in multi-target garbage detection are solved, achieving efficient and accurate garbage identification and detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-18
- Publication Date
- 2026-03-03
AI Technical Summary
Existing technologies for multi-target garbage detection suffer from low detection efficiency, high resource consumption, and high false positive and false negative rates, especially in complex scenarios where it is difficult to effectively extract feature information.
An improved YOLOv5 model is adopted, and a lightweight hybrid network MobileViTv3 is introduced as the feature extraction network. The feature extraction is optimized by combining dynamic convolution ODConv and efficient model block EfficientFormer block. The feature fusion network is reconstructed using feature reuse techniques Ghost Module and RepGhost Module, and the model structure is optimized to adapt to multi-target garbage detection.
It improves the recognition accuracy and detection speed of multi-target garbage detection, reduces computing resource consumption, can run efficiently on resource-constrained devices, and is suitable for practical detection scenarios.
Smart Images

Figure CN116452950B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural image target detection, and relates to an automatic garbage detection method, particularly to a technology for identifying and detecting multi-target garbage. Background Technology
[0002] Waste sorting is not only a crucial foundation for achieving harmless, reduced, and recyclable waste, but also an inevitable trend in social development. However, current waste detection and sorting primarily rely on manual labor, which suffers from low efficiency, high workload, and poor sanitation. With the rapid development of artificial intelligence technology, intelligent waste sorting offers a new and effective solution to the current waste detection and sorting problems.
[0003] The key to achieving intelligent waste sorting lies in the need for efficient object detection algorithms as technical support. Traditional object detection algorithms rely on manual feature extraction, which suffers from extremely poor robustness and performance that fails to meet the needs of practical applications. With the rise of deep learning technology, Convolutional Neural Networks (CNNs) have overcome the technical bottleneck of feature extraction in traditional object detection algorithms. Their powerful hierarchical representation capabilities have shone brightly in various detection tasks. Therefore, these algorithms are also widely used in the field of waste detection.
[0004] However, most current CNN-based garbage detection research focuses on single-target or few-target garbage images with limited categories, rarely addressing multi-target garbage images in real-world scenarios, thus lacking practicality for detection in real-life situations. Furthermore, while some studies have ported garbage detection algorithms to embedded modules, most models still have a huge number of parameters or computational demands, consuming significant computing resources and failing to perform well on resource-constrained devices, greatly impacting detection performance. In addition, in multi-target garbage detection tasks, garbage targets exhibit inter-class similarity, intra-class differences, and mutual occlusion. These characteristics directly hinder the model from extracting useful feature information to distinguish targets, ultimately leading to false positives and false negatives. Therefore, designing an efficient multi-target garbage detection algorithm is essential. Summary of the Invention
[0005] The purpose of this invention is to provide a multi-target garbage detection method based on deep learning technology, which overcomes the shortcomings of existing research in the field of multi-target garbage detection, effectively improves the ability to locate and identify dense multi-target garbage, and independently develops a multi-target garbage detection system based on this algorithm.
[0006] The present invention provides an automatic multi-target waste detection and identification method based on improved YOLOv5, comprising the following steps:
[0007] (1) First, multi-target garbage image data is acquired by camera and the dataset is preprocessed.
[0008] (2) In view of the lack of research in the field of multi-target garbage detection, a multi-target garbage detection model based on improved YOLOv5 is proposed. The improvement methods include introducing the hybrid network MobileViTv3 as the feature extraction network; using dynamic convolution ODConv and efficient model block EfficienFormer to optimize the feature extraction module; and using feature reuse technology to reconstruct the feature fusion network.
[0009] (3) The preprocessed multi-target garbage image data is fed into the improved YOLOv5 model for training and validation, and the model is tested using a test set. The final performance of the model is evaluated through multiple evaluation metrics.
[0010] (4) Input the garbage image to be detected into the weights of the improved YOLOv5 model obtained through training, and output the detection result by calculation.
[0011] Furthermore, the preprocessing method described in step 1 specifically includes:
[0012] (1.1) Set the corresponding categories for the dataset and label them using the image annotation software LabelImg. Then divide the dataset into training and test sets in a 7:3 ratio.
[0013] (1.2) The Mosaic data augmentation algorithm is used to randomly flip, scale and perform other operations on the four garbage images input to the network each time. Then, the images are stitched together in the order of top left, top right, bottom left and bottom right to form a new image. A fixed-size area is randomly cropped from the stitched image to form a new image.
[0014] (1.3) The adaptive anchor box calculation method is used to recalculate the anchor boxes for each training dataset to match the anchor box values that are most suitable for the current dataset, thereby improving the network's ability to locate and regress the target to be detected.
[0015] (1.4) Use an adaptive image scaling method to scale the original image to a resolution of 640*h or w*640, where h and w are both less than or equal to 640 pixels. In order to input the image into the network at a uniform size of 640*640, gray-white and black borders are added to complete the length or width of the scaled image, thereby reducing the computational load of the model and improving the training efficiency of the model.
[0016] Furthermore, the multi-target garbage detection method based on the improved YOLOv5 described in step 2 is specifically as follows:
[0017] (2.1) The hybrid network MobileViTv3 is used to replace the original YOLOv5 feature extraction network for global feature encoding of multi-target garbage, enabling the model to refine features and thus accurately locate target garbage in high-density scenes. MobileViT is built by combining the structural advantages of CNN and Transformer. It can easily achieve effective extraction of local and global features of images with a small number of parameters, effectively alleviating the problem of incomplete or even lost target feature information extraction caused by the limited receptive field of the original YOLOv5.
[0018] (2.2) Dynamic convolution ODConv is introduced to replace the convolution operation in the local representation module of the MobileViT block. It focuses on learning target features by dynamically generating attention values to address the problem of false positives and false negatives in complex garbage detection. Dynamic convolution ODConv dynamically generates attention weight values to adjust the convolution parameters according to different input features. Specifically, for the input feature X, it is first compressed into a 1×1×C form using GAP. in The feature vectors are aggregated and mapped to a low-dimensional space using an FC layer with a dimensionality reduction ratio r. Then, they are processed in parallel along the convolution kernel W. n The spatial dimension, input channel dimension, output channel dimension, and kernel dimension (4 parallel FC layers) are calculated to obtain sizes of k×k, C, and C, respectively. in ×1、C out We use feature tensors of size 1 and n×1, and generate attention weights α using either the Sigmoid or Softmax function, respectively. sn α cn α fn and α wn Finally, the generated attention weights are weighted and summed with their corresponding convolutional kernels to obtain a new convolution. 0DConv can be represented as:
[0019] y=(α w1 ⊙α f1 ⊙α c1 ⊙α s1 ⊙W1+…+α wn ⊙α fn ⊙α cn ⊙α sn ⊙W n )*x
[0020] in These represent the values at the convolution kernel W. n Attention weights are calculated based on the spatial dimension, input dimension, output channel dimension, and kernel dimension. ⊙ represents a multiplication operation along different dimensions of the kernel space. + represents an addition operation. * represents a new convolution formed by aggregating the four attention weights.
[0021] (2.3) The EfficientFormer block is introduced to replace the Linear Transformer in the global representation module of the MobileViT block. This extracts global information in a smoother manner, reducing the impact of redundant information and alleviating the huge computational burden of the Transformer. The EfficientFormer block removes the Layer Normalization (LN) layer from the original Transformer. In the spatial MLP, it replaces the original LN combination with a 1×1 convolutional combination with batch normalization (BN) with a 3D linear mapping, eliminating complex reshape operations and unifying feature dimensions. Furthermore, it fully utilizes the fusion mechanism of convolution and BN during model inference to improve inference speed. The EfficientFormer block can be represented as:
[0022] Y = Pooling(X) + X, (3)
[0023] z = Conv B (Conv B,G (Y))+Y,(4)
[0024] Where Pooling represents the space pooling operator. Conv B,G In this context, B and G refer to whether batch normalization (BN) and the activation function GeLU are used after the convolution operation, respectively.
[0025] (2.4) The convolutional and C3 modules in the YOL0v5 feature fusion network were redesigned using the feature reuse techniques GhostModule and RepGhostModule, maintaining the model's ability to express and fuse multi-scale objects with lower computational cost. In this invention, we replaced the convolutional operations in the Path Aggregation Network (PAN) with GhostModule; and replaced the convolutional operations in the original Bottleneck with RepGhostModule, proposing RepGhostBottleneck, thus forming the new RepGhostC3. GhostModule maintains the input network capacity by reusing features through concatenation operations. It divides the convolution into two parts: one part uses standard convolution to reduce dimensionality and generate a certain number of feature maps, and the other part uses linear operations (DWConv) to complete the missing feature maps. The formula for the feature reuse technique of GhostModule is as follows:
[0026] y=Cat([x,Φ1(x),...,Φ n-1 (x)])
[0027] Where Cat represents the concatenation operation, and n is the scaling factor for the control dimension. This represents the output feature after feature reuse. This indicates the input features that need to be processed and reused. This represents a neural network layer, such as the DWConv layer, where the generated feature tensors have a total dimension of ((n-1) / n)*C. out .
[0028] The RepGhost Module utilizes reparameterization to achieve efficient feature reuse. To address the issue of high memory consumption caused by concatenated operations, the RepGhost Module introduces reparameterization (two parallel layers) in the DWConv part to generate different feature maps. Feature reuse is implicitly achieved by fusing features from different layers during training, enhancing the network's ability to interact with contextual information. The formula for the RepGhost Module's feature reuse technique is as follows:
[0029] y=Add([x,Φ1(x),…,Φ n-1 (x)])=Φ * (x)
[0030] Where Add represents the adder. This represents the feature tensor generated by the linear function in the structural reparameterization, with a total dimension of n*C. out Φ i It will eventually merge into
[0031] Furthermore, the training, validation, and testing methods for the improved YOLOv5 model described in step 3 are as follows:
[0032] (3.1) Input the preprocessed multi-objective garbage dataset from step 1 into the improved network for training in multiple iterations. After each iteration, use the test set to verify the performance of the model generated in each iteration, and save the optimal model weight file by comparison.
[0033] (3.2) Use the test set to test the best model obtained from the final training. Evaluate the model performance through evaluation indicators such as the number of model parameters, computational cost, average accuracy and detection speed, so as to determine whether the model can be effectively deployed in multi-target garbage detection tasks.
[0034] Furthermore, the method for detecting multi-target garbage images using the improved model described in step 4 is as follows: First, the image to be detected is adaptively scaled to 640*640 according to method (1.3), and loaded into (3.2) to obtain the optimal model weights. The image is input into the model weights and linear and nonlinear calculations are performed respectively through convolution kernels and activation functions. Then, three detection branches [20*20*C], [40*40*C], and [80*80*C] are used to detect and identify targets of different scales in the image. The formula for dimension C is:
[0035] C = (n + xywh + CS) * anchors
[0036] Where n is the number of output target categories, xywh are the position coordinates of each target, CS is the confidence score of each target, and anchors represent the number of anchor boxes set for each detection branch.
[0037] This invention also provides a garbage detection system based on the proposed multi-target detection algorithm to meet the needs of practical applications.
[0038] The specific functions of the system include: static detection of a single garbage image or multiple garbage images in a single folder; in terms of real-time detection, it is also equipped with video detection function, and the system can call the camera to realize visual monitoring of garbage detection in the garbage sorting environment.
[0039] This invention has the following characteristics:
[0040] 1. This invention introduces the lightweight hybrid network MobileViTv3 as the feature extraction network for YOLOv5. While meeting the requirements of embedded hardware devices with fewer parameters, it enhances the model's global representation capabilities and effectively improves the model's accuracy in recognizing multi-target garbage images.
[0041] 2. This invention uses the EfficientFormer block and the dynamic convolution ODConv to replace the components of the MobileViT block, thereby reducing the impact of redundant features and focusing on learning important feature information, effectively solving the problems of missed detection and false detection of complex garbage targets.
[0042] 3. This invention introduces the feature reuse techniques Ghost Module and RepGhost Module to redesign the constituent units of the feature extraction network. While further reducing the computational cost of the model, it largely preserves the model's ability to fuse and interact with contextual information, thus maintaining the model's detection performance.
[0043] 4. The multi-target waste detection algorithm proposed in this invention is suitable for practical detection scenarios. It can quickly and accurately detect and identify multi-target waste, and has significant advantages in lightweight deployment. Therefore, this invention also develops a multi-target waste detection system based on this algorithm to meet the needs of practical applications. Attached Figure Description
[0044] Figure 1 This is a flowchart of the multi-target garbage detection algorithm proposed in this invention.
[0045] Figure 2 This is a structural diagram of the MobileVi block in the MobileViTv3 feature extraction network used in this invention.
[0046] Figure 3 This is a structural diagram of the ED-Mobile block feature extraction module proposed in this invention.
[0047] Figure 4 This is a schematic diagram of the dynamic convolution ODConv used in this invention.
[0048] Figure 5 This is a structural diagram of the EfficientFormer model block used in this invention.
[0049] Figure 6 This is a schematic diagram of the feature reuse technology Ghost Module used in this invention.
[0050] Figure 7 This is a schematic diagram of the feature reuse technology RepGhost Module used in this invention.
[0051] Figure 8 This is a structural diagram of the element module RepGhostC3 in the feature fusion network proposed in this invention.
[0052] Figure 9 This is a diagram of the LYOLO-MTG network structure proposed in this invention.
[0053] Figure 10 This is a comparison of the average accuracy curves of the LYOLO-MTG network and the YOLOv5 network proposed in this invention.
[0054] Figure 11 This is a comparison chart of the detection results of the LYOLO-MTG proposed in this invention with those of mainstream networks.
[0055] Figure 12 This is a flowchart of the operation of the waste detection system.
[0056] Figure 13 These are images of multiple targets of garbage that were actually collected.
[0057] Figure 14 This is a detection result image of the multi-target garbage images actually collected. Detailed Implementation
[0058] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.
[0059] This invention proposes a multi-target garbage detection algorithm suitable for real-world scenarios, combining... Figures 1 to 14 Detailed explanation is as follows:
[0060] like Figure 1 The flowchart shown is a multi-target litter detection algorithm based on an improved YOLOv5 network proposed in this invention. In this process, firstly, multi-target litter image data is acquired via a camera, and the dataset undergoes Mosica data augmentation, adaptive anchor boxes, and adaptive image scaling preprocessing. Secondly, the YOLOv5 model is improved to suit the multi-target litter detection task. The improvements include introducing a hybrid network, MobileViTv3, as the feature extraction network; optimizing the feature extraction module using dynamic convolution ODConv and an efficient model block, EfficienFormer; and reconstructing the feature fusion network using feature reuse techniques. Then, the image data is input into the improved YOLOv5 model at a fixed size of 640*640 for training and validation, and tested using a test set. Finally, the litter images to be detected are input into the model weights of the proposed multi-target litter automatic detection method, and the detection results are output through calculation.
[0061] like Figure 2 The diagram shows the structure of the MobileViT block in the MobileViTv3 feature extraction network used in this invention. The MobileViT block is a crucial factor determining network performance. It consists of three sub-modules: a local representation module, a global representation module, and a feature fusion module. The local and global representation modules model the local and global features of the input features using convolution and Linear Transformer, respectively. The feature fusion module uses a concatenation operation to efficiently fuse the local and global features.
[0062] like Figure 3The diagram shows the structure of the ED-Mobile block, the feature extraction module proposed in this invention. The ED-Mobile block retains the design structure of the MobileViT block, which is a combination of three modules: local representation, global representation, and feature fusion. Dynamic convolution ODConv replaces the convolutional operations in the original local representation module, learning different spam features by dynamically generating attention, thus improving the network's ability to identify complex spam. The original Linear Transformer is replaced by the EfficientFormer block, eliminating the cumbersome Unfold and Fold operations, unifying the feature dimensions, simplifying the global representation extraction process, and accelerating the model's inference speed.
[0063] like Figure 4 This is a schematic diagram of the dynamic convolution ODConv used in this invention. Specifically, the input feature X is first compressed into a 1×1×C vector using GAP. in The feature vectors are aggregated and mapped to a low-dimensional space with a dimensionality reduction ratio r using an FC layer and a ReLU activation function. Then, they are processed in parallel along the convolution kernel W. n The spatial dimension, input channel dimension, output channel dimension, and kernel dimension (4 parallel FC layers) are calculated to obtain sizes of k×k, C, and C, respectively. in ×1、C out Tensors of size ×1 and n×1 are used, and attention weights α are generated using either the Sigmoid or Softmax function, respectively. sn α cn α fn and α wn Finally, the generated attention weights are weighted and summed with the corresponding convolutional kernels to obtain a new convolution. Figure 7 The process of multiplying attention by the convolution kernel is demonstrated in four ways. Therefore, ODConv can be represented as:
[0064] y=(α w1 ⊙α f1 ⊙α c1 ⊙α s1 ⊙W1+…+α wn ⊙α fn ⊙α cn ⊙α sn ⊙W n )*x (5)
[0065] in These represent the values at the convolution kernel W. nAttention weights are calculated based on the spatial dimension, input dimension, output channel dimension, and kernel dimension. ⊙ represents a multiplication operation along different dimensions of the kernel space. + represents an addition operation. * represents a new convolution formed by aggregating the four attention weights.
[0066] like Figure 5 This is the structure diagram of the EfficientFormer block used in this invention. The EfficientFormer block replaces the Transformer's multi-head attention mechanism with spatial pooling operators, eliminates layer normalization (LN) layers, and replaces the original layer normalization (LN) combination with 1×1 convolutions with batch normalization (BN) in the spatial MLP with 1×1 convolutions, removing complex reshape operations and unifying feature dimensions. Furthermore, it fully utilizes the advantages of the fusion mechanism between convolutions and BN during model inference, improving inference speed. The EfficientFormer block can be represented as:
[0067] Y = Pooling(X) + X, (3)
[0068] Z = Conv B (Conv B,G (Y))+Y, (4)
[0069] Where Pooling represents the space pooling operator. Conv B,G In this context, B and G refer to whether batch normalization (BN) and the activation function GeLU are used after the convolution operation, respectively.
[0070] like Figure 6 The diagram shows a schematic of the feature reuse technique Ghost Module used in this invention. Ghost Module maintains the input network capacity by reusing features through concatenation operations. The structure of Ghost Module is shown in the figure. It divides the convolution into two parts: one part uses standard convolution to reduce dimensionality and generate a certain number of feature maps, and the other part uses linear operations (DWConv) to complete the missing feature maps. The feature reuse technique of Ghost Module can be expressed as:
[0071] y=Cat([x,Φ1(x),...,Φ n-1 (x)])
[0072] Where Cat represents the concatenation operation, and n is the scaling factor for the control dimension. This represents the output feature after feature reuse. This indicates the input features that need to be processed and reused. This indicates that a neural network layer, such as a depthwise convolution layer, generates a feature tensor with a total dimension of ((n-1) / n)*C. out .
[0073] like Figure 7 The diagram shows the RepGhost Module, the feature reuse technology used in this invention. RepGhostModule utilizes reparameterization to achieve efficient feature reuse. To address the issue of high memory consumption from concatenated operations, RepGhost Module introduces reparameterization (two parallel layers) in the DW convolution part to generate different feature maps. Feature reuse is implicitly achieved by fusing features from different layers during training, enhancing the network's ability to interact with contextual information. Simultaneously, during inference, feature weights from the branch BN layer are fused into the weights of the main branch DWConv and the BN layer, forming a simple inference block, i.e., a 3×3 DConv. This shifts the fusion process from the feature space to the weight space. Without any time cost, the complex parallel structure during training is equivalently transformed into a simple serial structure during inference, enabling the model to perform efficient inference on hardware devices. The feature reuse technology of GhostModule can be represented as:
[0074] y=Add([x,Φ1(x),…,Φ n-1 (x)])=Φ*(x)
[0075] Where Add represents the adder. This represents the feature tensor generated by the linear function in the structural reparameterization, with a total dimension of n*C. out Φ i It will eventually merge into
[0076] like Figure 8 The image shows the element module RepGhostC3 in the feature fusion network proposed in this invention. The RepGhostModule replaces the convolutional operations in the original Bottleneck, resulting in the new RepGhostC3. RepGhostC3 retains the cross-stage hierarchical structure of the original C3 and learns rich gradient combination information with fewer parameters, maintaining the model's feature fusion capability.
[0077] This invention proposes the LYOLO-MTG network based on YOLOv5. The structure of the LYOLO-MTG network is as follows: Figure 9As shown, in the backbone network, a lightweight hybrid network, MobileViTv3, is introduced as the feature extraction network. This ensures that the model can be embedded in resource-constrained devices with a small size while fully considering the global features of multi-target garbage. An EfficientFormer block replaces the Linear Transformer, smoothing the global representation of the image, simplifying the global feature extraction process, and reducing the model's computational cost. Dynamic convolution ODConv replaces the convolutional operations in the local representation module of the MobileViT block, focusing on learning important features by dynamically generating attention. In the feature fusion network, the Neck is reconstructed based on the RepGhost Module and GhostModule, which utilize feature reuse technology. A lightweight RepG-neck is proposed, further reducing the network weight while largely preserving the ability to fuse and interact with contextual information.
[0078] To verify the effectiveness of the proposed LYOLO-MTG algorithm, ablation experiments were conducted to demonstrate the superiority of the method used in this invention. For fair comparison, the same dataset and experimental environment were used in all experiments. In the experiments, YOLOv5s was used as the baseline network, and four combination strategies were sequentially introduced to optimize and improve the components of YOLOv5s: the hybrid network MobileViTv3, the efficient model block EfficientFormer block, the dynamic convolution ODConv, and the proposed lightweight feature fusion network RepG-neck. The ablation experiment results are shown in Table 1. It can be seen that the improvement strategies of each module in this invention contribute to improving the detection performance of the model, and the overall performance indicators are significantly better than the baseline network.
[0079] The average accuracy curve is as follows Figure 10 As shown. By Figure 10 It can be concluded that the LYOLO-MTG proposed in this invention achieves better results than YOLOv5 and has better practicality in the field of multi-target garbage detection.
[0080] Table 1: Ablation Experiment Results
[0081]
[0082] To verify the superiority of this invention over other object detection algorithms, comparative experiments were added, studying the performance of the state-of-the-art single-stage object detection algorithms YOLOXs, YOLOv6s, and YOLOv7-tiny on the same multi-object garbage dataset. The comparison results are shown in Table 2. The proposed LYOLO-MTG algorithm achieved the highest mAP (95.4%), with the fewest parameters (only 3.4M), a computational cost of 14.8G, and a detection speed of 97 FPS. Compared to other advanced detection algorithms, it exhibits superior detection performance, achieving a trade-off between detection accuracy and speed. Furthermore, its model size is suitable for deployment on hardware modules, making it practically applicable.
[0083] Table 2: Comparison of Evaluation Indicators for Various Models
[0084]
[0085] To more intuitively demonstrate the detection advantages of the LYOLO-MTG algorithm proposed in this invention, three multi-target garbage images are used as examples to showcase the detection results of LYOLO-MTG and other advanced detection models. The detection results are as follows: Figure 11 As shown. The LYOLO-MTG proposed in this invention can effectively locate and distinguish various types of waste, greatly reducing the false detection rate and missed detection rate of complex waste targets. It has strong identification and anti-obstruction capabilities and is more applicable in actual detection environments.
[0086] This invention proposes an intelligent waste detection system based on the aforementioned multi-objective waste detection algorithm. The system's operation flow is as follows: Figure 12 As shown in the diagram. The entire detection process begins with selecting the model weights for garbage detection; the weight values can be FP32 or FP16. Next, the data type to be detected (image or video) is selected, and detection is performed. Finally, the model's detection results, such as the number of different types of garbage in the image and the time taken to detect the garbage image, are displayed in the results area and saved. This system is deployed on a PC and has been tested in real-world detection scenarios. Test results show that the system maintains a high accuracy rate for various types of garbage in real life.
[0087] The following is combined Figure 13 and Figure 14 Here is an application example:
[0088] like Figure 13 The image shown is a garbage image in a real scene obtained by the image acquisition module. (a) and (b) are actual digital images, which are used for subsequent garbage detection.
[0089] The test results in the actual testing scenario are shown below. Figure 14 Various types of trash in the image can be effectively located and detected.
Claims
1. A multi-target garbage detection method based on an improved YOLOv5 model, characterized in that, Comprising the following steps: a) acquiring multi-target garbage image data by a camera, and preprocessing the data set; b) constructing a multi-target garbage detection model based on an improved YOLOv5, the improvement method comprising: introducing a mixed network MobileViTv3 as a feature extraction network; using a dynamic convolution ODConv and an efficient model block EfficientFormerblock to optimize the feature extraction module MobileViT block, wherein the dynamic convolution ODConv replaces the convolution operation of the local representation module in the MobileViT block, and the efficient model block EfficientFormer block replaces the Linear Transformer of the global representation module in the MobileViT block; and using feature reuse technologies GhostModule and RepGhost Module to reconstruct the feature fusion network Neck, wherein the Ghost Module replaces the convolution operation of the path aggregation network in the Neck, and the RepGhost Module replaces the convolution operation in the Bottleneck to form a RepGhostC3 module to replace the C3 module in the original Neck; c) inputting the preprocessed multi-target garbage image data into the improved YOLOv5 model for training and verification, and testing using a test set, and evaluating the final performance of the model through model parameter quantity, calculation quantity, average precision and detection speed evaluation indexes; d) inputting the garbage image to be detected into the improved YOLOv5 model weight obtained by training, and outputting the detection result through calculation.
2. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, The preprocessing method in step a) comprises: setting the corresponding categories of the data set input into the network, and using the image labeling software LabelImg for labeling; dividing the data set into a training set and a test set according to a ratio of 7:3; using a Mosaic data enhancement algorithm to randomly flip and scale four garbage images input into the network each time, then splicing them into one picture in the order of top left, top right, bottom left and bottom right, and randomly cutting the spliced picture with a fixed size area to form a new picture; using an adaptive anchor box calculation method to recalculate the anchor box of the data set each time to match the anchor box value most suitable for the current data set; using an adaptive image scaling method to scale the original length and width of the image to h×640 resolution or 640×w resolution, wherein h and w are less than or equal to 640 pixels, in order to input the network with a unified size of 640×640, the length and width of the scaled picture are completed by adding gray and black edges.
3. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, The dynamic convolution ODConv dynamically generates attention weight values to adjust the convolution parameters according to different input features, specifically: For input feature X, it is firstly compressed into a 1 × 1 × C_in feature vector by global average pooling, and then mapped to a low-dimensional space with a dimension reduction ratio by using a fully connected layer; then, in a parallel manner, the aggregated feature vector is respectively convolved along the spatial dimension, input channel dimension, output channel dimension and kernel dimension of the convolution kernel W n to obtain feature tensors with sizes of k × k, C in × 1, C out × 1 and n × 1, respectively, and Sigmoid or Softmax function is used to generate attention weights α sn , α cn , α fn and α wn , respectively; finally, the generated attention weights are weighted and summed with the corresponding convolution kernel to obtain a new convolution, and ODConv is represented as: y = (a w1 ⊙ a f1 ⊙ a c1 ⊙ a s1 ⊙ W1+... + a wn ⊙ a fn ⊙ a cn ⊙ a sn ⊙ W n )* x wherein respectively represent the attention weights calculated from the spatial dimensions, input dimensions, output channel dimensions and kernel dimensions of the convolution kernel W n respectively represent the attention weights calculated from the spatial dimensions, input dimensions, output channel dimensions and kernel dimensions of the convolution kernel W respectively represent the attention weights calculated from the spatial dimensions, input dimensions, output channel dimensions and kernel dimensions of the convolution kernel W 4. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, The efficient model block EfficientFormer block replaces the original multi-head attention mechanism of the Transformer with a spatial pooling operator to extract global information in a smooth processing manner, and combines 1x1 convolution with batch normalization in the spatial MLP, replacing the original layer normalization combination with three-dimensional linear mapping, and fully utilizing the fusion mechanism advantages of convolution and batch normalization during model inference to improve inference speed, and the EfficientFormer block is represented as: Y = Pooling (X) + X, Z = Conv B (Conv B,G (Y))+Y, where X, Y are the input, output of Token Mixer block respectively, Z is the output of MLP block, and the size dimensions of X, Y, Z are consistent, Pooling means to take the pooling operation as Token Mixer, Conv B,G B, G respectively refer to whether there is BN and GeLU after the convolution operation.
5. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, The Ghost Module maintains the network capacity of the input by using a series of operations to reuse features, which divides the convolution into two parts, one part uses standard convolution to reduce dimensionality to generate a certain number of feature maps, and the other part completes the missing feature maps through linear operation, and the formula of the feature reuse technology of the Ghost Module is as follows: y = Cat([x, Φ1(x),..., Φ n-1 (x)]) where Cat is a concatenation operation, n is a proportional coefficient of control dimension, represents the output features after feature reuse, represents the input features to be processed and reused, represents the neural network layer, the DWConv layer, the generated feature tensor, and the total dimension size is ((n-1) / n)*C out .
6. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, The RepGhost Module realizes efficient reuse of features by using the reparameterization technique, and the RepGhost Module introduces the reparameterization technique in the depth separable convolution part to generate different feature mappings, which implicitly realizes feature reuse by fusing features from different layers during training, and enhances the interaction ability of the network context information, and the formula of the feature reuse technology of the RepGhost Module is as follows: y = Add([x, Φ1(x),..., Φ n-1 (x)]) = Φ * (x) where Add denotes an adder, denotes the feature tensor of the linear function generation in structure reparameterization, with total dimension size n*C out , Φ i will eventually be fused into 7. The multi-target garbage detection method based on the improved YOLOv5 model according to claim 1, characterized in that, In step c), the preprocessed multi-target garbage data set is input into the improved network for training for multiple iteration cycles, and the performance of the model generated after each iteration is verified with the test set, and the optimal model weight file is saved by comparison; The optimal model obtained by final training is tested using the test set, and the model performance is evaluated by model parameter quantity, calculation amount, average precision and detection speed evaluation index to determine whether the model can be effectively deployed in the multi-target garbage detection task.
8. A garbage detection system based on the multi-target garbage detection method based on the improved YOLOv5 model of claim 1, characterized in that, Static detection is performed on a single garbage image or multiple garbage images in a single folder; In real-time detection, the system calls the camera to realize visual monitoring of garbage detection in the garbage sorting environment; When using the system, the model weight of the garbage detection needs to be loaded; select the data type to be detected and perform detection; The results of model detection and recognition, the number of different types of garbage in the image, and the time of detecting garbage images, will be displayed to the result area and saved uniformly.
Citation Information
Patent Citations
Road vehicle detection system and method based on YOLOv4
CN114821492A
Garbage type detection and identification method and device based on deep learning
CN114863255A
Lightweight YOLOv5-based household garbage classification method and APP
CN115439684A