RecycleNet
Effective trash classification model using only a small number of annotated images.
https://github.com/sangminwoo/RecycleNet
Category: Industrial Ecology
Sub Category: Circular Economy and Waste
Keywords
attention recyclenet trash-classification trashnet
Last synced: about 20 hours ago
JSON representation
Repository metadata
Attentional Learning of Trash Classification
- Host: GitHub
- URL: https://github.com/sangminwoo/RecycleNet
- Owner: sangminwoo
- License: mit
- Created: 2018-10-26T03:51:23.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-04T16:15:02.000Z (over 4 years ago)
- Last Synced: 2025-04-20T09:44:49.667Z (8 days ago)
- Topics: attention, recyclenet, trash-classification, trashnet
- Language: Python
- Homepage:
- Size: 358 MB
- Stars: 40
- Watchers: 2
- Forks: 10
- Open Issues: 1
- Releases: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
README.md
RecycleNet
In the era of mass production and mass consumption, trash disposal has become an important national issue. With this trend, the social and economic importance of trash collection and reusing is increasing. An alternative is to allow the machine to classify automatically once the user discharge the trash regardless of the material.
Using two methods for creating an effective trash classification model using only a small number of annotated trash images(2527).
1) Transfer learning: Using ImageNet pre-trained model
2) Effective feature learning with attention module
To demonstrate that the proposed methodologies were effective, a large number of ablation studies were conducted and were more effective than state-of-the-art attention modules.
- Backbone Network: ResNet
- Attention Module: RecycleNet
Requirements
Install all the python dependencies using pip:
$ git clone https://github.com/sangminwoo/RecycleNet.git
$ cd RecycleNet
$ pip install -r requirements.txt
- PyTorch is not inside. Please go to official website.
https://github.com/garythung/trashnet)
Data Preparation(TrashNet[1]:-
Total: 2527 (contains 6 classes)
- Glass 501
- Paper 594
- Cardboard 403
- Plastic 482
- Metal 410
- Non-recyclable Trash 137
-
Train/Val/Test set: 70/13/17
-
Data Augmentation
-
⚠️ You may use additional_dataset.zip as another version of dataset. But if you use both of them on training phase, it will increase intra-class variance thus will leads to decrease of accuracy. Maybe you can try to use it for just testing true-generalizability on totally different dataset.(In terms of real world problem, trashes have high intra-class variance so it's very important!)
Data Augmentation(Albumentations[4])
$ python augmentation.py --root_dir $ROOT --save_dir $SAVE --probability $PROB
$ROOT: 'dataset-resized/' (default)
$SAVE: 'augmented/' (default)
$PROB: low(default), mid, high (probability of applying the transform)
Training
Without pre-train(Training from scratch)
$ python main.py --gpu $GPUNUM --arch $ARCHITECTURE --no_pretrain
Without Attention Module
$ python main.py --gpu $GPUNUM --arch $ARCHITECTURE
With Attention Module
$ python main.py --gpu $GPUNUM --arch $ARCHITECTURE --use_att --att_mode $ATT
$GPUNUM: 0; 0,1; 0,3; 0,1,2; whatever
$ARCHITECTURE: resnet18_base(default), resnet34_base, resnet52_base, resnet101_base, resnet152_base
$ATT: ours(default), cbam, se
You can find more configurations in main.py.
Evaluation
$ python main.py --gpu $GPUNUM --resume save/model_best.pth.tar --use_att -e
$resume: save/model_best.pth.tar(default) (If you have changed save path, you should change resume path as well.)
$e (or evaluate): set evaluation mode
Webcam Inference
$ python webcam.py --resume save/model_best_pth.tar
Configuration
- Loss Function: Cross Entropy Loss
- Optimizer: SGD
- Initial Learning Rate: 2e-4
- epochs: 100
- For every 40 epochs, learning rate = learning rate * 1/10
Attention Module
- Attention Module
-
Attention mechanism learns parameters with a high weight for important features and a low weight for unnecessary features.
𝒙′′ = (𝒙,𝜽) ∗ 𝑨(𝒙′, ∅), 𝒘𝒉𝒆𝒓𝒆 𝟎 ≤ 𝑨(𝒙′, ∅) ≤ 𝟏.
𝒙: Input Feature, 𝒙′: CNN or later features, 𝒙′′: Output Feature,
θ, ∅: learable parameters, A: Attention operation -
When looking at the network from a forward perspective, the features are refined through attention modules.
(𝒅(𝒙, 𝜽)𝑨(𝒙′, ∅))/𝒅𝜽 = (𝒅(𝒙, 𝜽))/𝒅𝜽 ∗ 𝑨(𝒙′, ∅), 𝒘𝒉𝒆𝒓𝒆 𝟎 ≤ 𝑨(𝒙′, ∅) ≤ 𝟏. -
From a backward perspective, the greater the attention value, the greater the gradient value, so effective learning is achieved.
-
- Attention Visualization
- Visualization comparison of feature map extracted after the last convolution block.
- ResNet18 + Ours vs. ResNet18(baseline)
- While ResNet18 + Ours successfully classified, ResNet18 failed classification.
- Feature map shows that when Attention module is inserted, it attend more precisely on the object extent.
Ablation Study
- Non Pre-trained Model vs. Pre-trained Model (Transfer Learning)
Method | Accuracy@1 | Parameters(M) |
---|---|---|
ResNet18 | 70.302 | 11.18 |
ResNet34 | 64.965 | 21.29 |
ResNet50 | 58.701 | 23.52 |
Pre-trained ResNet18 | 90.023 | 11.18 |
Pre-trained ResNet34 | 93.271 | 21.29 |
Pre-trained ResNet50 | 93.735 | 23.52 |
- Attention Module(SENet vs. CBAM vs. Ours)
Method | Accuracy@1 | Parameters(M) |
---|---|---|
ResNet18 + SE[2] | 87.703 | 11.27 |
ResNet34 + SE[2] | 88.863 | 21.45 |
ResNet50 + SE[2] | 91.879 | 26.05 |
ResNet18 + CBAM[3] | 79.814 | 11.27 |
ResNet34 + CBAM[3] | 81.439 | 21.45 |
ResNet50 + CBAM[3] | 82.135 | 26.05 |
ResNet18 + Ours | 93.039 | 11.24 |
ResNet34 + Ours | 93.968 | 21.35 |
ResNet50 + Ours | 94.2 | 24.15 |
- Channel Attention & Spatial Attention
Network ablation | Accuracy@1 | Parameters(M) |
---|---|---|
ResNet18 | 90.023 | 11.18 |
ResNet18 + s | 92.807 | 11.20 |
ResNet18 + s + c | 93.039 | 11.24 |
Combination ablation | Accuracy@1 | Parameters(M) |
---|---|---|
Mul | 91.647 | 11.24 |
Max | 92.575 | 11.24 |
Sum | 93.039 | 11.24 |
Conclusion
While proposing deep-learning model which is specialized in trash classification, there was two difficult problems faced experimentally:
1) Insufficiency of data set
2) The absence of effective feature learning methods
was solved by transfer learning and attention mechanism.
The methodology proposed through quantitative and qualitative assessments was experimentally significant. Because the proposed method exhibits significant performance improvements without significantly increasing the number of parameters, it is expected that the experimental value is also high for other applications.
Reference
# | Reference | Link |
---|---|---|
1 | TrashNet | https://github.com/garythung/trashnet |
2 | SENet | https://github.com/hujie-frank/SENet |
3 | CBAM | https://github.com/Jongchan/attention-module |
4 | Albumentations | https://github.com/albu/albumentations |
Acknowledgement
We appreciate much the dataset TrashNet and the well organized code CBAM. Our codebase is mostly built based on them.
Owner metadata
- Name: Sangmin Woo
- Login: sangminwoo
- Email:
- Kind: user
- Description:
- Website: https://sangminwoo.github.io/
- Location: Daejeon, Korea
- Twitter:
- Company: KAIST
- Icon url: https://avatars.githubusercontent.com/u/33993419?u=d015b5b82369e9841dc29a930fdcbfbeff496081&v=4
- Repositories: 72
- Last ynced at: 2024-06-11T15:47:12.268Z
- Profile URL: https://github.com/sangminwoo
GitHub Events
Total
- Watch event: 2
- Fork event: 2
Last Year
- Watch event: 2
- Fork event: 2
Committers metadata
Last synced: 5 days ago
Total Commits: 53
Total Committers: 2
Avg Commits per committer: 26.5
Development Distribution Score (DDS): 0.245
Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0
Name | Commits | |
---|---|---|
Woo Sangmin | s****5@n****m | 40 |
Woo Sangmin | s****5@g****m | 13 |
Committer domains:
- naver.com: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 1
Total pull requests: 0
Average time to close issues: N/A
Average time to close pull requests: N/A
Total issue authors: 1
Total pull request authors: 0
Average comments per issue: 2.0
Average comments per pull request: 0
Merged pull request: 0
Bot issues: 0
Bot pull requests: 0
Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- min-hieu (1)
Top Pull Request Authors
Top Issue Labels
Top Pull Request Labels
Dependencies
- albumentations *
- matplotlib *
- numpy *
- opencv-python *
- scipy *
Score: 4.406719247264253