A method, device, electronic equipment and medium for real-time detection of domestic waste
By improving the YOLOv5s network model and introducing the attention mechanism and small target detection layer, various garbage identification problems have been solved, efficient and accurate garbage classification has been achieved, and real-time detection needs have been met.
Patent Information
- Application Number
- CN202210129621.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-11
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2042-02-11
AI Technical Summary
Existing technology cannot effectively and quickly identify and classify multiple categories of domestic waste, resulting in low efficiency and labor consumption, and cannot meet the needs of scientific, automated, and intelligent waste disposal.
Based on the improvement of the YOLOv5s network model, the lightweight feedforward convolutional attention module CBAM and the SE-Net channel attention module are introduced, combined with the small target detection layer, to form a multi-category real-time garbage detection method to improve detection accuracy and recall. rate and reduce the amount of calculation.
Achieved accurate identification of a variety of domestic waste, with a detection accuracy of 93.5%, a recall rate of 91.1%, a mAP@0.5 value of 96.4%, an inference speed of 13.1ms, and a calculation amount of 8.9GFLOPS. Compared with the original YOLOv5s model, the detection accuracy is increased by 4.6%. , the inference time is reduced by 7.4ms, meeting the needs of real-time detection of domestic waste.
Smart Images

Figure CN114492658B
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision technology, and specifically relates to a method, device, electronic device and medium for real-time detection of domestic waste based on an attention mechanism combination. Background Art
[0002] In recent years, with the rapid development of the global economy, the level of residents' consumption has increased significantly, the size of the urban population has continued to expand, and the amount of domestic waste has continued to increase gradually. As of 2020, the annual output of domestic waste in the world is close to 34 million tons, and China's annual output of domestic waste is close to 20 million tons, ranking first in the world. Therefore, the Ministry of Housing and Urban-Rural Development issued a notice on accelerating the classification of domestic waste in some key cities in 2017, clearly pointing out the acceleration of the classification of domestic waste. In 2019, the State Administration of Institutional Affairs issued a corresponding notice "Reference Standards for the Evaluation of Domestic Waste Classification Work in Public Institutions" and put forward requirements for further promoting related work.
[0003] Domestic waste pollution has become the main source of environmental pollution, seriously damaging the global ecological environment and affecting the normal life of residents. With the global goal of environmental protection and green development, and the promulgation of corresponding garbage classification policies, countries have begun to gradually implement them. As of 2020, about 11 countries in the world have participated in garbage classification. A total of 237 cities in China have implemented garbage classification policies, of which 30 cities have promulgated mandatory garbage classification regulations. Garbage classification is conducive to environmental protection and resource recycling, and is in line with the global theme of global environmental protection. Domestic waste is mostly mixed raw waste with high water content and a high proportion of organic waste. The traditional domestic waste treatment method cannot be effectively and quickly solved. The traditional domestic waste classification method has the characteristics of labor consumption, low efficiency, and poor work quality. Therefore, a scientific, automated, and intelligent application of garbage classification methods is needed. It forces the design of a more perfect detection and identification method that can simultaneously identify multiple categories of garbage. Summary of the invention
[0004] The technical problem to be solved by the present invention is to provide a method, device, electronic device and medium for real-time detection of domestic waste based on an attention mechanism combination in view of the deficiencies of the above-mentioned prior art. The method is based on an improved YOLOv5s network with an attention mechanism combination, and proposes a method for simultaneous detection and identification of multiple categories of waste, which can better solve the problem of waste detection and identification and has extremely wide application scenarios and market value.
[0005] In order to solve the above technical problems, the technical solution adopted by the present invention is: a real-time detection method for domestic waste based on attention mechanism combination, characterized in that the method comprises the following steps:
[0006] Get the junk image detection dataset;
[0007] The junk images in the junk image detection dataset are respectively input into the improved YOLOv5s network model and iteratively trained by GPU to obtain the optimal weight of the improved YOLOv5s network model; the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network;
[0008] The optimal weights are loaded into the improved YOLOv5s network model, the garbage image to be detected is input, and the detection result is output. The detection result includes the location of the target garbage on the image and the category to which it belongs.
[0009] In the present invention, the improved YOLOv5s network model introduces a lightweight feedforward convolutional attention module CBAM after the Focus module at the front end of the backbone network, and the Focus module performs operations such as slicing, connection and convolution on the input image and then outputs a feature map, which enters the channel attention module CAM, performs global maximum pooling and global average pooling operations on the input feature map, and then compresses the number of channels and expands it to the original feature dimension again to obtain two activated results, and finally sums the two activated results and outputs a feature map through a Sigmoid function, which is then multiplied with the original input feature map to complete the channel attention operation, and the result output by the channel attention module is input into the spatial attention module SAM, and the global maximum pooling and global average pooling operations are adopted to connect the two output feature maps together, and then the channel dimension is changed through a convolution operation, and the feature map is output through a Sigmoid function, which is then multiplied with the original input feature map to complete the spatial attention operation, and the processed feature map is sent to the next layer of convolution module;
[0010] A SE-Net channel attention module is placed at the end of the backbone network. The SPP module completes the spatial pyramid pooling operation and outputs three feature maps at the end of the backbone network. The two-dimensional features of each channel are compressed into a real number, and the number of channels remains unchanged to obtain the current feature map. Through the excitation operation, the feature map is converted into r of the original feature dimension through a fully connected layer. -1 The feature map is multiplied and activated by the ReLu function, and the fully connected layer generates the original feature dimension. The Sigmoid function is used to convert it into a standardized weight from 0 to 1, and finally the weighted feature map is input into the Neck network of YOLOv5s.
[0011] Optionally, in addition to introducing a lightweight feedforward convolutional attention module CBAM after the Focus module at the front end of the backbone network of the YOLOv5s network model and post-placing a SE-Net channel attention module at the end of the backbone network, the improved YOLOv5s network model also adds a small target detection layer at the prediction end of the YOLOv5s network model to improve the head network structure, so as to improve the detection of smaller target garbage by the improved YOLOv5s network model.
[0012] Optionally, the method for obtaining the junk image detection dataset is:
[0013] Collect garbage images containing a variety of daily life garbage, mark the garbage name, garbage category and garbage location in the garbage images, and then establish a garbage image detection data set; the garbage categories include four garbage classification categories: domestic garbage, recyclable garbage, hazardous garbage and other garbage;
[0014] And stored in the file type of xml format, the information annotation mainly includes: selecting the format of the garbage image data set to be annotated as VOC format, the name and type of garbage to be detected in the garbage image, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image;
[0015] The garbage labeled with the name of the item is then labeled according to the major categories to which it belongs, which are domestic garbage, recyclable garbage, hazardous waste and other garbage. Then, a garbage image detection dataset is established using the garbage images of the small categories of garbage and the large categories of garbage that have been labeled with domestic garbage.
[0016] Optionally, the specific process of establishing the junk image detection dataset is:
[0017] Step S1-1: Identify the type and size of garbage to be detected, and collect garbage images of corresponding names by video capture, camera shooting or online collection;
[0018] Step S1-2: Use the target detection and annotation software Labelimg to annotate the garbage image obtained in S1-1 and store it in a file type in xml format. The information annotation mainly includes: selecting the format of the garbage image data set to be annotated as VOC format, the garbage name and garbage category of the garbage to be detected, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image;
[0019] Step S1-3: After completing the information labeling, the number of images in the junk image data set is counted, all the xml format file types that have completed the information labeling are converted into txt file types, and the coordinate values of the junk are normalized to obtain the junk image detection data set.
[0020] Optionally, the anchor box values of the improved YOLOv5s network model are set to [5, 6, 8, 14, 15, 11], [10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326], and the improved YOLOv5s network model is trained on the set anchor box values to compare the output prediction box with the real box, calculate the difference between the two, reversely update and iterate, and adaptively adjust the network model parameters.
[0021] Optionally, the junk images of the junk image detection dataset are respectively input into the improved YOLOv5s network model and trained for 1000 iterations using the GPU, the image size is set to 640×640, the batch size for each model iteration training is set to 16, the initial learning rate is set to 0.01, and the iterative training is performed using the GPU in the created virtual environment.
[0022] Optionally, the detection result includes the name, category, prediction box size, confidence value and location information of the detected garbage on the image, so as to realize simultaneous identification of multiple types of domestic garbage and achieve the purpose of real-time detection of domestic garbage.
[0023] In order to solve the above problems, the present invention also provides a real-time detection device for domestic waste, which comprises:
[0024] Preprocessing module, used to obtain garbage image detection dataset;
[0025] A training module is used to input the junk images in the junk image detection data set into the improved YOLOv5s network model respectively and perform iterative training through a GPU to obtain the optimal weight of the improved YOLOv5s network model through training; the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network;
[0026] The garbage detection module is used to load the optimal weights into the improved YOLOv5s network model, input the garbage image to be detected, output the detection result, and obtain the location and category of the target garbage on the image.
[0027] In order to solve the above problem, the present invention further provides an electronic device, wherein the electronic device comprises:
[0028] at least one processor; and,
[0029] a memory communicatively connected to the at least one processor; wherein,
[0030] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned method for real-time detection of domestic waste based on a combination of attention mechanisms.
[0031] In order to solve the above problems, the present invention also provides a computer-readable storage medium storing computer instructions, which are operated to execute the above-mentioned method for real-time detection of domestic waste based on attention mechanism combination.
[0032] Compared with the prior art, the present invention has the following advantages:
[0033] 1. The present invention improves the YOLOv5s network model on the basis of the YOLOv5s network model. A lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network of the YOLOv5s network model. By adding an attention mechanism combination to the YOLOv5s network model, the detection accuracy, recall rate and mAP value of the model can be improved, while reducing the reasoning time and calculation amount. A small target detection layer is added at the prediction end to improve the head network structure for detecting garbage objects with smaller targets, including capsules, button batteries, etc., which can provide the accuracy of this small target garbage. While meeting the faster detection speed, the present invention also has excellent performance in detection accuracy, can meet the requirements of real-time detection of domestic garbage, and to a certain extent reduces the calculation amount of the network model, improves the reasoning speed and detection accuracy, provides an efficient detection method for garbage classification, reduces the consumption of labor costs, and accelerates the development of intelligent garbage classification.
[0034] 2. The present invention can detect and identify a variety of common types of garbage in life. The accuracy of domestic garbage detection reaches 93.5%, the recall rate reaches 91.1%, the mAP@0.5 value reaches 96.4%, the inference speed reaches 13.1ms, and the model calculation amount reaches 8.9GFLOPS. Compared with the original YOLOv5s model, the calculation amount is reduced by 45.3%, the detection accuracy is improved by 4.6%, and the inference time is reduced by 7.4ms. It can realize the simultaneous identification of multiple types of garbage, providing a technical solution for the intelligent treatment of garbage and achieving the purpose of real-time detection of domestic garbage.
[0035] 3. The domestic waste detection method, device, electronic device and computer-readable storage medium described in the present invention solve the problem of waste detection and real-time identification.
[0036] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 It is a flowchart of the specific implementation process of the present invention;
[0038] Figure 2 A comparison chart of the model training effects of the present invention on four pre-training models;
[0039] Figure 3 It is a schematic diagram of the improved YOLOv5s network model in which the attention mechanism combination is introduced into the YOLOv5s network model in Comparative Example 2;
[0040] Figure 4 The training effect diagram of the improved YOLOv5s network model in which the attention mechanism combination is introduced into the YOLOv5s network model in comparative example 2;
[0041] Figure 5 The schematic diagram of the improved YOLOv5s network model in Comparative Example 3 is a diagram in which a small target detection layer is added to the YOLOv5s network model;
[0042] Figure 6 This is a training effect diagram of the improved YOLOv5s network model in comparative example 3, in which a small target detection layer is added to the YOLOv5s network model;
[0043] Figure 7 This is a schematic diagram of the improved YOLOv5s network model of Example 1 of the present invention;
[0044] Figure 8 This is a comparison diagram of the training effects of the improved YOLOv5s network model of the embodiment of the present invention and the original YOLOv5s network model of Comparative Example 1;
[0045] Fig. 9 This is a diagram of the garbage detection effect based on the improved YOLOv5s network model of the present invention. DETAILED DESCRIPTION
[0046] Example 1
[0047] like Figure 1 As shown, the present embodiment proposes a method for real-time detection of domestic waste based on a combination of attention mechanisms, comprising the following steps:
[0048] S1: Obtain a junk image detection dataset, and divide the junk image detection dataset into a training set, a validation set, and a test set;
[0049] In this embodiment, garbage image detection data sets are obtained by collecting garbage images online, capturing domestic garbage in videos, and photographing them. All domestic garbage in the images are labeled according to their names. A total of 13 types of garbage are obtained, and the 13 types are divided into four categories, namely: domestic garbage, recyclable garbage, hazardous garbage, and other garbage. A garbage detection data set containing multiple categories is established, and the data set is divided into a training set, a validation set, and a test set. The specific steps are as follows:
[0050] Step S1-1: Identify the types and sizes of garbage to be detected, capture garbage in real life scenes in videos and take photos with cameras, and use Python programming language to write crawler scripts for online collection to collect garbage images of corresponding names;
[0051] Step S1-2: Use the target detection and annotation software Labelimg to annotate the collected image data set and store it in the file type of xml format. A total of 13 types of garbage are obtained, namely: apple core, cylindrical battery, button battery, book, capsule, pencil, toothbrush, old pants, mobile phone, remote control, old shirt, vegetable leaves, watermelon rind. The information annotation mainly includes: selecting the format of the annotation data set as VOC format, the name and category of the garbage to be detected, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image;
[0052] Step S1-3: After the information annotation is completed, the size of the statistical data set is calculated, and a total of 7671 valid samples are obtained. A script is written in Python programming language, all the files with completed information annotation are converted into txt file type and the coordinate values are normalized to obtain a garbage image detection data set, and the garbage image detection data set is divided into a training set, a validation set and a test set according to a sample quantity ratio of 7:1:2, wherein domestic garbage includes apple cores, toothbrushes, vegetable leaves, and watermelon peels, totaling 2204 samples; recyclable garbage includes books, old pants, and old tops, totaling 2179 samples; hazardous garbage includes cylindrical batteries, button batteries, pencils, and mobile phones, totaling 1805 samples; other garbage includes capsules and remote controls, totaling 1483 samples.
[0053] S2. Input the garbage images in the training set and the validation set into the improved YOLOv5s network model and perform iterative training on the GPU to obtain the optimal weight. Specifically, the data set in the training set is iteratively trained for 1000 times, the image size is set to 640×640, the batch size is set to 16 for each model iteration training, the initial learning rate is set to 0.01, and the iterative training is performed on the GPU in the created virtual environment.
[0054] like Figure 7As shown, the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolution attention module CBAM is introduced after the backbone network front-end Focus module of the YOLOv5s network model, and the Focus module performs slicing, connection, convolution and other operations on the input image and then outputs a feature map, which enters the channel attention module, performs maximum pooling and average pooling operations on the input feature map, and then compresses the number of channels and expands to the original feature dimension again to obtain two activated results, and finally adds the two activated results and connects a sigmoid function to output the feature map, which is then multiplied with the original input feature map to complete the channel attention operation, and the result output by the channel attention module is input into the spatial attention module, and the maximum pooling and average pooling are adopted to stack the two output feature maps together, and then the channel dimension is changed by the convolution operation, and the feature map is output through a sigmoid function, which is then multiplied with the original input feature map to complete the spatial attention operation, and the processed feature map is sent to the next layer of convolution module;
[0055] The SE-Net channel attention module is placed at the end of the backbone network. The SPP module completes the spatial pyramid pooling operation and outputs three feature maps at the end of the backbone network. The two-dimensional features of each channel are compressed into a real number, and the number of channels remains unchanged to obtain the current feature map. Through the excitation operation, the feature map is converted into multiples of the original feature dimension through a fully connected layer and activated by the ReLu function. The fully connected layer generates the original feature dimension back and converts it into a standardized weight from 0 to 1 using the s-type function. Finally, the weighted feature map is input into the Neck network.
[0056] And a small target detection layer is added to the prediction end of the YOLOv5s network model to improve the head network structure. This is to solve the problem of high error rate in detecting small target garbage. For example, among the 13 types of garbage, there are small-sized target garbage such as cylindrical batteries, button batteries, capsules, etc., thereby improving the detection accuracy and finally obtaining the improved YOLOv5s network model.
[0057] The anchor box values of the improved YOLOv5s network model are set to [5, 6, 8, 14, 15, 11], [10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], and [116, 90, 156, 198, 373, 326]. The improved YOLOv5s network model is trained on the set anchor box values to compare the output prediction box with the real box, calculates the difference between the two, and reversely updates and iterates to adaptively adjust the network model parameters.
[0058] S3. Use the optimal weights to input the garbage image to be detected into the trained improved YOLOv5s network model to obtain the real-time garbage detection results, such as Fig. 9 As shown in the figure, the detection results mainly include the detected garbage category and name, prediction box size, confidence value and target location information.
[0059] In this embodiment, the training set and validation set in step S1 are input into the four pre-training models of YOLOv5s, YOLOv5m, YOLOv5l and YOLOv5x provided by the official for 100 iterations of training respectively. After the iterative training is completed, the corresponding optimal weights are obtained. Then, the trained YOLOv5s, YOLOv5m, YOLOv5l and YOLOv5x pre-training models are tested using the data set in the test set. The training effect comparison chart is shown in FIG. Figure 2 The test results are shown in Table 1.
[0060] Table 1 Test results of four pre-trained models
[0061]
[0062] It can be seen from the above table that the mAP value of YOLOv5s is 91.8%, the inference time is 19.8ms, the mAP value of YOLOv5m is 96%, the inference time is 70.1ms, the mAP value of YOLOv5l is 92.9%, the inference time is 122.9ms, and the mAP value of YOLOv5x is 91.9%, and the inference time is 306.1ms.
[0063] Through the performance index analysis of the above four pre-training models, for the data set used in the present invention, the YOLOv5m model has the highest accuracy, but the inference time is long and cannot meet the real-time requirements. Although the accuracy of the YOLOv5s model is lower than that of the other three models, the inference time is the shortest and can meet the real-time requirements. Therefore, according to actual needs, the present invention selects the YOLOv5s network model as the pre-training model, and then improves the accuracy and recall rate by improving the YOLOv5s network model.
[0064] Comparative Example 1
[0065] The method of this comparative example is the same as the method of Example 1, except that the network model trained in this comparative example is YOLOv5s.
[0066] Comparative Example 2
[0067] The method of this comparative example is the same as that of Example 1, except that the improved YOLOv5s trained in this comparative example is improved on the YOLOv5s network model. Specifically, a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network. The schematic diagram of the improved YOLOv5s is shown in FIG. Figure 3 shown.
[0068] Comparative Example 3
[0069] The method of this comparative example is the same as that of Example 1, except that the improved YOLOv5s trained in this comparative example is improved on the YOLOv5s network model. Specifically, a small target detection layer is added to the prediction end of the YOLOv5s network model to improve the head network structure. Figure 4 shown.
[0070] Then, the training effects and test results of the four network models in Example 1 and Comparative Examples 1-3 are combined with Figure 4 , Figure 6 , Figure 8 , Table 2 shows the test results as follows:
[0071] Table 2 Test results of the detection methods in Example 1 and Comparative Examples 1-3
[0072]
[0073]
[0074] It can be seen from the above table that the mAP value of YOLOv5s is 91.8%, the reasoning time is 19.8ms, and the calculation amount is 16.5GFLOPS. The mAP value of the improved YOLOv5s network model is 96.4%, the reasoning time is 13.1ms, and the calculation amount is 8.9GFLOPS. The mAP value of the YOLOv5s network model with an increased attention mechanism combination used in Example 2 is 94.5%, the reasoning time is 8.5ms, and the calculation amount is 6.0GFLOPS; the mAP value of the YOLOv5s network model with an increased small target detection layer in Example 3 is 93.6%, the reasoning time is 32.2ms, and the calculation amount is 27.7GFLOPS. Through the analysis of the performance indicators of the above four network models, for the data set used in the present invention, although the thrust time of adding a small target detection layer is longer than the reasoning time of the network model with an increased attention mechanism combination, it can improve the recall rate, which is more critical for garbage classification. Compared with the original YOLOv5s network model, the accuracy of the improved YOLOv5s network model in the detection method of the present invention is improved by 4.6%, the precision is improved by 2.5%, the recall rate is improved by 3%, the inference time is reduced by 6.7ms, and the calculation amount is reduced by 7.6GFLOPS.
[0075] Example 2
[0076] The present invention also provides a real-time detection device for domestic waste, the device comprising:
[0077] A preprocessing module, used to obtain a junk image detection dataset and divide the junk image detection dataset into a training set, a validation set and a test set;
[0078] A training module is used to input the garbage images in the training set and the validation set into the improved YOLOv5s network model respectively and perform iterative training through a GPU to obtain the optimal weight of the improved YOLOv5s network model through training; the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network;
[0079] The garbage detection module is used to load the optimal weights into the improved YOLOv5s network model, input the garbage image to be detected, output the detection result, and obtain the location and category of the target garbage on the image.
[0080] In this embodiment, garbage image detection data sets are obtained by collecting garbage images online, capturing domestic garbage in videos, and photographing them. All domestic garbage in the images are labeled according to their names. A total of 13 types of garbage are obtained, and the 13 types are divided into four categories, namely: domestic garbage, recyclable garbage, hazardous garbage, and other garbage. A garbage detection data set containing multiple categories is established, and the data set is divided into a training set, a validation set, and a test set. The specific steps are as follows:
[0081] Step S1-1: Identify the types and sizes of garbage to be detected, capture garbage in real life scenes in videos and take photos with cameras, and use Python programming language to write crawler scripts for online collection to collect garbage images of corresponding names;
[0082] Step S1-2: Use the target detection and annotation software Labelimg to annotate the collected image data set and store it in the file type of xml format. A total of 13 types of garbage are obtained, namely: apple core, cylindrical battery, button battery, book, capsule, pencil, toothbrush, old pants, mobile phone, remote control, old shirt, vegetable leaves, watermelon rind. The information annotation mainly includes: selecting the format of the annotation data set as VOC format, the name and category of the garbage to be detected, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image;
[0083] Step S1-3: After the information annotation is completed, the size of the statistical data set is calculated, and a total of 7671 valid samples are obtained. A script is written in Python programming language, all the files with completed information annotation are converted into txt file type and the coordinate values are normalized to obtain a garbage image detection data set, and the garbage image detection data set is divided into a training set, a validation set and a test set according to a sample quantity ratio of 7:1:2, wherein domestic garbage includes apple cores, toothbrushes, vegetable leaves, and watermelon peels, totaling 2204 samples; recyclable garbage includes books, old pants, and old tops, totaling 2179 samples; hazardous garbage includes cylindrical batteries, button batteries, pencils, and mobile phones, totaling 1805 samples; other garbage includes capsules and remote controls, totaling 1483 samples.
[0084] In this embodiment, the junk images in the training set and the validation set are respectively input into the following Fig. 9 The improved YOLOv5s network model shown in the figure is iteratively trained on the GPU to obtain the optimal weights. Specifically, the data set in the training set is iteratively trained for 1000 times, the image size is set to 640×640, the batch size is set to 16 for each model iteration training, the initial learning rate is set to 0.01, and the iterative training is performed on the GPU in the created virtual environment.
[0085] like Figure 7 As shown, the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolution attention module CBAM is introduced after the backbone network front-end Focus module of the YOLOv5s network model, and the Focus module performs slicing, connection, convolution and other operations on the input image and then outputs a feature map, which enters the channel attention module, performs maximum pooling and average pooling operations on the input feature map, and then compresses the number of channels and expands to the original feature dimension again to obtain two activated results, and finally adds the two activated results and connects a sigmoid function to output the feature map, which is then multiplied with the original input feature map to complete the channel attention operation, and the result output by the channel attention module is input into the spatial attention module, and the maximum pooling and average pooling are adopted to stack the two output feature maps together, and then the channel dimension is changed by the convolution operation, and the feature map is output through a sigmoid function, which is then multiplied with the original input feature map to complete the spatial attention operation, and the processed feature map is sent to the next layer of convolution module;
[0086] The SE-Net channel attention module is placed at the end of the backbone network. The SPP module completes the spatial pyramid pooling operation and outputs three feature maps at the end of the backbone network. The two-dimensional features of each channel are compressed into a real number, and the number of channels remains unchanged to obtain the current feature map. Through the excitation operation, the feature map is converted into multiples of the original feature dimension through a fully connected layer and activated by the ReLu function. The fully connected layer generates the original feature dimension back and converts it into a standardized weight from 0 to 1 using the s-type function. Finally, the weighted feature map is input into the Neck network.
[0087] And a small target detection layer is added to the prediction end of the YOLOv5s network model to improve the head network structure. This is to solve the problem of high error rate in detecting small target garbage. For example, among the 13 types of garbage, there are small-sized target garbage such as cylindrical batteries, button batteries, capsules, etc., thereby improving the detection accuracy and finally obtaining the improved YOLOv5s network model.
[0088] The anchor box values of the improved YOLOv5s network model are set to [5, 6, 8, 14, 15, 11], [10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], and [116, 90, 156, 198, 373, 326]. The improved YOLOv5s network model is trained on the set anchor box values to compare the output prediction box with the real box, calculates the difference between the two, and reversely updates and iterates to adaptively adjust the network model parameters.
[0089] Use the optimal weights to input the garbage image to be detected into the trained improved YOLOv5s network model to obtain the real-time garbage detection results, as shown in the attached figure. Fig. 9 As shown in the figure, the detection results mainly include the detected garbage category and name, prediction box size, confidence value and target location information.
[0090] Example 3
[0091] The present invention also provides an electronic device, an electronic device, characterized in that the electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for real-time detection of domestic waste based on the attention mechanism combination of Example 1.
[0092] Example 4
[0093] This embodiment also provides a computer-readable storage medium storing computer instructions, which are operated to execute the method for real-time detection of domestic waste based on the combination of attention mechanisms described in Example 1.
[0094] The above is only a preferred embodiment of the present invention and does not limit the present invention in any way. Any simple modification, change and equivalent change made to the above embodiment according to the technical essence of the invention still falls within the protection scope of the technical solution of the present invention.
Claims
1. A real-time detection method for domestic waste based on a combination of attention mechanisms, characterized in that: The method comprises the following steps: Get the junk image detection dataset; The junk images in the junk image detection dataset are respectively input into the improved YOLOv5s network model and iteratively trained by GPU to obtain the optimal weight of the improved YOLOv5s network model; the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network; The optimal weights are loaded into the improved YOLOv5s network model, the garbage image to be detected is input, and the detection result is output. The detection result includes the location of the target garbage on the image and the category to which it belongs.
2. According to claim 1, a real-time detection method for domestic waste based on attention mechanism combination is characterized in that: In addition to introducing a lightweight feedforward convolutional attention module CBAM after the Focus module at the front end of the backbone network of the YOLOv5s network model and placing a SE-Net channel attention module at the end of the backbone network, the improved YOLOv5s network model also adds a small target detection layer at the prediction end of the YOLOv5s network model to improve the head network structure, so as to improve the detection of smaller target garbage by the improved YOLOv5s network model.
3. According to claim 1, a real-time detection method for domestic waste based on attention mechanism combination is characterized in that: The method for obtaining the garbage image detection dataset is: Collect garbage images containing a variety of daily life garbage, mark the garbage name, garbage category and garbage location in the garbage images, and then establish a garbage image detection data set; the garbage categories include four garbage classification categories: domestic garbage, recyclable garbage, hazardous garbage and other garbage; And stored in the file type of xml format, the information annotation mainly includes: selecting the format of the garbage image data set to be annotated as VOC format, the name and type of garbage to be detected in the garbage image, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image; The garbage labeled with the name of the item is then labeled according to the major categories to which it belongs, which are domestic garbage, recyclable garbage, hazardous waste and other garbage. Then, a garbage image detection dataset is established using the garbage images of the small categories of garbage and the large categories of garbage that have been labeled with domestic garbage.
4. According to claim 3, a real-time detection method for domestic waste based on attention mechanism combination is characterized in that: The specific process of establishing the garbage image detection data set is as follows: Step S1-1: Identify the type and size of garbage to be detected, and collect garbage images of corresponding names through video capture, camera shooting or online collection; Step S1-2: Use the target detection and annotation software Labelimg to annotate the garbage image obtained in S1-1 and store it in an XML file type. The information annotation mainly includes: selecting the VOC format of the annotation data set, the garbage name and garbage category of the garbage to be detected, the name and storage path of the file generated by the annotated image, and the coordinate value and length and width of the target garbage in the image; Step S1-3: After completing the information labeling, the number of images in the junk image data set is counted, all the xml format file types that have completed the information labeling are converted into txt file types, and the coordinate values of the junk are normalized to obtain the junk image detection data set.
5. A method for real-time detection of domestic waste based on a combination of attention mechanisms according to claim 1 or 2, characterized in that: The anchor box values of the improved YOLOv5s network model are set to [5, 6, 8, 14, 15, 11], [10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], and [116, 90, 156, 198, 373, 326]. The improved YOLOv5s network model is trained on the set anchor box values to compare the output prediction box with the real box, calculates the difference between the two, and reversely updates and iterates to adaptively adjust the network model parameters.
6. According to claim 1, a real-time detection method for domestic waste based on attention mechanism combination is characterized in that: The garbage images of the garbage image detection dataset are respectively input into the improved YOLOv5s network model and trained by GPU for 1000 iterations. The image size is set to 640×640, the batch size is set to 16 for each model iteration training, the initial learning rate is set to 0.01, and the iterative training is performed by GPU in the created virtual environment.
7. According to claim 1, a real-time detection method for domestic waste based on attention mechanism combination is characterized in that: The detection result includes the name, category, prediction box size, confidence value of the detected garbage and the location information of the target garbage on the image.
8. A real-time detection device for domestic waste based on an attention mechanism combination, characterized in that: The device includes: Preprocessing module, used to obtain garbage image detection dataset; A training module is used to input the junk images in the junk image detection data set into the improved YOLOv5s network model respectively and perform iterative training through a GPU to obtain the optimal weight of the improved YOLOv5s network model through training; the improved YOLOv5s network model is improved on the YOLOv5s network model, specifically: a lightweight feedforward convolutional attention module CBAM is introduced after the Focus module at the front end of the backbone network of the YOLOv5s network model, and a SE-Net channel attention module is placed at the end of the backbone network; The garbage detection module is used to load the optimal weights into the improved YOLOv5s network model, input the garbage image to be detected, output the detection result, and obtain the location and category of the target garbage on the image.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for real-time detection of domestic waste based on a combination of attention mechanisms as described in any one of claims 1-7.
10. A computer-readable storage medium storing computer instructions, wherein the computer instructions are operated to execute the method for real-time detection of domestic waste based on a combination of attention mechanisms as described in any one of claims 1-7.
