Garbage classification method based on improved Cswin Transform model
Through the improved Cswin Transformer model, the Agent attention module and LionBatch optimization strategy were introduced, combined with the label smooth cross-entropy loss function, the problems of poor generalization ability and overfitting of the garbage classification algorithm are solved, and efficient and accurate garbage image recognition is achieved. and classification.
Patent Information
- Application Number
- CN202411094489.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-10
- Publication Date
- 2024-12-03
- Estimated Expiration
- 2044-08-10
AI Technical Summary
Existing garbage classification algorithms have poor generalization capabilities, low classification accuracy when facing different types of garbage, and are prone to overfitting problems. Especially when training data is insufficient, it is difficult to maintain high efficiency in practical applications.
The improved Cswin Transformer model is adopted, and the Agent attention module and LionBatch optimization strategy are introduced, combined with the label smooth cross-entropy loss function, the feature extraction ability and training efficiency of the model are enhanced, the calculation complexity is reduced, and the generalization performance of the model is improved.
It significantly improves the accuracy and efficiency of garbage classification, reduces the number of parameters and training costs of the model, improves the ability to recognize garbage images in complex background environments, and enhances the robustness and generalization capabilities of the model.
Smart Images

Figure CN119068241A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of natural image classification and relates to an efficient multi-modal fusion method for classifying junk images. Background Art
[0002] With the acceleration of urbanization and the rapid growth of population, the improvement of residents' living standards has brought about the diversification of consumption structure, and the amount of domestic waste has also increased dramatically. In this context, effectively controlling the growing amount of garbage has become a major challenge. Although garbage sorting and recycling are effective ways to deal with urban garbage and protect the environment, due to the wide variety and different forms of garbage, a lot of manpower is required to correctly sort the garbage. In addition, the lack of residents' awareness of classification and the incomplete implementation of relevant policies have also led to unsatisfactory results in the implementation of garbage sorting. Accurate garbage sorting technology can not only effectively distinguish different types of garbage, but also significantly improve the feasibility of harmless treatment, ensure that hazardous waste is specially treated, and reduce threats to the environment and public health. Automated garbage processing technology further improves sorting efficiency and reduces operating costs through artificial intelligence and machine learning. Therefore, the development of effective automatic garbage sorting methods is of great practical significance.
[0003] Image recognition is increasingly used in the field of garbage classification, mainly relying on the development of deep learning technology. Traditional garbage classification algorithms mainly rely on manual feature extraction and classic machine learning classifiers, such as support vector machines (SVM) and decision trees. These methods usually describe garbage images by extracting manually designed features such as color histograms, texture features, and shape features. Due to the limitations of feature extraction, traditional algorithms have poor generalization ability, low classification accuracy, and slow speed when facing different types of garbage, which limits their scope of application. At present, image classification algorithms based on CNN have achieved initial results in garbage classification research, which has strongly promoted the rapid development of intelligent garbage classification management. Convolutional neural networks (CNNs) automatically extract image features through multi-layer convolution, pooling, and fully connected layers, and can learn effective features from data, avoiding the limitations of manually designed features. The powerful feature expression ability of CNN enables it to capture complex information in images and significantly improve classification accuracy. However, CNN also has some significant shortcomings in garbage classification applications. Although CNN performs well in feature extraction, its complex structure and numerous parameters can easily lead to overfitting problems, especially when there is insufficient training data. Overfitting can cause the model to perform well on the training data, but in actual applications, the classification effect will drop significantly when faced with unseen data.
[0004] Garbage classification under limited data and complex background environments has always been a difficult and hot issue in research. The ideal garbage classification method should be based on sufficient data as support. However, the data obtained in practical applications often cannot meet the requirements of deep learning, resulting in overfitting and convergence collapse of the network model on a small number of data sets, weakening the generalization ability of the model. At the same time, due to the influence of the natural environment and complex background, the main body of the obtained image may not be effectively recognized by the network model, affecting the accuracy of the garbage classification results. Therefore, it is very necessary to design an efficient garbage classification algorithm. Summary of the invention
[0005] The purpose of the present invention is to provide a garbage classification method based on deep learning technology, break through the limitations of existing research in the field of garbage classification, and effectively improve the accuracy of garbage classification.
[0006] The present invention discloses an automatic garbage classification method based on an improved Cswin Transformer, comprising the following steps:
[0007] (1) First, we obtain a garbage image dataset in natural scenes by collecting it through cameras and searching the Internet, and then preprocess the dataset;
[0008] (2) In view of the challenges of garbage classification and the lack of research in this task field, a garbage classification model based on an improved CswinTransformer is proposed. The improvement method includes introducing the Agent Attention Module (AA) to enhance the model's ability to extract features; using the LionBatch optimization strategy in the training phase to improve the model training speed and resource utilization efficiency; and using the label smoothing cross entropy loss function in the training phase to improve the generalization performance of the model;
[0009] (3) The preprocessed garbage image data is fed into the improved Cswin Transformer model for training and verification, and the test set is used for centralized testing, and the final performance of the model is evaluated through multiple evaluation indicators;
[0010] (4) The garbage image to be classified is input into the improved Cswin Transformer model trained in step c above, and the classification result is output through forward calculation.
[0011] Furthermore, the pretreatment method described in step 1 is specifically:
[0012] (1.1) Before the experiment, we first set the corresponding category for the garbage targets in each image; normalize the size of the image I input to the network and scale the image size to 224*224 pixels; then, we augment the data by performing operations such as mirroring, flipping, translating, shearing, affine transformation, and rotation on the image set; finally, we randomly divide the data set into a training set and a test set in a ratio of 8:2.
[0013] (1.2) Set the data preprocessing method for the training model. Use the Mixup data enhancement algorithm to perform linear interpolation on every two garbage images input to the network, mix the two images in proportion, and mix their corresponding labels to form a new image data. The calculation formula of Mixup data enhancement is as follows:
[0014]
[0015] Among them I i ,I j are two images randomly selected from the training set, L i ,L j is the corresponding one-hot label, λ 1 ∈[0,1] is a hyperparameter generated by Beta distribution calculation. Based on prior knowledge, a new sample is constructed.
[0016] Furthermore, the garbage classification method based on the improved Cswin Transformer described in step 2 is specifically as follows:
[0017] (2.1) The Agent Attention Module (AA) is introduced into the feature fusion network to improve the flexibility and information capture ability of the model. The attention calibration process of the feature map is optimized by combining the soft attention mechanism. Specifically, the input feature map I is linearly transformed to simplify the attention weight matrix W to obtain the query vector Q, key vector K and value vector V. The calculation process is as follows:
[0018] Q=IW Q
[0019] K=IW K
[0020] V=IW V
[0021] Where W Q is the weight matrix of query Q, W K is the key weight matrix, W V is the weight matrix of the value; then the agent attention fuses the output of the soft attention mechanism, and the calculation process is as follows:
[0022] First, the Softmax attention O S It is expressed as:
[0023]
[0024] Then, we introduce the agent tag A to replace the original query Q, and perform attention calculation between the new query A, key K, and value V to aggregate the agent features V from all values. A , the calculation process is as follows:
[0025] V A =Softmax(AK T )V
[0026] Then, A is used as the key in the second attention calculation of the query matrix Q, V A As the value, broadcast the global information of the proxy feature to each query token and obtain the final output O A , the calculation process is as follows:
[0027] O A =Softmax(QA T )V A
[0028] =Softmax(QA T )*Softmax(AK T )V
[0029] The newly defined agent A essentially acts as a proxy for the query Q, aggregating global information from the key K and value V, and then broadcasting it back to Q, maintaining the global context modeling capability; in order to better utilize the location information, the agent attention O adds a carefully designed agent bias, the calculation formula is as follows:
[0030] O = Softmax(QA T +B 2 )*Softmax(AK T +B 1 )V+DWC(V)
[0031] Among them, B 1 ∈[0,1],B 2 ∈[0,1] is the bias and DWC(·) is the depthwise separable convolution, which enables the attention mechanism to reduce the complexity of the model while maintaining the performance.
[0032] (2.2) After the optimization strategy LionBatch is introduced in the training phase, the training speed and resource utilization efficiency of the model are improved; LionBatch allows the pruning decision to be adjusted according to the real-time performance of the data during the training process, thereby controlling the training process more finely; LionBatch can maintain model performance while reducing training costs, achieving lossless training acceleration. The specific calculation process of this module is as follows:
[0033] First, calculate the average loss L for the entire dataset a , which can be expressed as:
[0034]
[0035] Among them, N represents the number of samples, l represents the loss function, and x i represents the model input, y i Represents the model output. For data samples with a loss less than the average, pruning will be performed with a certain probability, which can be expressed as:
[0036]
[0037] Among them, t∈[1,300] represents the current training round, p t represents the current data sample, r∈[0,1] is the hyperparameter of probability pruning; due to the reduction in sample size, the gradient of the entire data set will change, resulting in inconsistency with the expected gradient of the original data set. In order to solve this problem, the average loss L a The gradient of the data sample is rescaled and can be expressed as:
[0038]
[0039] Among them, g t represents the gradient of the current data sample, η t ∈[0,1] is the learning rate, is the loss function with respect to the parameter g t-1 The gradient of ; then optimize the pruned data subset for training, use the gradient and previous momentum to calculate the current update momentum, and use the sign(·) function to specify the update direction to update the model parameters, which can be expressed as:
[0040] m t =β 1 m t-1 +(1-β 1 ) t
[0041] θ t =θ t-1 -η t (sign(m t )+λ2 θ t -1)
[0042] Among them, m t represents momentum, β 1 ∈[0,1] represents the momentum factor, g t represents the gradient, θ t Represents the current model training parameters, λ 2 ∈[0,1] is the hyperparameter for calculating momentum; repeat the above process and gradually optimize the model parameters until the expected performance indicators are achieved.
[0043] (2.3) Introduce a label smoothed cross entropy loss function to learn and optimize difficult samples, so that the model pays more attention to such samples during training and improves the generalization ability of the model; the loss of difficult samples is large, but the number is relatively scarce, and it is not easy for the model to pay attention to them during training. Therefore, it is necessary to assign higher learning weights to difficult samples; when using the label smoothed cross entropy method, by calculating the deviation between the predicted probability and the true label of all samples, the samples with larger predicted probability deviation are defined as difficult samples and given higher learning weights.
[0044] Furthermore, the training, verification and testing methods of the improved Cswin Transformer model described in step 3 are specifically as follows:
[0045] (3.1) Input the garbage dataset preprocessed in step 1 into the improved CswinTransformer network in step 2 for training. Set 300 iterations. After each iteration, use the validation set to verify the performance of the model generated in each iteration. Save the optimal model weight file by comparison.
[0046] (3.2) After the training iteration is completed, the test set is used to test the optimal model obtained in the final training in (3.1). The performance of the improved model is evaluated by the model's parameter quantity, Top1 accuracy, precision, recall rate, and F1 score to verify the effectiveness and advancement of the model.
[0047] Furthermore, the method for classifying garbage images using the improved model described in step 4 is as follows: first, the garbage image to be classified is input into the model, and loaded into (3.1) to obtain the optimal model weight, and finally the correct garbage category is identified through prediction.
[0048] The present invention has the following characteristics:
[0049] 1. This paper introduces a new method for garbage classification using a multimodal fusion garbage classification network. It integrates advanced technologies such as the Cswin Transformer architecture, Agent attention mechanism, and LionBatch optimization strategy, and can quickly and accurately identify and classify garbage.
[0050] 2. This invention introduces the Agent attention mechanism to address the problem of high model computational burden under large-scale data sets. By introducing agent tokens when calculating attention, the aggregation process of global information is simplified, which not only maintains high expressive power but also reduces computational complexity. It can also focus on the key areas of the image more effectively, thereby improving the accuracy and efficiency of classification, and has significant advantages when processing large amounts of data and complex tasks.
[0051] 3. This paper adopts LionBatch optimization strategy to solve the problems of large number of Transformer model parameters and slow training speed. It achieves lossless model training acceleration by calculating momentum updates through symbolic operations and reducing the training of useless samples. It effectively reduces the overall training cost and significantly improves the model efficiency and effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 This is a flow chart of the garbage classification algorithm proposed in the present invention.
[0053] Figure 2 This is the Mixup data enhancement strategy used in the present invention.
[0054] Figure 3 This is a structural diagram of the Agent attention mechanism used in the present invention.
[0055] Figure 4 This is a structural diagram of the MFGC module proposed in the present invention.
[0056] Figure 5 Schematic diagram of the LionBatch optimization strategy proposed in the present invention.
[0057] Figure 6 This is a structural diagram of the MFGC-Net model proposed in the present invention.
[0058] Figure 7 Attention heatmap of MFGC-Net on junk images used for this invention.
[0059] Figure 8 This is a comparison curve of the training accuracy between the MFGC-Net proposed in this invention and the mainstream network.
[0060] Fig. 9 A scatter plot comparing the training parameters and time of the MFGC-Net proposed in the present invention and the mainstream network.
[0061] Fig.10 This is an example of garbage images collected by the present invention in a natural environment.
[0062] Fig.11 This is an example diagram of the recognition results of the MFGC-Net proposed in this invention on 135 types of junk images. DETAILED DESCRIPTION
[0063] The present invention is further described below with reference to the accompanying drawings and specific implementation examples.
[0064] The present invention proposes an efficient garbage classification algorithm, combining Figures 1 to 11 The detailed instructions are as follows:
[0065] like Figure 1 The flowchart of the garbage classification algorithm based on the improved Cswin Transformer network proposed by the present invention is shown. In this process, garbage image data is first collected in natural scenes by a camera and obtained by searching the Internet, and the data set is preprocessed. Secondly, the Cswin Transformer model is improved to improve the accuracy of the garbage classification task. The improvement method includes introducing an Agent Attention Module (AA) to improve the feature extraction capability; using the LionBatch optimization strategy to improve the model training speed and resource utilization efficiency; and using a label smoothing cross entropy loss function to improve the generalization performance of the model. Then, the image data is input into the improved Cswin Transformer model with a fixed size of 224*224 for training and verification, and the test set is used for centralized testing. Finally, the garbage image to be classified is input into the model weight of the garbage automatic classification method proposed by the present invention, and the classification result is output by forward calculation.
[0066] like Figure 2 The Mixup data enhancement strategy used in the present invention is shown in FIG. Mixup data enhancement generates new training samples by linearly interpolating two images and their corresponding labels. Specifically, it mixes two images and mixes their labels in the same proportion to form a new image and label pair. This method not only increases the diversity of training data, but also improves the generalization ability of the model, reduces overfitting, and enhances the model's resistance to noise and adversarial samples.
[0067] like Figure 3The figure shows the structure of the Agent attention mechanism used in the present invention. The Agent attention mechanism combines standard soft attention and linear attention to more comprehensively capture the salient features of the input data. Specifically, the Agent attention mechanism introduces a set of agent tokens that first aggregate information from key-value pairs and then broadcast it back to the query token. Since the number of agent tokens can be designed to be much smaller than the query token, the Agent attention mechanism significantly reduces the computational complexity while maintaining the global context modeling capability.
[0068] like Figure 4 This is a structural diagram of the MFGC module proposed in the present invention. The MFGC module is equipped with Figure 3 The module uses the Agent Self-Attention Mechanism (AA) to optimize the information processing flow. The module uses layer normalization (LN) in the beginning and middle parts to standardize the mean and variance of the input layer. Between the two layer normalization links, the Agent Self-Attention Mechanism (AA) is integrated. This mechanism optimizes the attention calculation by introducing agent tokens, reduces the complexity of direct calculations, and improves the efficiency and accuracy of information processing. Following AA, the module also uses a multi-layer perceptron (MLP), which consists of several fully connected layers and embeds nonlinear activation functions between layers. The MFGC Block with the Agent Attention Mechanism performs well in computational efficiency and fast processing, and is suitable for different application scenarios.
[0069] like Figure 5 This is a schematic diagram of the LionBatch optimization strategy proposed in the present invention. Specifically, LionBatch only tracks momentum during model training and calculates updates through symbolic operations, thereby reducing memory overhead and ensuring consistency of update amplitudes in all dimensions. In addition, LionBatch implements dynamic pruning, allowing pruning decisions to be adjusted according to the real-time performance of the data during training, thereby controlling the training process more finely. Through this dynamic and unbiased pruning method, LionBatch can maintain model performance while reducing training costs, achieving lossless training acceleration.
[0070] Based on Cswin Transformer, the present invention proposes MFGC-Net network. Figure 6The figure shows the structure diagram of the MFGC-Net model proposed in the present invention. MFGC-Net uses a four-layer pyramid structure to efficiently process and abstract image features. The first three layers of the network constitute the basic feature extraction and processing modules, and each layer is composed of multiple CSWin modules. These blocks use the self-attention mechanism of the cross-shaped window to process image data, which is suitable for capturing the local features of the image and its spatial correlation. The last layer uses the MFGC module, which replaces the cross-shaped window self-attention mechanism of the traditional Cswin module and adopts the Agent self-attention mechanism. Through innovative structural design, MFGC-Net effectively improves the depth and breadth of feature processing, enhances the expressiveness of the model, and optimizes computational efficiency.
[0071] In order to analyze the contribution of each improvement strategy to improving model performance, ablation experiments were conducted to evaluate the effectiveness of the improvement strategies. For fair comparison, the same dataset and experimental environment were used in all experiments. Cswin Transformer was used as the baseline network, and Agent attention mechanism, Lion optimizer and InfoBatch pruning were introduced in turn to optimize and improve Cswin Transformer. The ablation experiment results are shown in Table 1. The Top1 accuracy achieved by each improvement strategy reached 93.53%, 94.04% and 93.52% respectively, all exceeding Cswin Transformer. Finally, the MFGC-Net model proposed by combining all improvement strategies achieved a Top1 accuracy of 94.35% on the basis of fewer parameters and lower time complexity than Cswin Transformer, which was 1.85% higher than Cswin Transformer.
[0072] Table 1: Ablation experiments
[0073]
[0074] like Figure 7 The figure shows the heat map of the attention of the present invention using MFGC-Net on the garbage image. It can be seen from the figure that the MFGC-Net model can effectively suppress the influence of noise information (background, stones, branches, etc.), improve the coverage and attention of the target area, and pay more attention to the global (contour and texture) of the garbage target. The above results show that the proposed MFGC-Net can effectively calibrate the model's attention to the target, accurately locate and identify garbage targets in complex scenes. This also indirectly proves that the model has strong generalization performance when applied.
[0075] In order to verify the superiority of the present invention over other advanced classification algorithms, the present invention adds comparative experiments, and the comparative results are shown in Table 2, Table 3 and Table 4. The MFGC-Net model of the present invention has the highest Top1 accuracy, reaching 98.89% on the GarbageClassification dataset, 96.43% on the TrashNet dataset, and 94.35% on the MixTrash dataset built by the present invention, with a parameter volume of 43.18M. Compared with other advanced classification algorithms, the classification performance is better, and a trade-off can be achieved between classification accuracy and classification speed.
[0076] Table 2: Performance comparison of each model on the Garbage Classification dataset
[0077]
[0078] Table 3: Performance comparison of each model on the TrashNet dataset
[0079]
[0080] Table 4: Performance comparison of each model on the MixTrash dataset
[0081]
[0082] like Figure 8 The figure shows the training accuracy comparison curve of MFGC-Net proposed in the present invention and the mainstream network. It can be seen from the figure that the Top1 accuracy curve of MFGC-Net rises steadily and converges quickly until it tends to fit, and the final Top1 accuracy value is better than other models.
[0083] like Fig. 9 The figure shows a scatter plot comparing the training parameters and time of the MFGC-Net proposed in the present invention and the mainstream network. As can be seen from the figure, MFGC-Net performs excellently, standing out with the highest Top-1 accuracy and moderate training time. Under the same parameter conditions, the training time of MFGC-Net is significantly lower than that of other models, and its accuracy is higher than that of other models, demonstrating excellent classification performance and high training efficiency.
[0084] Combine the following Fig.10 and Fig.11 Here is an application case:
[0085] like Fig.10The figure shows an example of garbage images in natural scenes obtained by the image acquisition module. The image set is 135 types of household garbage images, including apple cores, banana peels, batteries, books, button batteries, cigarette butts, lunch boxes, pencils, plastic bottles, remote controls, waste paper, watermelon peels, etc. In order to verify that the method proposed in the present invention has strong robustness in real scenes, the garbage images (a) and (b) to be classified are input into the weights of the improved Cswin Transformer model obtained by training, and the visual classification results are output by calculation.
[0086] The classification results are as follows Fig.11 As shown, all kinds of garbage in the visible image can be effectively classified, which has practical application significance.
Claims
1. A garbage classification method based on an improved Cswin Transformer model, characterized in that: The steps include: a. First, a garbage image dataset T is created in natural scenes by collecting data through cameras and searching the Internet, and the dataset is preprocessed to obtain a new garbage image dataset MT after processing; During the preprocessing process, each image I∈MT is properly adjusted and enhanced to ensure image clarity and effective feature extraction; b. Build a garbage classification model based on the improved Cswin Transformer. The improvement method includes introducing the Agent attention module in the feature fusion network to enhance the model's ability to extract features; The LionBatch optimization strategy is used in the training phase to improve the model training speed and resource utilization efficiency; The label smoothed cross entropy loss function is used in the training phase to improve the generalization performance of the model; c. The preprocessed garbage image data is fed into the improved Cswin Transformer model for training and verification, and the test set is used for centralized testing. The final performance of the model is evaluated using five evaluation indicators; d. Input the garbage image to be classified into the improved Cswin Transformer model trained in step c above, and output the classification result through forward calculation.
2. The image preprocessing method in step a of claim 1, characterized in that: The image I input to the network is normalized and scaled to 224*224 pixels. The data is augmented by mirroring, flipping, translating, shearing, affine transformation, and rotating the dataset. The dataset is randomly divided into a training set and a test set at a ratio of 8:
2. The Mixup data enhancement algorithm is used to perform linear interpolation on every two garbage images input to the network, and the two images are mixed in proportion, and their corresponding labels are mixed to form a new image data. The calculation formula for Mixup data enhancement is as follows: Among them I i ,I j are two images randomly selected from the training set, L i ,L j is the corresponding unique hot label, λ1∈[0,1] is the hyperparameter calculated by Beta distribution, and a new sample is constructed based on prior knowledge.
3. The Agent attention method in step b of claim 1, characterized in that: It is composed of two soft attention mechanisms Softmax, which are responsible for agent aggregation and agent broadcasting respectively, so as to optimize the attention calibration process of the feature map; the specific method is to perform a linear transformation on the image data I in step a of claim 1 to simplify the attention weight matrix W, and obtain the query vector Q, key vector K and value vector V. The calculation process is as follows: Q2IW Q K=IW K V=IW V Where W Q is the weight matrix of query Q, W K is the weight matrix of key K, W V is a weight matrix of value V; then the agent attention fuses the output of the soft attention mechanism, and the calculation process is as follows: First, the Softmax attention O S It is expressed as: About S =Softmax(QK T )V Then, we introduce the agent tag A to replace the original query Q, and perform attention calculation between the new query A, key K, and value V to aggregate the agent features V from all values. A , the calculation process is as follows: V A =Softmax(AK T )V Then, A is used as the key in the second attention calculation of the query matrix Q, V A As the value, broadcast the global information of the proxy feature to each query token and obtain the final output O A , the calculation process is as follows: O A =Softmax(QA T )V A =Softmax(QA T )*Softmax(AK T )V The newly defined agent A essentially acts as a proxy for the query Q, aggregating global information from the key K and value V, and then broadcasting it back to Q, maintaining the global context modeling capability; in order to better utilize the location information, the agent attention O adds a carefully designed agent bias, the calculation formula is as follows: <h2 style=";text-align:left;direction:ltr">O=Softmax(QA<h2 style=";text-align:left;direction:ltr"> T <h2 style=";text-align:left;direction:ltr"> +B2)*Softmax(AK<h2 style=";text-align:left;direction:ltr"> T <h2 style=";text-align:left;direction:ltr"> +B1)V+DWC(V) Among them, B1∈[0,1],B2∈[0,1] are biases, and DWC(·) is a depthwise separable convolution, which enables the attention mechanism to reduce the complexity of the model while maintaining performance.
4. The LionBatch optimization strategy in step b of claim 1, characterized in that: During model training, only momentum is tracked, and updates are calculated through symbolic operations, thereby reducing memory overhead and ensuring consistency of update amplitudes in all dimensions. During training, pruning decisions are adjusted based on the real-time performance of the data, reducing the training of useless samples, and achieving lossless training acceleration. The LionBatch optimization strategy calculation process is as follows: First, calculate the average loss L for the entire dataset a , which can be expressed as: Among them, N represents the number of samples, l represents the loss function, and x i represents the model input, y i Represents the model output, for which the average loss L is less than a The data samples will be pruned according to a certain probability, which can be expressed as: Among them, t∈[1,300] represents the current training round, p t represents the current data sample, r∈[0,1] is the hyperparameter of probability pruning; due to the reduction in sample size, the gradient of the entire data set will change, resulting in inconsistency with the expected gradient of the original data set. In order to solve this problem, the average loss L a The gradient of the data sample is rescaled and can be expressed as: Among them, g t represents the gradient of the current data sample, η t ∈[0,1] is the learning rate, is the loss function with respect to the parameter g t-1 The gradient of ; then optimize the pruned data subset for training, use the gradient and previous momentum to calculate the current update momentum, and use the sign(·) function to specify the update direction to update the model parameters, which can be expressed as: m t =β1m t-1 +(1-β1)g t i t =θ t-1 -or t (sign(m t )+λ2θ t -1) Among them, m t represents momentum, β1∈[0,1] represents momentum factor, g t represents the gradient, θ t Represents the current model training parameters, λ2∈[0,1] is the hyperparameter for calculating momentum; repeat the above process and gradually optimize the model parameters until the expected performance indicators are achieved.
5. The label smoothed cross entropy loss function in step b of claim 1, characterized in that: By introducing a smoothing coefficient, the label distribution is made smoother, the sensitivity to label noise is reduced, and the generalization ability of the model is improved. The calculation process of the label smoothing cross entropy loss function is as follows: First, the label is smoothed. For each true label z i , generates a smooth label It can be expressed as: Where ∈∈[0,1] is the smoothing coefficient and K is the number of categories; the Softmax function is then used to calculate the model's predicted probability c i , expressed as: Among them, s i is the output of the model, combined with the smoothed label With the predicted probability c i Calculate the cross entropy loss L p , and dynamically adjust the loss weight according to the sample difficulty. Finally, the label smoothed cross entropy loss function can be expressed as: Among them, α∈[0,1] is a dynamic weight factor, which is dynamically adjusted according to the sample difficulty to increase the attention to difficult samples.
6. The training, verification and testing method of the improved Cswin Transformer model in step c of claim 1, characterized in that: The preprocessed garbage dataset was input into the improved network for training for 300 iterations; After each iteration, the test set is used to verify the performance of the model generated in each iteration. The optimal model is obtained after 300 training and testing times. The test set is used to test the optimal model obtained by the final training. The model performance is evaluated by the model's parameter quantity, Top1 accuracy, precision, recall rate, and F1 score to verify the effectiveness and advancement of the model.
7. The method for classifying junk images by a model according to step d of claim 1, characterized in that: The junk image to be classified is adaptively scaled to a resolution of 224*224 pixels and loaded into the model of the present invention; the image is then input into the model with weights, and each layer module of the model uses these weights to extract features from the image and identify key features in the image; secondly, the features are finally calculated through the fully connected layer to convert the features into category probabilities; finally, the model selects the category with the highest probability as the prediction result, that is, it is considered that the input junk image belongs to this category.
Citation Information
Patent Citations
Construction waste classification method and device based on optimized Swin Transform network
CN115661507A
Multi-target garbage detection method based on improved YOLOv5 model
CN116452950A
Garbage detection method in complex scene based on improved YOLOv8 model
CN117710771A
Cited By
Garbage classification method based on GMama model
CN120431408A
A garbage classification method based on GMamba model
CN120431408B
