A Waste Sorting Method Based on an Improved Cswin Transformer Model

CN119068241BActive Publication Date: 2026-08-21ZHEJIANG FORESTRY UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411094489.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-10
Publication Date
2026-08-21
Estimated Expiration
2044-08-10

AI Technical Summary

Technical Problem

理想的垃圾分类方法应基于足量的数据作为支撑,然而在实际应用中所获得的数据往往不能满足深度学习的要求,从而导致网络模型在数量少的数据集上产生过拟合以及收敛崩溃的现象,削弱模型的泛化能力

Benefits of technology

[0047]进一步的,步骤4所述的用改进模型对垃圾图像进行分类的方法具体为:首先将待分类的垃圾图像输入到模型,并载入(3.1)中得到最优的模型权重,最终通过预测识别正确的垃圾类别。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119068241B_ABST
    Figure CN119068241B_ABST
Patent Text Reader

Abstract

The application discloses an automatic garbage recognition method, which is characterized by the following steps: obtaining the image of garbage through a camera and internet search, and performing data enhancement preprocessing on the picture; introducing an Agent attention module into a Cswin Transformer model to enhance the feature extraction capability of the model; adopting a LionBatch optimization strategy to improve the model training speed and resource utilization efficiency; adopting a label smoothing cross-entropy loss function to dynamically weight the difficult samples; inputting the preprocessed image data into the improved model for training and testing to obtain an optimal model; and finally inputting the image to be classified into the optimal model to obtain the classification result. The automatic garbage recognition method based on the improved Transformer can ensure automatic garbage recognition and obtain the correct type, and has a good application prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of natural image classification and relates to an efficient multimodal fusion method for classifying garbage images. Background Technology

[0002] With the acceleration of urbanization and rapid population growth, the improvement of residents' living standards has led to the diversification of consumption patterns, resulting in a sharp increase in the amount of household waste. Against this backdrop, effectively controlling the ever-increasing volume of waste has become a major challenge. While waste sorting and recycling are effective methods for managing urban waste and protecting the environment, the diverse types and forms of waste require a significant human resource investment to correctly classify it. Precise waste sorting technology can not only effectively distinguish different types of waste but also significantly improve the feasibility of harmless treatment, ensuring that hazardous waste is treated specifically and reducing threats to the environment and public health. Automated waste processing technology further improves sorting efficiency and reduces operating costs through artificial intelligence and machine learning. Therefore, developing effective automated waste sorting methods has significant practical implications.

[0003] Image recognition is increasingly widely used in waste sorting, primarily due to the development of deep learning technology. Traditional waste sorting algorithms mainly rely on manual feature extraction and classic machine learning classifiers, such as Support Vector Machines (SVMs) and decision trees. These methods typically describe waste images by extracting manually designed features such as color histograms, texture features, and shape features. Due to the limitations of feature extraction, traditional algorithms suffer from poor generalization ability, low classification accuracy, and slow speed when facing different types of waste, thus limiting their application scope. Currently, CNN-based image classification algorithms have shown initial success in waste sorting research, strongly promoting the rapid development of intelligent waste sorting management. Convolutional Neural Networks (CNNs) automatically extract image features through multiple layers of convolution, pooling, and fully connected layers, learning effective features from data and avoiding the limitations of manually designed features. CNNs' powerful feature representation capabilities enable them to capture complex information in images, significantly improving classification accuracy. However, CNNs also have some significant drawbacks in waste sorting applications. Although CNNs perform well in feature extraction, their complex structure and numerous parameters make them prone to overfitting, especially when training data is insufficient. Overfitting can make a model perform well on training data, but in real-world applications, its classification performance drops significantly when faced with unseen data.

[0004] Waste sorting under limited data and complex backgrounds has always been a challenging and hot research topic. An ideal waste sorting method should be supported by sufficient data; however, in practical applications, the data obtained often fails to meet the requirements of deep learning, leading to overfitting and convergence failure of network models on small datasets, thus weakening the model's generalization ability. Furthermore, due to the influence of the natural environment and complex backgrounds, the main subjects in the obtained images may not be effectively identified by the network model, affecting the accuracy of the waste sorting results. Therefore, designing an efficient waste sorting algorithm is essential. Summary of the Invention

[0005] The purpose of this invention is to provide a waste sorting method based on deep learning technology, which breaks through the limitations of existing research in the field of waste sorting and effectively improves the accuracy of waste sorting.

[0006] The present invention provides an automatic waste sorting method based on an improved Cswin Transformer, comprising the following steps:

[0007] (1) First, a dataset of garbage images was collected in natural scenes by camera and obtained by searching the Internet, and the dataset was preprocessed.

[0008] (2) In response to the challenges of garbage classification and the lack of research in this task area, a garbage classification model based on an improved CswinTransformer is proposed. The improvement methods include introducing an Agent Attention Module (AA) to enhance the model's ability to extract features; using the LionBatch optimization strategy during the training phase to improve the model's training speed and resource utilization efficiency; and using the label smooth cross-entropy loss function during the training phase to improve the model's generalization performance.

[0009] (3) The preprocessed garbage image data is fed into the improved Cswin Transformer model for training and validation, and the test set is used for centralized testing. The final performance of the model is evaluated through multiple evaluation metrics.

[0010] (4) 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.

[0011] Furthermore, the preprocessing method described in step 1 specifically includes:

[0012] (1.1) Before the experiment, the garbage targets in each image were first classified accordingly; the size of the image I input to the network was normalized and scaled to 224*224 pixels; the data was then augmented by performing operations such as mirroring, flipping, translating, cropping, affine transformation, and rotation on the image set; finally, the dataset was randomly divided into training set and test set in a ratio of 8:2.

[0013] (1.2) Set up a data preprocessing method for the training model. Use the Mixup data augmentation algorithm to perform linear interpolation on every two garbage images input to the network, mix the two images proportionally, and mix their corresponding labels to form a new image data. The calculation formula of Mixup data augmentation is as follows:

[0014]

[0015] Where I i ,I j Two images were randomly selected from the training set, L i ,L j These are the corresponding one-hot labels. λ1∈[0,1] are hyperparameters calculated using the Beta distribution. New samples are constructed based on prior knowledge.

[0016] Furthermore, the waste sorting method based on the improved Cswin Transformer described in step 2 is as follows:

[0017] (2.1) An Agent Attention Module (AA) is introduced and embedded into the feature fusion network to improve the model's flexibility and information capture capability. The attention calibration process of the feature map is optimized by combining a soft attention mechanism. Specifically, the input feature map I is linearly transformed to simplify the attention weight matrix W, resulting in 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] Among them W Q It is the weight matrix of query Q, W K W is the weight matrix of the keys. V It is the weight matrix of values; then the Agent attention is fused with the output of the soft attention mechanism, and the calculation process is as follows:

[0022] First, set the Softmax attention OS Represented as:

[0023]

[0024] Then, an agent label A is introduced to replace the original query Q, and attention is performed among the new query A, key K, and value V to aggregate the Agent aggregated agent feature V from all values. A The calculation process is as follows:

[0025] V A =Softmax(AK) T V

[0026] Then, in the second attention calculation of the query matrix Q, A is used as the key, and V... A As a value, global information about the proxy features is broadcast to each query tag, and the final output O is obtained. 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 query Q, aggregating global information from key K and value V, and then broadcasting it back to Q, maintaining the ability to model the global context. To better utilize location information, Agent attention O adds a carefully designed Agent bias, calculated as follows:

[0030] O = Softmax(QA) T +B2)*Softmax(AK T +B1)V+DWC(V)

[0031] Here, B1∈[0,1] and 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.

[0032] (2.2) The LionBatch optimization strategy is introduced during the training phase to improve the training speed and resource utilization efficiency of the model. LionBatch allows pruning decisions to be adjusted based on the real-time performance of the data during training, thereby enabling more granular control over the training process. 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 , can be represented as:

[0034]

[0035] Where N represents the number of samples, l represents the loss function, and x i Indicates the model input, y i The model output indicates that for data samples with losses less than the average loss, pruning will be performed according to a certain probability, which can be represented as:

[0036]

[0037] Where t∈[1,300] represents the current training round, p t Let r represent the current data sample, and r∈[0,1] be the hyperparameter of probability pruning. Due to the reduction in sample size, the gradient of the entire dataset will change, leading to inconsistency with the expected gradient of the original dataset. To address this issue, a value less than the average loss L is used. a The gradient of the data sample, after rescaling, 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. It is the loss function relative to the parameter g t-1 The gradient is calculated; then, the pruned subset of data is used for optimization training. The current update momentum is calculated using the gradient and the previous momentum, and the update direction is specified using the sign(·) function to update the model parameters. This can be expressed as:

[0040] m t =β1m t-1 +(1-β1)g t

[0041] θ t =θ t-1 -η t (sign(m t )+λ2θ t -1)

[0042] Where, m t Let g represent momentum, β1∈[0,1] represent momentum factor, and g t Let θ represent the gradient. t λ represents the current model training parameters, and λ2∈[0,1] is the hyperparameter for calculating momentum; repeat the above process to gradually optimize the model parameters until the expected performance index is achieved.

[0043] (2.3) Introducing a label-smooth cross-entropy loss function to learn and optimize hard samples, making the model pay more attention to these samples during training and improving the model's generalization ability; hard samples have a large loss, but their number is relatively small, and they are not easily noticed by the model during training. Therefore, it is necessary to assign higher learning weights to hard samples; when using the label-smooth cross-entropy method, by calculating the deviation between the predicted probability and the true label of all samples, samples with a large deviation in predicted probability are defined as hard samples and given higher learning weights.

[0044] Furthermore, the training, validation, and testing methods for the improved Cswin Transformer model described in step 3 are as follows:

[0045] (3.1) Input the preprocessed garbage dataset in step 1 into the improved CswinTransformer network in step 2 for training. Set an iteration cycle of 300 rounds. 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 best model obtained in the final training in (3.1) is tested using the test set. The performance of the improved model is evaluated by the number of model parameters, Top1 accuracy, precision, recall and F1 score, so as 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 weights, and finally the correct garbage category is identified through prediction.

[0048] This invention has the following characteristics:

[0049] 1. This invention introduces a novel method for waste sorting using a multimodal fusion waste sorting network. It integrates advanced technologies such as the Cswin Transformer architecture, Agent attention mechanism, and LionBatch optimization strategy, enabling rapid and accurate identification and sorting of waste.

[0050] 2. This invention addresses the problem of high computational burden on models with large-scale datasets by introducing an Agent attention mechanism. By introducing an agent token during attention calculation, the aggregation process of global information is simplified, maintaining high expressive power while reducing computational complexity. It can also more effectively focus on key regions of the image, thereby improving classification accuracy and efficiency, and has significant advantages when handling large amounts of data and complex tasks.

[0051] 3. This invention addresses the issues of large parameter count and slow training speed in Transformer models by employing the LionBatch optimization strategy. Through symbolic operations to calculate momentum updates and reducing training on useless samples, it achieves lossless model training acceleration. This effectively reduces overall training costs and significantly improves model efficiency and performance. Attached Figure Description

[0052] Figure 1 This is a flowchart of the garbage classification algorithm proposed in this invention.

[0053] Figure 2 The Mixup data augmentation strategy used in this invention.

[0054] Figure 3 This is a structural diagram of the Agent attention mechanism used in this invention.

[0055] Figure 4 This is a structural diagram of the MFGC module proposed in this invention.

[0056] Figure 5 This is a schematic diagram of the LionBatch optimization strategy proposed in this invention.

[0057] Figure 6 This is a structural diagram of the MFGC-Net model proposed in this invention.

[0058] Figure 7 This invention uses MFGC-Net to generate a heatmap of interest on garbage images.

[0059] Figure 8 The curves show a comparison of the training accuracy of the proposed MFGC-Net with mainstream networks.

[0060] Figure 9 This is a scatter plot comparing the training parameters and time of the proposed MFGC-Net with mainstream networks.

[0061] Figure 10 This is an example of garbage images collected in the natural environment according to the present invention.

[0062] Figure 11 This is an example of the recognition results of the MFGC-Net proposed in this invention on 135 types of garbage images. Detailed Implementation

[0063] The present invention will be further described below with reference to the accompanying drawings and specific embodiments.

[0064] This invention proposes an efficient waste sorting algorithm, combining... Figures 1 to 11 Detailed explanation is as follows:

[0065] like Figure 1 The flowchart shown is a presentation of the proposed waste classification algorithm based on an improved Cswin Transformer network. In this process, waste image data is first collected from natural scenes using a camera and obtained through internet searches, and the dataset is preprocessed. Next, the Cswin Transformer model is improved to enhance the accuracy of waste classification. Improvements include introducing an Agent Attention (AA) module to improve feature extraction capabilities; employing a LionBatch optimization strategy to improve model training speed and resource utilization efficiency; and using a label-smoothed cross-entropy loss function to improve the model's generalization performance. Then, the image data is input into the improved Cswin Transformer model at a fixed size of 224*224 for training and validation, and tested using a test set. Finally, the waste images to be classified are input into the model weights of the proposed automatic waste classification method, and the classification result is output through forward calculation.

[0066] like Figure 2 The diagram illustrates the Mixup data augmentation strategy used in this invention. Mixup data augmentation generates new training samples by linearly interpolating two images and their corresponding labels. Specifically, it mixes two images and their labels in the same proportion, thus forming new image-label pairs. This method not only increases the diversity of training data but also improves the model's generalization ability, reduces overfitting, and enhances the model's resistance to noise and adversarial examples.

[0067] like Figure 3 The diagram shows the structure of the Agent attention mechanism used in this 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 proxy tokens that first aggregate information from key-value pairs and then broadcast it back to the query token. Since the number of proxy tokens can be designed to be much smaller than the number of query tokens, the Agent attention mechanism significantly reduces computational complexity while maintaining global context modeling capabilities.

[0068] like Figure 4 This is a structural diagram of the MFGC module proposed in this invention. The MFGC module is equipped with... Figure 3The module employs an Agent Self-Attention (AA) mechanism to optimize information processing. Layer Normalization (LN) is used in the initial and middle sections to standardize the mean and variance of the input layer. Between the two LN stages, the Agent Self-Attention (AA) mechanism is integrated. This mechanism optimizes attention computation by introducing agent tokens, reducing direct computational complexity and improving both efficiency and accuracy of information processing. Following AA, the module also uses a Multilayer Perceptron (MLP) consisting of several fully connected layers with nonlinear activation functions embedded between them. The MFGC Block, incorporating the Agent Attention mechanism, demonstrates excellent computational efficiency and fast processing, making it suitable for various application scenarios.

[0069] like Figure 5 This diagram illustrates the LionBatch optimization strategy proposed in this invention. Specifically, LionBatch tracks only momentum during model training and calculates updates through symbolic operations, thereby reducing memory overhead and ensuring consistency of update magnitude across all dimensions. Furthermore, LionBatch implements dynamic pruning, allowing adjustments to pruning decisions based on real-time data performance during training, thus providing more granular control over the training process. Through this dynamic and unbiased pruning method, LionBatch can maintain model performance while reducing training costs, achieving lossless training acceleration.

[0070] This invention proposes the MFGC-Net network based on the Cswin Transformer. For example... Figure 6 The diagram shows the structure of the MFGC-Net model proposed in this invention. MFGC-Net utilizes 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, each consisting of multiple CSWin modules. These blocks use a cross-shaped window self-attention mechanism to process image data, suitable for capturing local image features and their spatial correlations. The final layer employs the MFGC module, which replaces the traditional cross-shaped window self-attention mechanism of the CSWin module with an Agent self-attention mechanism. Through its innovative structural design, MFGC-Net effectively improves the depth and breadth of feature processing, enhances the model's expressive power, and optimizes computational efficiency.

[0071] 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. CswinTransformer was used as the baseline network, and Agent attention, Lion optimizer, and InfoBatch pruning were sequentially introduced to optimize and improve CswinTransformer. The ablation experiment results are shown in Table 1. The Top-1 accuracies achieved by each improvement strategy reached 93.53%, 94.04%, and 93.52%, respectively, all exceeding those of CswinTransformer. Finally, the MFGC-Net model proposed by combining all improvement strategies achieved a Top-1 accuracy of 94.35% with fewer parameters and lower time complexity than CswinTransformer, representing a 1.85% improvement over CswinTransformer.

[0072] Table 1: Ablation Experiment

[0073]

[0074] like Figure 7 The figure shows the attention heatmap of the proposed MFGC-Net model on a garbage image. As can be seen from the figure, the MFGC-Net model effectively suppresses the influence of noise information (background, pebbles, branches, etc.), improving both the coverage and attention level of the target region, and significantly enhancing the global (outline and texture) attention to garbage targets. These results demonstrate that the proposed MFGC-Net can effectively calibrate the model's attention to targets, accurately locating and identifying garbage targets in complex scenes. This also indirectly proves the model's strong generalization performance in application.

[0075] To verify the superiority of this invention over other advanced classification algorithms, comparative experiments were added, and the results are shown in Tables 2, 3, and 4. The MFGC-Net model of this invention achieves the highest Top-1 accuracy, reaching 98.89% on the GarbageClassification dataset, 96.43% on the TrashNet dataset, and 94.35% on the self-built MixTrash dataset, with a parameter count of 43.18M. Compared to other advanced classification algorithms, it demonstrates superior classification performance, achieving a trade-off between classification accuracy and 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 a comparison curve of the training accuracy of the proposed MFGC-Net and mainstream networks. As can be seen from the figure, the Top1 accuracy curve of MFGC-Net rises steadily and converges rapidly until it tends to fit, and the final Top1 accuracy value is better than other models.

[0083] like Figure 9 The image shows a scatter plot comparing the training parameters and training time of the proposed MFGC-Net with mainstream networks. As can be seen from the figure, MFGC-Net performs exceptionally well, standing out with the highest Top-1 accuracy and moderate training time. Under the same parameter conditions, MFGC-Net's training time is significantly lower than other models, while its accuracy is higher, demonstrating superior classification performance and efficient training.

[0084] The following is combined with Figure 10 and Figure 11 Here is an application example:

[0085] like Figure 10 The image shown is an example of garbage images in a natural scene obtained by the image acquisition module. This image set contains 135 categories of household waste images, including apple cores, banana peels, batteries, books, button batteries, cigarette butts, lunch boxes, pencils, plastic bottles, remote controls, waste paper, watermelon rinds, etc. To verify the robustness of the proposed method in real-world scenarios, the garbage images (a) and (b) to be classified are input into the weights of the trained improved Cswin Transformer model, and the classification results are calculated and visualized.

[0086] Classification results as follows Figure 11 As shown in the image, all types of garbage can be effectively classified, which has practical application significance.

Claims

1. A waste sorting method based on an improved Cswin Transformer model, characterized in that, Includes the following steps: a. First, a dataset of junk images is created by capturing images in natural scenes using cameras and by searching the internet. The dataset was preprocessed to obtain a new dataset of garbage images. ; During preprocessing, each image Appropriate adjustments and enhancements were made to ensure image clarity and effective feature extraction; b. Construct a garbage classification model based on an improved Cswin Transformer. The improvement method includes introducing an Agent attention module into the feature fusion network to enhance the model's feature extraction capability. The Agent attention module consists of two soft attention mechanisms, Softmax, responsible for Agent aggregation and Agent broadcasting respectively, thereby optimizing the attention calibration process of the feature map. Specifically, the image data from step a... Perform a linear transformation to simplify the attention weight matrix , obtain the query vector Key vector Sum value vector The calculation process is as follows: , , ,in It is a query The weight matrix, Is a key The weight matrix, It is worth The weight matrix is ​​then calculated; the Agent attention is fused with the output of the soft attention mechanism, and the calculation process is as follows: First, the Softmax attention... Represented as ; Then introduce the proxy tag. Replace the original query And in the new query ,key Sum Attention is performed between the values ​​to aggregate the Agent's aggregated agent features from all values. The calculation process is as follows: Then query the matrix The second attention calculation utilizes As a key, As a value, global information about the proxy features is broadcast to each query tag and the final output is obtained. The calculation process is as follows: The newly defined proxy Essentially serving as a query The proxy, from the key Sum Aggregate global information in the middle and then broadcast it back. Maintaining global context modeling capabilities; to better utilize location information, Agent attention... A carefully designed agent bias has been added, calculated as follows: ,in It's a deviation. It uses depthwise separable convolution, which reduces model complexity while maintaining performance of the attention mechanism; the LionBatch optimization strategy is used during the training phase to improve model training speed and resource utilization efficiency. During the training phase, the label-smooth cross-entropy loss function is used to improve the model's generalization performance; c. The preprocessed garbage image data is fed into the improved Cswin Transformer model for training and validation, and tested using a test set. The final performance of the model is evaluated through five evaluation metrics. 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 waste sorting method based on the improved Cswin Transformer model as described in claim 1, characterized in that, The image preprocessing method in step a involves processing the image input to the network. Perform size normalization processing to scale the image size to 224*224 pixels; Data augmentation is achieved by performing mirroring, flipping, translation, shearing, affine transformation, and rotation operations on the dataset. The dataset is randomly divided into training and testing sets in an 8:2 ratio. The Mixup data augmentation algorithm is used to perform linear interpolation on every two garbage images input to the network, mixing the two images proportionally and their corresponding labels to form a new image dataset. The calculation formula for Mixup data augmentation is shown below: ,in These are two images randomly selected from the training set. It is the corresponding unique hot tag. The hyperparameters are calculated using the Beta distribution, and new samples are constructed based on prior knowledge. .

3. The waste sorting method based on the improved Cswin Transformer model as described in claim 1, characterized in that, The LionBatch optimization strategy in step b only tracks momentum during model training and calculates updates through symbolic operations, thereby reducing memory overhead and ensuring consistency of update magnitude across all dimensions. During training, it adjusts pruning decisions based on real-time data performance, reducing training on useless samples and achieving lossless training acceleration. The calculation process of the LionBatch optimization strategy is as follows: First, the average loss of the entire dataset is calculated. , can be represented as ,in Indicates the number of samples. Represents the loss function. Indicates the model input, This indicates the model output, for values ​​less than the average loss. The data samples will be pruned according to a certain probability, which can be represented as: ,in Indicates the current training round. Indicates the current data sample. These are the hyperparameters for probabilistic pruning. Due to the reduced sample size, the gradient of the entire dataset changes, leading to inconsistencies with the expected gradient of the original dataset. To address this issue, the gradient is reduced to less than the average loss. The gradient of the data sample, after rescaling, can be expressed as: ,in This represents the gradient of the current data sample. It's the learning rate. It is the loss function relative to the parameters The gradient is then used; then, optimization training is performed on the pruned subset of data, using the gradient and the previous momentum to calculate the current update momentum. The function specifies the update direction to update the model parameters, which can be represented as: , ,in Indicates momentum. Represents the momentum factor. Represents the gradient. Indicates the current model training parameters. It is a hyperparameter for calculating momentum; repeat the above process to gradually optimize the model parameters until the expected performance index is achieved.

4. The waste sorting method based on the improved Cswin Transformer model as described in claim 1, characterized in that, The label smoothing cross-entropy loss function in step b introduces a smoothing coefficient to make the label distribution smoother, reduce sensitivity to label noise, and improve the model's generalization ability. The calculation process of the label smoothing cross-entropy loss function is as follows: First, the labels are smoothed. For each true label... Generate a smooth label , can be represented as: ,in It is the smoothing coefficient. It is the number of categories; then the Softmax function is used to calculate the model's predicted probabilities. , is represented as: ,in, It is the model's output, combined with smoothed labels. With predicted probability Calculate cross-entropy loss The loss weights are dynamically adjusted based on the sample difficulty, and finally, the label smooth cross-entropy loss function can be expressed as: , in It is a dynamic weighting factor that is dynamically adjusted based on the difficulty of the samples, thereby increasing attention to difficult samples.

5. The waste sorting method based on the improved Cswin Transformer model as described in claim 1, characterized in that, The training, validation, and testing method of the improved Cswin Transformer model in step c involves inputting the preprocessed garbage dataset into the improved network for training over 300 iteration cycles. After each iteration, the performance of the model generated in each iteration is verified using a test set. After 300 training and testing iterations, the optimal model is obtained. The optimal model obtained from the final training is then tested using a test set. The model performance is evaluated by the number of parameters, Top-1 accuracy, precision, recall, and F1 score to verify the effectiveness and sophistication of the model.

6. The waste sorting method based on the improved Cswin Transformer model as described in claim 1, characterized in that, In step d, the method for classifying garbage images according to the present invention adaptively scales the garbage image to be classified to a resolution of 224*224 pixels and loads it into the model of the present invention. Then, the image is input into the model with weights, and each layer of the model uses these weights to extract features from the image and identify key features in the image. Next, the features are processed through a fully connected layer for final calculation, converting the features into class probabilities. Finally, the model selects the class with the highest probability as the prediction result, that is, it considers the input garbage image to belong to that class.