Recyclenet

Effective trash classification model using only a small number of annotated images
Alternatives To Recyclenet
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Nlp Tutorial13,226
9 days ago35mitJupyter Notebook
Natural Language Processing Tutorial for Deep Learning Researchers
Text_classification7,628
2 months ago45mitPython
all kinds of text classification models and more with deep learning
Absa Pytorch1,782
6 months ago91mitPython
Aspect Based Sentiment Analysis, PyTorch Implementations. 基于方面的情感分析,使用PyTorch实现。
Chinese Text Classification Pytorch1,609
3 years ago28mitPython
中文文本分类,TextCNN,TextRNN,FastText,TextRCNN,BiLSTM_Attention,DPCNN,Transformer,基于pytorch,开箱即用。
Nlp Journey1,563
6 days ago3April 29, 2020apache-2.0Python
Documents, papers and codes related to Natural Language Processing, including Topic Model, Word Embedding, Named Entity Recognition, Text Classificatin, Text Generation, Text Similarity, Machine Translation),etc. All codes are implemented intensorflow 2.0.
Attention Gated Networks1,099
3 years agomitPython
Use of Attention Gates in a Convolutional Neural Network / Medical Image Classification and Segmentation
Simplecvreproduction1,021
a year ago3apache-2.0Jupyter Notebook
Replication of simple CV Projects including attention, classification, detection, keypoint detection, etc.
Textclassifier1,003
2 years ago29apache-2.0Python
Text classifier for Hierarchical Attention Networks for Document Classification
Tf Rnn Attention703
4 years agomitPython
Tensorflow implementation of attention mechanism for text classification tasks.
Textclassification Keras649
3 years ago13mitPython
Text classification models implemented in Keras, including: FastText, TextCNN, TextRNN, TextBiRNN, TextAttBiRNN, HAN, RCNN, RCNNVariant, etc.
Alternatives To Recyclenet
Select To Compare


Alternative Project Comparisons
Readme

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

Data Preparation(TrashNet[1]: garythung/trashnet)

  • 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

Alt text

  • 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.

Alt text

  • 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 garythung/trashnet
2 SENet hujie-frank/SENet
3 CBAM Jongchan/attention-module
4 Albumentations albu/albumentations

Acknowledgement

We appreciate much the dataset TrashNet and the well organized code CBAM. Our codebase is mostly built based on them.

Popular Classification Projects
Popular Attention Projects
Popular Data Processing Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Python
Classification
Attention
Resnet