Garbage classification method based on GMama model

By introducing the lightweight scanning mechanism and core scanning mechanism of the GMamba model, combined with the mixed loss function, the efficiency and accuracy of garbage classification on resource-constrained devices are solved, and efficient and accurate garbage image recognition is achieved.

CN120431408AActive Publication Date: 2025-08-05ZHEJIANG FORESTRY UNIVERSITY

Patent Information

Application Number
CN202510889185.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-30
Publication Date
2025-08-05
Estimated Expiration
2045-06-30

AI Technical Summary

Technical Problem

Existing garbage classification methods are difficult to achieve efficient and lightweight garbage classification on resource-constrained equipment, especially in limited data and complex contexts, and the classification accuracy is insufficient, and the problem of category imbalance is serious.

Method used

The garbage classification method based on the GMamba model is adopted, and by introducing a lightweight scanning mechanism LSM and a core scanning mechanism CSM, combined with mixed loss functions, it optimizes feature extraction and long-range dependency modeling, reduces the computational complexity and improves classification performance.

Benefits of technology

Efficient and accurate garbage classification is realized on resource-constrained equipment, which significantly improves classification accuracy and efficiency, and adapts to garbage image recognition in complex scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120431408A_ABST
    Figure CN120431408A_ABST
Patent Text Reader

Abstract

The invention discloses a garbage classification method based on a GMama model, and the method comprises the steps: obtaining garbage images through a camera and Internet search, and carrying out the data enhancement preprocessing; a lightweight module GML and a core module GMC are introduced into the GMama model, and the extraction capability of local and long-range spatial dependence features is enhanced through a lightweight scanning mechanism LSM and a core scanning mechanism CSM; dynamically optimizing the class imbalance problem by adopting a mixed loss function and combining focus loss and cross entropy loss; inputting the preprocessed image data into a GMama model for training and testing to obtain an optimal model; and finally, inputting a to-be-classified image into the optimal model, and outputting a classification result. According to the GMama-based garbage automatic identification method provided by the invention, efficient and accurate garbage classification is realized through lightweight design and high accuracy, and the GMama-based garbage automatic identification method is particularly suitable for resource-constrained equipment and has a wide application prospect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of computer vision and image classification, and relates to a lightweight garbage image classification method based on an improved Mamba architecture, which is suitable for efficient garbage classification on resource-constrained devices. Background Art

[0002] With the acceleration of urbanization and the rapid growth of domestic waste, waste sorting has become a vital component of environmental protection and resource recycling. Traditional waste sorting methods, which primarily rely on manual sorting or simple mechanical equipment, are inefficient and unable to cope with the diversity and complexity of waste types. In recent years, the rapid development of deep learning technology has significantly improved the efficiency of waste sorting. In particular, methods based on convolutional neural networks (CNNs) and Transformer models have significantly improved classification accuracy by automatically extracting image features. However, these methods face numerous challenges in practical applications, limiting their performance and scalability in complex scenarios. The demand for efficient and lightweight waste sorting algorithms is increasingly urgent, especially on resource-constrained devices. Therefore, developing an automatic waste sorting method that balances classification accuracy and computational efficiency is of great practical significance.

[0003] The application of deep learning in the field of garbage classification mainly relies on the powerful feature extraction capabilities of CNN and Transformer models. Traditional garbage classification algorithms usually use manual feature extraction combined with classic machine learning classifiers, but these methods have poor generalization capabilities and cannot cope with the diversity and complex backgrounds of garbage images. In contrast, CNN automatically learns image features through multi-layer convolution and pooling operations, significantly improving classification accuracy. In recent years, Transformer models have also been introduced to garbage classification tasks due to their ability to model long-range dependencies. However, CNN and Transformer models usually have a large number of parameters and high computational complexity, making them difficult to deploy efficiently on resource-constrained devices. In addition, the Mamba architecture based on state-space models has attracted attention for its efficient sequence modeling capabilities, but its application in the field of garbage classification is still limited, and related research has not fully utilized its lightweight potential.

[0004] The task of garbage classification faces many challenges in the face of limited data and complex background environments. First, an ideal deep learning model requires a large amount of labeled data support, but in real-world scenarios, garbage image datasets are often limited in size, especially with insufficient samples of rare categories, which makes the model prone to overfitting and reduced generalization ability. Secondly, garbage images are often accompanied by complex backgrounds and similar appearances. Existing models are insufficient in capturing fine-grained features and long-range spatial dependencies, affecting classification accuracy. In addition, the problem of class imbalance further exacerbates the difficulty of model optimization, and the classification performance of rare categories is generally low. Therefore, a lightweight and efficient garbage classification algorithm is designed that not only meets the needs of resource-constrained devices, but also improves classification performance in complex scenarios, and has important research and application value. Summary of the Invention

[0005] The purpose of this invention is to provide a garbage classification method based on deep learning technology, breaking through the limitations of existing research in the field of garbage classification and effectively improving the accuracy of garbage classification.

[0006] The present invention provides a GMamba-based automatic garbage classification method, comprising the following steps:

[0007] (1) First, we collect garbage image datasets in natural scenes through camera capture and Internet search, and then preprocess the datasets;

[0008] (2) In response to the challenges of garbage classification and the lack of research in this field, a garbage classification model based on GMamba is proposed. The improvement methods include introducing the LSM lightweight scanning mechanism to improve the efficiency of feature extraction; introducing the CSM core scanning mechanism to maintain accuracy while reducing computational complexity; and using a hybrid loss function in the training stage, combining focal loss and cross entropy loss to optimize the class imbalance problem.

[0009] (3) The preprocessed garbage image dataset is fed into the GMamba model for training and validation, and the model performance is evaluated using the validation set. The evaluation metrics include Top-1 accuracy, precision, recall, F1 score, number of parameters, and training time.

[0010] (4) Input the garbage image to be classified into the GMamba model trained in step c above, and output the classification result through forward calculation.

[0011] Furthermore, the pretreatment method described in step 1 is specifically as follows:

[0012] (1.1) Before the experiment, first set the corresponding category for the garbage target in each image; The images were normalized to 224*224 pixels. The data was then amplified by mirroring, flipping, translating, cropping, and affine transformation. Finally, the dataset was randomly divided 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]

[0016] in are two junk images randomly selected from the training set, is the unique hot label of each sample category. It is a hyperparameter generated by Beta distribution calculation, and a new sample is constructed through prior knowledge. .

[0017] Furthermore, the garbage classification method based on the GMamba model described in step 2 is specifically as follows:

[0018] (2.1) Introduce the LSM lightweight scanning mechanism into the network to reduce the amount of computation while maintaining the global receptive field; the specific method is to input garbage images Perform hole sampling in four directions and input feature maps at a fixed step size Perform interval sampling and decompose it into multiple smaller blocks; the calculation process of each block index of interval sampling is as follows:

[0019]

[0020] in , is the spatial coordinate of the input feature map, and They are input feature maps The height and width, is a fixed step size, Indicates rounding down, using sin and cos functions to introduce periodic offsets to ensure a more even distribution of sampling points. is the index space coordinate of each block sampled at intervals; then the sampled block It can be expressed as:

[0021]

[0022] in , is the input feature map The number of channels; then for each sampled block Apply the SSM module to extract local features. The calculation process is as follows:

[0023]

[0024]

[0025]

[0026]

[0027]

[0028] in, 、 、 It is a fixed learnable parameter, which is optimized through model training and initialized with a normal distribution. 、 、 is a fixed learnable bias matrix, initialized to zero or small random values, and Represents the activation function, ensuring that the elements of the matrix calculation remain positive, It's time The hidden state of is the previous hidden state, the state transition matrix , input matrix and the output matrix According to the input Dynamically generated at each time step, It is the processed local feature map output; finally, the local features of all channels are merged into a global feature map. The calculation process is as follows:

[0029]

[0030] in, represents the feature map concatenation operation, is the final generated global feature map.

[0031] (2.2) The CSM lightweight scanning mechanism is introduced into the network, which adopts multi-directional scanning paths and comprehensive scanning mechanisms to bridge the gap between one-dimensional sequence scanning and two-dimensional plane traversal, thereby efficiently capturing long-range dependencies and contextual information in the image; the CSM core scanning mechanism includes two main steps: selective cross scanning and cross merging. The specific method is to Expanded into multiple one-dimensional sequences for selective scanning, the calculation process is as follows:

[0032]

[0033] in represents the feature map flattening operation, Indicates the direction of scanning, which has four specific values: row forward, row reverse, column forward, and column reverse. Indicates the Sequence of directions; Sequence of each scanning path The four SSM modules process the sequences in four directions in parallel to obtain four sets of enhanced sequences. , the calculation process is as follows:

[0034]

[0035]

[0036]

[0037]

[0038]

[0039] in, 、 、 It is a fixed learnable parameter, which is optimized through model training and initialized with a normal distribution. 、 、 is a fixed learnable bias matrix, initialized to zero or small random values, It's time The hidden state of is the previous hidden state, the state transition matrix , input matrix and the output matrix According to the input Dynamically generated at each time step; then the four directions Deserialize and reconstruct each sequence into a two-dimensional feature map , a new feature map is generated for each direction , and then fuse the feature maps in the four directions. The calculation process is as follows:

[0040]

[0041]

[0042]

[0043] in Represents the feature graph deserialization operation, Indicates the operation of adjusting the feature map dimension to meet the requirements of subsequent matrix calculations. Represents the fused global feature map.

[0044] (2.3) A hybrid loss function is introduced to learn and optimize difficult samples and improve the generalization ability of the model; it combines the focus loss and cross entropy loss in a ratio of 8:2. By dynamically adjusting the sample weights and measuring the difference between the model prediction and the true label, it reduces the focus on easy-to-classify samples and enhances the modeling ability of difficult-to-classify samples, ensuring the stability of the overall classification performance; the hybrid loss function The calculation process is as follows:

[0045]

[0046] in represents the focal loss function, Represents the cross entropy loss function; the focal loss function is for each sample, the model outputs the predicted probability , represents the probability that the sample belongs to the true category, and then dynamically adjusts the loss weight to make the difficult-to-classify samples ( Smaller) results in a higher loss value, and the calculation process is as follows:

[0047]

[0048] in is the weight factor used to adjust the weights of positive and negative samples, is a modulation factor that controls the weight difference between difficult and easy samples, Represents the difference between the predicted probability and the true label, and finally the focus loss is obtained by combining them; the cross entropy loss penalizes the deviation between the predicted probability and the true label, prompting the model to improve the predicted probability of the correct category. The calculation process is as follows:

[0049]

[0050] in Represents the one-hot encoding of the true label of the sample, Represents the model for category The predicted probability is finally obtained by cross entropy loss; the focus loss and cross entropy loss are mixed at 8: 2 to obtain the final mixed loss function It can be expressed as:

[0051]

[0052] Furthermore, the training and verification method of the GMamba model described in step 3 is specifically as follows:

[0053] (3.1) The garbage dataset preprocessed in step 1 Input the data into the GMamba model in step 2 for training. Set a 300-round iteration cycle. After each iteration, use the validation set to verify the performance of the model generated by each iteration. Save the optimal model weight file through comparison.

[0054] (3.2) After the training iterations are completed, the optimal model obtained from the final training in (3.1) is tested on the test set. The performance of the improved model is evaluated by the model's Top-1 accuracy, precision, recall rate, F1 score, number of parameters, and training time to verify the effectiveness and advancement of the model.

[0055] Furthermore, the method for classifying junk images using the improved model in step 4 is as follows: first, the junk images to be classified are Input into the model and load into (3.1) to get the optimal model weight, and finally identify the correct garbage category through prediction.

[0056] The present invention has the following characteristics:

[0057] 1. The GMamba model integrates lightweight and core modules into a four-layer pyramid structure. It combines dynamic selective scanning with a hybrid loss function to achieve efficient and accurate spam image classification. Compared to traditional CNN and Transformer models, GMamba reduces the number of parameters while shortening training time by approximately half, making it suitable for efficient deployment on resource-constrained devices.

[0058] 2. This paper addresses the computational burden of large-scale spam image datasets by introducing a lightweight scanning mechanism (LSM). LSM simplifies the global feature extraction process through hole sampling and feature recombination, reducing computational complexity. Furthermore, combined with deep convolution and a compressed excitation mechanism, it effectively focuses on key areas of spam images, improving classification accuracy and efficiency.

[0059] 3. To address the diversity of junk images and the need for long-range dependency modeling, this paper introduces a core scanning mechanism, the CSM. CSM employs four-directional selective scanning and parallel processing of multi-directional sequences using a state-space model. This enhances fine-grained feature extraction and long-range spatial dependency modeling, significantly improving classification performance in complex backgrounds.

[0060] 4. Aiming at the problem of category imbalance in garbage classification tasks, this paper adopts a hybrid loss function, combining Focus loss and cross entropy loss, dynamically adjusting the weights of difficult-to-classify samples and optimizing the classification performance of more difficult samples. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 This is a flow chart of the garbage classification algorithm proposed in this invention.

[0062] Figure 2 This is the Mixup data enhancement strategy used in the present invention.

[0063] Figure 3 This is a structural diagram scanned by LSM lightweight scanning used in the present invention.

[0064] Figure 4 This is the structural diagram of the GML module proposed in the present invention.

[0065] Figure 5 This is a structural diagram of the CSM core scan used in the present invention.

[0066] Figure 6 This is a structural diagram of the GMC module proposed in the present invention.

[0067] Figure 7 This is a structural diagram of the GMamba model proposed in the present invention.

[0068] Figure 8 This is a comparison curve of the training accuracy of GMamba proposed in this invention and mainstream networks.

[0069] Figure 9 A scatter plot comparing the training parameters and time of GMamba proposed in this invention and mainstream networks.

[0070] Figure 10 This is an example of garbage images collected by the present invention in a natural environment.

[0071] Figure 11 This is an example of the recognition results of GMamba proposed in this invention on 135 types of junk images. DETAILED DESCRIPTION

[0072] The present invention is further described below with reference to the accompanying drawings and specific implementation examples.

[0073] This invention proposes an efficient garbage classification algorithm, combined with Figures 1 to 11 The detailed instructions are as follows:

[0074] like Figure 1The figure shows a flowchart of the garbage classification algorithm based on the GMamba model proposed by the present invention. 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 GMamba model is used to improve the accuracy of the garbage classification task. The method of the GMamba model includes introducing a lightweight scanning mechanism LSM to reduce computational redundancy and efficiently extract local and global features; introducing a core scanning mechanism CSM to enhance long-range dependency modeling through four-way selective scanning; and using a hybrid loss function to optimize category imbalance. Then, the image data is input into the GMamba model with a fixed size of 224*224 for training and verification, and is centrally verified using a verification set. Finally, the garbage image to be classified is input into the GMamba model weights of the garbage automatic classification method proposed by the present invention, and the classification result is output through forward calculation.

[0075] like Figure 2 The figure shows the Mixup data augmentation strategy used in this paper. Mixup data augmentation generates new training samples by linearly interpolating two images and their corresponding labels. Specifically, it mixes the two images and 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 model's generalization ability, reduces overfitting, and enhances the model's resistance to noise.

[0076] like Figure 3 The figure shows an example of the LSM lightweight scanning used in the present invention. LSM uses hole sampling and feature recombination technology to efficiently capture the salient features of junk images to reduce computational complexity and improve classification performance. Specifically, LSM first divides the input image into patches of fixed size, each patch representing the visual features of a local area. Subsequently, LSM rearranges these patches into multiple spatial subsequences, such as the orange subsequence {1,3,11,13}, the green subsequence {6,8,14,16}, the blue subsequence {2,4,10,12} and the pink subsequence {5,7,9,15}, each of which has a certain non-local perception range. These spatial subsequences are respectively sent to the model for modeling. After modeling, the output features of each subsequence are reorganized according to the original spatial layout to generate a hybrid feature map that integrates global contextual semantics, and the local and global features are fused through a compression excitation mechanism to maintain the modeling capability of key features, thereby achieving efficient feature extraction and classification on resource-constrained devices.

[0077] like Figure 4This is the structural diagram of the GML module proposed in the present invention. The GML module contains two parallel branches, one for local feature extraction and the other for global semantic modeling. In the local branch, the GML module uses DW 3×3 convolution to extract local spatial structural features, and combines BatchNorm with 1×1 convolution to further integrate information between channels to obtain a local feature map. In the global branch, the GML module introduces a lightweight scanning mechanism LSM to generate a global feature map. The local and global feature maps are sent to the Squeeze-Excitation module for fusion. The GML module adaptively adjusts the importance of different channels through the channel attention mechanism, and performs well in terms of computational efficiency and classification accuracy. It is particularly suitable for garbage classification tasks on resource-constrained devices.

[0078] like Figure 5 Shown is an example diagram of the CSM core scanning used in the present invention. CSM efficiently captures the long-range spatial dependency features of garbage images through four-way selective scanning and state-space model processing to improve classification performance. Specifically, CSM first flattens the input feature map in four directions to generate four sequences of interleaved mixed image blocks (4N). Each set of sequences is processed in parallel by the SSM module to extract global context information. Subsequently, CSM deserializes the processed sequence, reconstructs it into a two-dimensional feature map, and fuses multi-directional features through residual connections and layer normalization to maintain the ability to model key features. The parallel scanning design of CSM can achieve efficient feature extraction and garbage classification on resource-constrained devices.

[0079] like Figure 6 This is a structural diagram of the GMC module proposed in the present invention. The GMC module uses residual connections and layer normalization LN through CSM Block and feedforward network FFN to maintain training stability. In the CSM Block, the input feature first increases its dimension through a linear layer, then passes through a depth-wise separable convolution DWConv to extract the local spatial structure, and then enhances the expression ability through the SiLU nonlinear activation function. The input is then passed to the CSM module, which rearranges the image patch across scales and constructs multiple groups of heterogeneous spatial subsequences in the spatial dimension, so that the model can perceive the contextual dependencies of different scales and different positions. After the mixing is completed, the feature output is a fusion of multi-scale context-aware feature representations through linear projection.

[0080] like Figure 7The figure shows the structural diagram of the GMamba model proposed in the present invention. The GMamba model adopts a four-layer pyramid structure to efficiently process garbage image features and optimize classification performance. The first and fourth layers of the network are composed of lightweight modules GML. Each layer uses hole sampling and feature reorganization through the lightweight scanning mechanism LSM to capture the local features and global context of the image, significantly reducing computational redundancy. The two middle layers use the core module GMC. The GMC module replaces the traditional attention mechanism with the core scanning mechanism CSM, and enhances the long-range spatial dependency modeling capability based on four-way selective scanning and state space model SSM. GMamba significantly improves the depth and breadth of feature expression and optimizes computational efficiency through innovative lightweight design and efficient feature processing. It is particularly suitable for garbage classification tasks on resource-constrained devices.

[0081] To demonstrate the superiority of our present invention over other advanced classification algorithms, we conducted comparative experiments, the results of which are shown in Tables 1 and 2. Our GMamba model demonstrated superior classification performance, achieving a Top-1 accuracy of 92.75% on the Huawei Cloud garbage classification dataset and 92.58% on the MixTrash dataset, with only 17.18M parameters. Compared to other advanced classification algorithms, the GMamba model not only significantly outperforms other algorithms in classification accuracy, but also achieves an excellent trade-off between classification speed and accuracy through its lightweight design.

[0082] Table 1: Performance comparison of various models on the Huawei Cloud garbage classification dataset

[0083] Model Top 1 accuracy (%) Accuracy (%) Recall rate (%) F1 score (%) Parameter quantity (M) ResNet 76.53 75.89 76.32 76.12 23.50 EfficientNet 80.37 80.29 80.53 80.27 17.55 ViT 85.59 85.47 85.47 85.42 22.08 Swin Transformer 88.25 88.46 88.47 88.32 48.94 ViM 91.50 91.52 91.48 91.45 28.24 EfficientViM 84.55 84.46 84.33 84.27 19.68 MobileMamba 91.13 90.93 90.88 90.85 17.58 VMamba 93.12 93.01 92.97 92.99 31.42 EffcientVMamba 91.84 91.62 91.54 91.42 12.37 GMamba (this invention) <![CDATA[ 92.75 ]]> <![CDATA[ 92.58 ]]> <![CDATA[ 92.53 ]]> <![CDATA[ 92.42 ]]> <![CDATA[ 17.18 ]]>

[0084] Table 2: Performance comparison of various models on the MixTrash dataset

[0085] Model Top 1 accuracy (%) Accuracy (%) Recall rate (%) F1 score (%) Parameter quantity (M) ResNet 86.48 85.69 84.89 84.92 23.50 EfficientNet 88.87 88.59 88.27 88.07 17.55 ViT 90.06 89.88 89.66 89.62 22.08 Swin Transformer 89.66 88.46 88.47 88.32 48.94 ViM 90.68 90.62 90.48 90.43 28.24 EfficientViM 85.63 85.46 85.33 85.19 19.68 MobileMamba 91.37 90.93 90.66 90.48 17.58 VMamba 93.18 93.12 92.87 92.81 31.42 EffcientVMamba 91.24 91.03 90.88 90.82 12.37 GMamba (this invention) <![CDATA[ 92.58 ]]> <![CDATA[ 92.29 ]]> <![CDATA[ 92.14 ]]> <![CDATA[ 92.02 ]]> <![CDATA[ 17.18 ]]>

[0086] like Figure 8The figure shows a training accuracy comparison curve between the GMamba model proposed in this invention and mainstream networks. The GMamba model showed rapid performance improvement in the early stages of training, with its accuracy rising rapidly within the first 50 epochs, significantly outperforming typical Transformer architecture models such as ViT_small, SwinTransformer_small, and ViM_small. As the training rounds progressed, GMamba, leveraging its structural design advantages, continued to steadily improve its accuracy, ultimately achieving a Top-1 accuracy of over 92% within approximately 300 epochs, leading all compared models and second only to or approaching the performance of VMamba_tiny. In addition, compared to lightweight models such as EfficientNetB4 and EfficientViM_small, GMamba not only achieved significant improvements in accuracy, but also maintained good convergence stability, without significant performance fluctuations.

[0087] like Figure 9 Shown is a scatter plot comparing the training parameter count and time of GMamba, proposed in the present invention, and mainstream networks. Each dot in the figure represents a model, with the horizontal axis representing the time required to complete training and the vertical axis representing the model's final accuracy. The bubble colors, from light to dark, correspond to parameters from large to small. GMamba requires relatively short training time, yet achieves an accuracy of approximately 92.8%, leading the way among all models. Furthermore, GMamba's parameter size is moderate, far smaller than that of large models such as SwinTransformer, demonstrating higher parameter efficiency. In contrast, although SwinTransformer has a large number of parameters and takes longer to train, its accuracy is slightly lower than GMamba, demonstrating an imbalance between efficiency and performance. Furthermore, GMamba outperforms traditional visual backbone networks such as ViT, ViM, and ResNet, achieving a good trade-off between model lightweightness and accuracy. This demonstrates that GMamba can achieve excellent classification performance while maintaining a low computational cost, validating its potential and practical value as an efficient visual model.

[0088] The following combination Figure 10 and Figure 11 Here is an application case:

[0089] like Figure 10 The following are examples of garbage images in natural scenes obtained by the image acquisition module (a), (b), (c), and (d). The image set contains 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 proposed method has strong robustness in real scenes, Figure 10The junk images (a) and (b) to be classified are input into the trained GMamba model weights, and the classification results are visualized by calculation output.

[0090] The classification results are as follows Figure 11 As shown, Figure 10 In the example of garbage images (a) the recognition probability is 0.9742 and the category is classified as battery button, (b) the recognition probability is 0.9686 and the category is classified as cigarette butt. Figure 10 The junk image examples (a) and (b) can be effectively classified, which has practical application significance.

Claims

1. A garbage classification method based on the GMamba model, characterized in that: The steps include: a. Collect and preprocess the garbage image dataset. First, collect garbage images in natural scenes through the camera, and build the garbage image dataset by searching the Internet. , and the dataset Perform data preprocessing to obtain a new processed garbage image dataset ; During the preprocessing process, the dataset Each image in Perform size normalization, contrast adjustment, and data augmentation to optimize image clarity and enhance the effectiveness of feature extraction; b. Build a garbage classification model based on the GMamba model. Improvements include introducing a lightweight scanning mechanism (LSM) into the Mamba network and using a dynamic selective scanning mechanism to reduce redundant computation and improve feature extraction efficiency. The CSM core scanning mechanism is introduced to enhance spatial modeling capabilities through a four-way selective scanning mechanism while reducing computational complexity. A hybrid loss function is used in the training phase, combining focal loss and cross entropy loss to optimize the class imbalance problem and improve the generalization performance of the model; c. Input the preprocessed garbage image dataset into the GMamba model for training and validation. The optimal model weights are saved through iterative training, and the model performance is evaluated using the validation set. Evaluation metrics include Top-1 accuracy, precision, recall, F1 score, number of parameters, and training time. d. Input the garbage image to be classified into the GMamba model trained in step c and output the classification result through forward calculation.

2. The method according to claim 1, wherein: The method for collecting and preprocessing the garbage image dataset in step a specifically includes: For input garbage images Normalize the image size and scale it to a uniform 224*224 pixel resolution. Process the data using mirroring, flipping, translation, shearing, and affine transformations. Split the dataset into a training set and a validation set at a ratio of 8:

2. Use the Mixup data augmentation algorithm to perform linear interpolation on every two garbage images, proportionally mixing the images and their corresponding labels to generate new image data. The calculation formula for Mixup data augmentation is as follows: in are two junk images randomly selected from the training set, is the unique hot label corresponding to each sample category, It is a hyperparameter generated by Beta distribution calculation, and a new sample is constructed through prior knowledge. .

3. The method according to claim 1, wherein: The LSM lightweight scanning method based on the GMamba model in step b specifically includes: using a hole sampling and feature reorganization mechanism to reduce the amount of calculation while maintaining the global receptive field; the specific method is to input the garbage image in step a of claim 1 Perform hole sampling in four directions and input feature maps at a fixed step size Perform interval sampling and decompose it into multiple smaller blocks; the calculation process of each block index of interval sampling is as follows: in , is the spatial coordinate of the input feature map, and They are input feature maps The height and width, is a fixed step size, Indicates rounding down, using sin and cos functions to introduce periodic offsets to ensure a more even distribution of sampling points. is the index space coordinate of each block sampled at intervals; then the sampled block It can be expressed as: in , is the input feature map The number of channels; then for each sampled block Apply the SSM module to extract local features. The calculation process is as follows: in, 、 、 It is a fixed learnable parameter, which is optimized through model training and initialized with a normal distribution. 、 、 is a fixed learnable bias matrix, initialized to zero or small random values, and Represents the activation function, ensuring that the elements of the matrix calculation remain positive, It's time The hidden state of is the previous hidden state, the state transition matrix , input matrix and the output matrix According to the input Dynamically generated at each time step, It is the processed local feature map output; finally, the local features of all channels are merged into a global feature map. The calculation process is as follows: in, represents the feature map concatenation operation, is the final generated global feature map.

4. The method according to claim 1, wherein: The CSM lightweight scanning method based on the GMamba model in step b specifically includes: adopting a multi-directional scanning path and a comprehensive scanning mechanism to bridge the gap between one-dimensional sequence scanning and two-dimensional plane traversal, and efficiently capturing long-range dependencies and contextual information in the image; the CSM core scanning mechanism includes two main steps: selective cross-scanning and cross-merging. The specific method is as follows: for the input garbage image in step a of claim 1, Expanded into multiple one-dimensional sequences for selective scanning, the calculation process is as follows: in represents the feature map flattening operation, Indicates the direction of scanning, which has four specific values: row forward, row reverse, column forward, and column reverse. Indicates the Sequence of directions; Sequence of each scanning path The four SSM modules process the sequences in four directions in parallel to obtain four sets of enhanced sequences. , the calculation process is as follows: in, 、 、 It is a fixed learnable parameter, which is optimized through model training and initialized with a normal distribution. 、 、 is a fixed learnable bias matrix, initialized to zero or small random values, It's time The hidden state of is the previous hidden state, the state transition matrix , input matrix and the output matrix According to the input Dynamically generated at each time step; then the four directions Deserialize and reconstruct each sequence into a two-dimensional feature map , a new feature map is generated for each direction , and then fuse the feature maps in the four directions. The calculation process is as follows: in Represents the feature graph deserialization operation, Indicates the operation of adjusting the feature map dimension to meet the requirements of subsequent matrix calculations. Represents the fused global feature map.

5. The method according to claim 1, wherein: The hybrid loss function method combining focal loss and cross entropy loss in step b specifically includes: It combines focus loss and cross entropy loss in a ratio of 8:

2. By dynamically adjusting the sample weights and measuring the difference between the model prediction and the true label, it reduces the focus on easy-to-classify samples and enhances the modeling ability of difficult-to-classify samples, thus ensuring the stability of the overall classification performance. The calculation process is as follows: in represents the focal loss function, Represents the cross entropy loss function; the focal loss function is for each sample, the model outputs the predicted probability , represents the probability that the sample belongs to the true category, and then the loss weight is dynamically adjusted to make the difficult-to-classify samples obtain a higher loss value. The calculation process is as follows: in is the weight factor used to adjust the weights of positive and negative samples, is a modulation factor that controls the weight difference between difficult and easy samples, Represents the difference between the predicted probability and the true label, and finally the focus loss is obtained by combining them; the cross entropy loss penalizes the deviation between the predicted probability and the true label, prompting the model to improve the predicted probability of the correct category. The calculation process is as follows: in Represents the one-hot encoding of the true label of the sample, Represents the model for category The predicted probability is finally obtained by cross entropy loss; the focus loss and cross entropy loss are mixed at 8: 2 to obtain the final mixed loss function .

6. The method according to claim 1, wherein: The method for inputting the pre-processed garbage image dataset into the GMamba model training and verification method in step c specifically includes: The model was input into the GMamba model and trained for 300 iterations. After each iteration, the validation set was used to evaluate the performance of the model for each iteration, and the model weight with the highest Top-1 accuracy was saved. The validation set was used to perform a performance test on the optimal model obtained from the final training. The effectiveness and advancement of the model were evaluated through the model's Top-1 accuracy, precision, recall rate, F1 score, number of parameters, and training time indicators.

7. The method according to claim 1, wherein: The method of inputting the garbage image to be classified into the GMamba model trained in step c in step d specifically includes: Adaptively scale the image to a resolution of 224*224 pixels and input it into the GMamba model of the present invention; then The input is fed into the model with the optimal weights. Each layer of the model uses these weights to extract the key features of the junk image. The extracted features are processed by the fully connected layer and converted into category probabilities. Finally, the category with the highest probability is selected as the prediction result, which means that the input junk image is considered to be belongs to this category.

Citation Information

Patent Citations

  • Lightweight agricultural pest detection method and system

    CN116994243A

  • Garbage detection method in complex scene based on improved YOLOv8 model

    CN117710771A

  • Road garbage detection method based on hybrid scanning Vision Mama model

    CN118968255A

  • Garbage classification method based on improved Cswin Transform model

    CN119068241A

Cited By

  • Assembly precision prediction method based on PointNet + + improved network

    CN120823449A