A Deep Learning-Based Method and System for Waste Classification and Identification
By constructing a garbage classification model using the ResNet-50 network structure and CBAM attention mechanism, this method solves the problem of traditional methods requiring a large amount of manpower, material resources, and feature engineering, and achieves efficient and accurate garbage classification, applicable to fields such as image recognition and medical image analysis.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2026-04-03
AI Technical Summary
Existing waste classification and identification methods require a lot of manpower and resources to design image parameters. Traditional machine learning algorithms perform poorly in high-dimensional data processing and are difficult to handle large-scale image classification tasks. Furthermore, traditional methods require manual feature engineering design, which is difficult to adapt to the feature representation of different types of waste.
A garbage classification model is constructed by using the ResNet-50 network structure for transfer learning, combined with the CBAM attention mechanism and data augmentation technology. Overfitting is reduced through transfer learning, and the model is fine-tuned to adapt to the garbage image dataset by utilizing the features of the pre-trained model. The CBAM attention mechanism is introduced to improve feature extraction capability, and cross-entropy loss and optimization function are used to optimize model performance.
A high-performance, highly generalizable waste sorting model has been developed, which improves the accuracy of waste sorting, shortens the training time, and can automatically process image data. It is applicable to fields such as image recognition, facial recognition, and medical image analysis.
Smart Images

Figure CN116416476B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to image classification and recognition, and in particular to a method and system for garbage classification and recognition based on deep learning. Background Technology
[0002] With the continuous increase in the amount of household waste, waste management has become increasingly important and challenging. To avoid improper waste disposal and address the pollution and soil degradation caused by traditional waste incineration and landfill, we need to better manage waste through sorting and recycling. Proper waste sorting and recycling can effectively conserve resources and enable resource reuse, while also significantly improving waste management efficiency, reducing environmental pollution, and improving the ecological environment. Therefore, waste sorting and recycling is a future development trend.
[0003] In existing technologies, common methods for garbage classification and identification include image classification algorithms and machine learning methods. Image classification algorithms generally involve extracting low-level features from an image, encoding the extracted image features, and designing a classifier to classify the image into categories. This algorithm is based on the features of the image itself, and after feature extraction, it performs feature processing such as dimensionality reduction, and then uses a corresponding classifier to distinguish and judge the categories. This method requires a lot of human and material resources to design and adjust image parameters.
[0004] Using traditional machine learning algorithms, such as support vector machines and random forests, to extract features from data and train classifiers for garbage classification requires manual feature engineering. Different feature representation methods are needed for different types of garbage. At the same time, traditional machine learning algorithms perform poorly when processing high-dimensional data and are not up to the task of large-scale image classification. Summary of the Invention
[0005] Purpose of the invention: The purpose of this invention is to provide a high-performance, highly generalizable, and highly accurate method and system for garbage classification and identification based on deep learning.
[0006] Technical Solution: To achieve the above objectives, the present invention provides a method for waste classification and identification based on deep learning, comprising the following steps:
[0007] Step S1: Obtain a dataset containing various types of garbage images;
[0008] Step S2: Preprocess the images in the dataset and divide the preprocessed dataset into training and testing sets;
[0009] Step S3: Select the ResNet-50 network structure as the pre-trained model, and use transfer learning to train and fine-tune the pre-trained model;
[0010] Step S4: Introduce the CBAM attention mechanism module into the fine-tuned pre-trained model to construct a garbage classification model;
[0011] Step S5: Perform performance analysis on the waste sorting model.
[0012] The preprocessing of images in the dataset described in step S2 includes data annotation, data analysis, image scaling and cropping, image data standardization, and data augmentation.
[0013] Data annotation refers to classifying and numbering each image in the dataset;
[0014] Data analysis refers to removing junk data, specifically images that are of uneven quality due to differences in image type, aspect ratio, and shooting environment.
[0015] Image data standardization refers to the normalization operation performed on an image, adjusting the feature values of different dimensions to a similar range;
[0016] Data augmentation refers to expanding a dataset to increase the number of images within it.
[0017] The normalization operation mentioned above is:
[0018]
[0019] In the formula, output is the image pixel value output, input is the image pixel value input, max and min are the maximum and minimum pixel values, and after normalization, the pixel values of the image are adjusted to the (0,1) range.
[0020] The data augmentation includes performing transformation operations on images within the garbage dataset using color enhancement, horizontal flipping, vertical flipping, image sharpening, Gaussian noise, and Gaussian blur.
[0021] Specifically, step S3 involves training and fine-tuning the pre-trained model using transfer learning: freezing the convolutional blocks near the input in the pre-trained model, keeping the initial layer weights unchanged, training the remaining convolutional blocks near the output and the fully connected classifier using the training set to obtain new weights. The new weights are obtained by subtracting the backpropagation error from the initial weights. When the backpropagation error is positive, the weight values are decreased; when the backpropagation error is negative, the weight values are increased.
[0022] The fine-tuned model is tested using the training and test sets to evaluate its accuracy (Train_Accuracy) and loss (Train_Loss) on the training set, and its accuracy (Val_Accuracy) and loss (Val_Loss) on the test set.
[0023] The accuracy rate mentioned therein is
[0024]
[0025] In the above formula (2), TP represents the number of instances that are correctly classified as positive, that is, the number of instances that are actually positive and classified as positive by the classifier; TN represents the number of instances that are correctly classified as negative, that is, the number of instances that are actually negative and classified as negative by the classifier; FP represents the number of instances that are incorrectly classified as positive, that is, the number of instances that are actually negative but classified as positive by the classifier; FN represents the number of instances that are incorrectly classified as negative, that is, the number of instances that are actually positive but classified as negative by the classifier.
[0026] The loss value mentioned above is
[0027]
[0028] In the above formula (3), N is the total number of samples, i represents one of the output samples, y is the actual value, and x is the predicted value.
[0029] Specifically, step S4 involves introducing the CBAM attention mechanism module into the fine-tuned pre-trained model to construct a garbage classification model. This includes: adding the CBAM attention mechanism module to the first-level convolutional layer of the ResNet-50 network structure to improve the representation ability of image features; fixing the weights of all layers except the fully connected layers; adding the CBAM module before the last layer to increase attention to important image information during feature extraction; replacing the ordinary pooling layer with an AP module composed of two adaptive average pooling layers to enhance the selection of image feature information; modifying the fully connected layer, then activating it with Softmax to output the classification result, and using Dropout to reduce overfitting and improve the generalization ability of the garbage classification model.
[0030] The CBAM attention mechanism module includes a channel attention mechanism and a spatial attention mechanism. The channel attention mechanism can weight different channels and retain the channel feature information that is most important for image classification and recognition. The spatial attention mechanism focuses on the feature information of different regions in the image and obtains the spatial importance of each position by calculating the feature map channel by channel. By introducing the CBAM attention mechanism module into the fine-tuned pre-trained model, the model can better capture the key information in the image.
[0031] Specifically, step S5 involves performing performance analysis on the garbage classification model as follows: Based on the garbage classification model, cross-entropy loss is selected as the loss function, and two optimization functions, SGD and Adam, are selected for comparison while keeping other parameters unchanged; different optimization functions are trained using a test set, and the loss rate after each iteration is recorded. The performance differences of the two optimization functions on the test set are compared, the changes in the loss rate curve are analyzed, and a suitable optimization function is selected to improve the performance and recognition efficiency of the deep garbage classification model.
[0032] This invention also provides a system for garbage classification and identification based on deep learning, including an image preprocessing module, a model training module, and a model analysis module;
[0033] The image preprocessing module is used to preprocess image sample data of various types of garbage;
[0034] The model training module includes training and fine-tuning the ResNet-50 network structure, and building a garbage classification model based on the ResNet-50 network structure.
[0035] The model analysis module is used to perform performance analysis on the waste sorting model.
[0036] Beneficial effects: The present invention has the following advantages: 1. The present method adopts transfer learning when constructing the garbage classification model, and uses the features learned by the pre-trained model to reduce the overfitting problem that may occur when training on small datasets and shorten the training time of the pre-trained model; then fine-tuning the pre-trained model to adapt to the garbage image dataset, it can quickly construct a high-performance garbage classification model with strong generalization ability and improve the accuracy of garbage classification.
[0037] 2. The method of this invention is based on deep learning and uses the backpropagation algorithm to train the network. By constructing a multi-layered neural network, it learns and extracts high-level feature representations, thereby realizing automated data classification, recognition, clustering and other tasks. It can be widely used in the fields of image recognition, facial recognition, image processing, medical image analysis and other technical fields. Attached Figure Description
[0038] Figure 1 This is a schematic diagram of the method flow of the present invention;
[0039] Figure 2 The flowchart below shows the process of using transfer learning to train a pre-trained model in the method of this invention. Detailed Implementation
[0040] The technical solution of the present invention will be described in detail below with reference to the embodiments and accompanying drawings.
[0041] like Figure 1As shown, a deep learning-based method for garbage classification and identification includes the following steps:
[0042] Step S1: Obtain a dataset containing various types of garbage images;
[0043] Step S2: Preprocess the images in the dataset, and divide the preprocessed dataset into training and test sets in an 8:2 ratio;
[0044] Preprocessing includes data annotation, data analysis, image scaling and cropping, image data standardization, and data augmentation. Data annotation refers to classifying and numbering each image in the dataset. Data analysis involves removing low-quality images from the dataset that are uneven in overall data quality due to differences in image type, aspect ratio, and shooting environment. Image data standardization involves normalizing the images to adjust the feature values of different dimensions to a similar range. Data augmentation involves expanding the dataset to increase the number of images within it.
[0045] The normalization operation mentioned above is:
[0046]
[0047] In the formula, output is the image pixel value output, input is the image pixel value input, max and min are the maximum and minimum pixel values, and after normalization, the pixel values of the image are adjusted to the (0,1) range.
[0048] The data augmentation includes performing transformation operations on images within the garbage dataset using color enhancement, horizontal flipping, vertical flipping, image sharpening, Gaussian noise, and Gaussian blur.
[0049] Step S3: Select the ResNet-50 network structure as the pre-trained model, and use transfer learning to train and fine-tune the pre-trained model; specifically: as follows... Figure 2 As shown, the convolutional blocks near the input end in the pre-trained model are frozen, the weights of the initial layer remain unchanged, and the remaining convolutional blocks near the output end and the fully connected classifier are trained with the training set to obtain new weights. The new weights are obtained by subtracting the backpropagation error from the initial weights. When the backpropagation error is positive, the weight value is decreased, and when the backpropagation error is negative, the weight value is increased.
[0050] The fine-tuned model is tested using the training and test sets to evaluate its accuracy (Train_Accuracy) and loss (Train_Loss) on the training set, and its accuracy (Val_Accuracy) and loss (Val_Loss) on the test set.
[0051] The accuracy rate mentioned therein is
[0052]
[0053] In the above formula (2), TP represents the number of instances that are correctly classified as positive, that is, the number of instances that are actually positive and classified as positive by the classifier; TN represents the number of instances that are correctly classified as negative, that is, the number of instances that are actually negative and classified as negative by the classifier; FP represents the number of instances that are incorrectly classified as positive, that is, the number of instances that are actually negative but classified as positive by the classifier; FN represents the number of instances that are incorrectly classified as negative, that is, the number of instances that are actually positive but classified as negative by the classifier.
[0054] The loss value mentioned above is
[0055]
[0056] In the above formula (3), N is the total number of samples, i represents one of the output samples, y is the actual value, and x is the predicted value.
[0057] Step S4: Introduce the CBAM attention mechanism module into the fine-tuned pre-trained model to construct a garbage classification model. Specifically, add the CBAM attention mechanism module to the first-level convolutional layer in the ResNet-50 network structure to improve the representation ability of image features, fix the weights of other layers except the fully connected layers, and add the CBAM module before the last layer to increase the attention to important image information during feature extraction. Replace the ordinary pooling layer with the AP module (Adaptive Pooling model) composed of two layers of adaptive average pooling to increase the selection of image feature information. Modify the fully connected layer, then activate it with Softmax to output the classification result, and use Dropout to reduce overfitting and improve the generalization ability of the garbage classification model.
[0058] Given that the ResNet-50 network structure consists of a single pooling layer followed by a fully connected layer for output, which can lead to excessive interference after the fully connected layer learns all the parameter values, an adaptive pooling module is introduced to reduce and increase the spatial channels, suppress some useless weight features, and reduce the number of parameters.
[0059] Adding a Dropout layer to a fully connected layer prevents overfitting and improves the model's generalization ability. The direct effect of Dropout is to reduce the number of intermediate features, thereby reducing redundancy and increasing the orthogonality between features in each layer.
[0060] The CBAM attention mechanism module includes a channel attention mechanism and a spatial attention mechanism. The channel attention mechanism can weight different channels and retain the channel feature information that is most important for image classification and recognition. The spatial attention mechanism mainly focuses on the feature information of different regions in the image. It obtains the spatial importance of each position by calculating the feature map channel by channel. By introducing the CBAM attention mechanism module into the fine-tuned pre-trained model, the model can better capture the key information in the image.
[0061] Step S5: Perform performance analysis on the garbage classification model; specifically: based on the garbage classification model, select cross-entropy loss as the loss function, and compare two optimization functions, SGD and Adam, while keeping other parameters unchanged; train different optimization functions using a test set, record the loss rate after each iteration, compare the performance differences of the two optimization functions on the test set, analyze the changes in the loss rate curve, and select a suitable optimization function to improve the performance and recognition efficiency of the deep garbage classification model.
[0062] This invention also provides a deep learning-based system for waste classification and identification, including an image preprocessing module, a model training module, and a model analysis module. The image preprocessing module is used to preprocess image sample data of various types of waste. The model training module includes training and fine-tuning a ResNet-50 network structure and building a waste classification model based on the ResNet-50 network structure. The model analysis module is used to perform performance analysis on the waste classification model.
[0063] In traditional machine learning, it is usually necessary to retrain a new model from scratch to solve new problems, which requires a large amount of data and computing resources. This method adopts transfer learning when building a garbage classification model. It utilizes the features learned by the pre-trained model to reduce the overfitting problem that may occur when training on small datasets and shorten the training time of the pre-trained model. Then, the pre-trained model is fine-tuned to adapt to the garbage image dataset, which can quickly build a high-performance garbage classification model with strong generalization ability and improve the accuracy of garbage classification.
[0064] The method of this invention is based on deep learning and uses the backpropagation algorithm to train the network. By constructing a multi-layered neural network, it learns and extracts high-level feature representations, thereby realizing automated data classification, recognition, clustering and other tasks. It can be widely used in the fields of image recognition, facial recognition, image processing, medical image analysis and other technical fields.
Claims
1. A method for waste classification and identification based on deep learning, characterized in that, Includes the following steps: Step S1: Obtain a dataset containing various types of garbage images; Step S2: Preprocess the images in the dataset and divide the preprocessed dataset into training and testing sets; Step S3: Select the ResNet-50 network structure as the pre-trained model, and use transfer learning to train and fine-tune the pre-trained model. Specifically, freeze the convolutional blocks near the input end in the pre-trained model, keep the weights of the initial layer unchanged, and train the remaining convolutional blocks near the output end and the fully connected classifier with the training set to obtain new weights. The new weights are obtained by subtracting the backpropagation error from the initial weights. When the backpropagation error is positive, decrease the value of the weights; when the backpropagation error is negative, increase the value of the weights. Step S4: Introduce the CBAM attention mechanism module into the fine-tuned pre-trained model to construct a garbage classification model. Specifically, add the CBAM attention mechanism module to the first-level convolutional layer in the ResNet-50 network structure to improve the representation ability of image features, fix the weights of other layers except the fully connected layers, and add the CBAM module before the last layer to increase the attention to important image information during feature extraction; replace the ordinary pooling layer with the AP module composed of two layers of adaptive average pooling to increase the selection of image feature information; modify the fully connected layer, then activate it with Softmax to output the classification result, and use Dropout to reduce overfitting and improve the generalization ability of the garbage classification model. The CBAM attention mechanism module includes a channel attention mechanism and a spatial attention mechanism. The channel attention mechanism can weight different channels and retain the channel feature information that is most important for image classification and recognition. The spatial attention mechanism focuses on the feature information of different regions in the image and obtains the spatial importance of each position by calculating the feature map channel by channel. By introducing the CBAM attention mechanism module into the fine-tuned pre-trained model, the model can better capture the key information in the image. Step S5: Perform performance analysis on the waste sorting model.
2. The method for waste classification and identification based on deep learning according to claim 1, characterized in that, Step S2 describes the preprocessing of images in the dataset, including data annotation, data analysis, image scaling and cropping, image data standardization, and data augmentation. Data annotation refers to classifying and numbering each image in the dataset; Data analysis refers to removing junk data, specifically images that are of uneven quality due to differences in image type, aspect ratio, and shooting environment. Image data standardization refers to the normalization operation performed on an image, adjusting the feature values of different dimensions to a similar range; Data augmentation refers to expanding a dataset to increase the number of images within it.
3. The method for waste classification and identification based on deep learning according to claim 2, characterized in that, The normalization operation is as follows: (1), In the formula, output is the output of image pixel values, input is the input of image pixel values, and max and min are the maximum and minimum pixel values. After normalization, the pixel values of the image are adjusted to the range of (0,1).
4. The method for waste classification and identification based on deep learning according to claim 2, characterized in that, The data augmentation includes transforming images within the garbage dataset using color enhancement, horizontal flipping, vertical flipping, image sharpening, Gaussian noise, and Gaussian blur.
5. The method for waste classification and identification based on deep learning according to claim 1, characterized in that, The fine-tuned model is tested using the training and test sets to evaluate its accuracy (Train_Accuracy) and loss (Train_Loss) on the training set, and its accuracy (Val_Accuracy) and loss (Val_Loss) on the test set.
6. The method for waste classification and identification based on deep learning according to claim 5, characterized in that, The accuracy rate mentioned therein is (2), In the above formula (2), TP represents the number of instances that are correctly classified as positive, that is, the number of instances that are actually positive and classified as positive by the classifier; TN represents the number of instances that are correctly classified as negative, that is, the number of instances that are actually negative and classified as negative by the classifier; FP represents the number of instances that are incorrectly classified as positive, that is, the number of instances that are actually negative but classified as positive by the classifier; FN represents the number of instances that are incorrectly classified as negative, that is, the number of instances that are actually positive but classified as negative by the classifier.
7. The method for waste classification and identification based on deep learning according to claim 5, characterized in that, The loss value mentioned above is (3), In the above formula (3), N is the total number of samples. This represents one of the output samples, where y is the actual value and x is the predicted value.
8. The method for waste classification and identification based on deep learning according to claim 1, characterized in that, The performance analysis of the garbage classification model described in step S5 is as follows: Based on the garbage classification model, cross-entropy loss is selected as the loss function, and two optimization functions, SGD and Adam, are selected for comparison while keeping other parameters unchanged; different optimization functions are trained using a test set, and the loss rate after each iteration is recorded. The performance differences of the two optimization functions on the test set are compared, the changes in the loss rate curve are analyzed, and a suitable optimization function is selected to improve the performance and recognition efficiency of the deep garbage classification model.
9. A system based on the deep learning-based garbage classification and identification method of claim 1, characterized in that: It includes an image preprocessing module, a model training module, and a model analysis module; The image preprocessing module is used to preprocess image sample data of various types of garbage; The model training module includes training and fine-tuning the ResNet-50 network structure, and building a garbage classification model based on the ResNet-50 network structure. The model analysis module is used to perform performance analysis on the waste sorting model.