All Projects → sangminwoo → RecycleNet

sangminwoo / RecycleNet

Licence: MIT license
Attentional Learning of Trash Classification

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to RecycleNet

MGAN
Exploiting Coarse-to-Fine Task Transfer for Aspect-level Sentiment Classification (AAAI'19)
Stars: ✭ 44 (+91.3%)
Mutual labels:  attention
pytorch-attention-augmented-convolution
A pytorch implementation of https://arxiv.org/abs/1904.09925
Stars: ✭ 20 (-13.04%)
Mutual labels:  attention
reasoning attention
Unofficial implementation algorithms of attention models on SNLI dataset
Stars: ✭ 34 (+47.83%)
Mutual labels:  attention
seq2seq-pytorch
Sequence to Sequence Models in PyTorch
Stars: ✭ 41 (+78.26%)
Mutual labels:  attention
chinese ancient poetry
seq2seq attention tensorflow textrank context
Stars: ✭ 30 (+30.43%)
Mutual labels:  attention
keras-utility-layer-collection
Collection of custom layers and utility functions for Keras which are missing in the main framework.
Stars: ✭ 63 (+173.91%)
Mutual labels:  attention
Astgcn
⚠️[Deprecated] no longer maintained, please use the code in https://github.com/guoshnBJTU/ASTGCN-r-pytorch
Stars: ✭ 246 (+969.57%)
Mutual labels:  attention
DeepMove
Codes for WWW'18 Paper-DeepMove: Predicting Human Mobility with Attentional Recurrent Network
Stars: ✭ 120 (+421.74%)
Mutual labels:  attention
Im2LaTeX
An implementation of the Show, Attend and Tell paper in Tensorflow, for the OpenAI Im2LaTeX suggested problem
Stars: ✭ 16 (-30.43%)
Mutual labels:  attention
natural-language-joint-query-search
Search photos on Unsplash based on OpenAI's CLIP model, support search with joint image+text queries and attention visualization.
Stars: ✭ 143 (+521.74%)
Mutual labels:  attention
dreyeve
[TPAMI 2018] Predicting the Driver’s Focus of Attention: the DR(eye)VE Project. A deep neural network learnt to reproduce the human driver focus of attention (FoA) in a variety of real-world driving scenarios.
Stars: ✭ 88 (+282.61%)
Mutual labels:  attention
attention-ocr
A pytorch implementation of the attention based ocr
Stars: ✭ 44 (+91.3%)
Mutual labels:  attention
AiR
Official Repository for ECCV 2020 paper "AiR: Attention with Reasoning Capability"
Stars: ✭ 41 (+78.26%)
Mutual labels:  attention
lstm-attention
Attention-based bidirectional LSTM for Classification Task (ICASSP)
Stars: ✭ 87 (+278.26%)
Mutual labels:  attention
flow1d
[ICCV 2021 Oral] High-Resolution Optical Flow from 1D Attention and Correlation
Stars: ✭ 91 (+295.65%)
Mutual labels:  attention
Cgnl Network.pytorch
Compact Generalized Non-local Network (NIPS 2018)
Stars: ✭ 252 (+995.65%)
Mutual labels:  attention
tensorflow-chatbot-chinese
網頁聊天機器人 | tensorflow implementation of seq2seq model with bahdanau attention and Word2Vec pretrained embedding
Stars: ✭ 50 (+117.39%)
Mutual labels:  attention
Recurrent-Independent-Mechanisms
Implementation of the paper Recurrent Independent Mechanisms (https://arxiv.org/pdf/1909.10893.pdf)
Stars: ✭ 90 (+291.3%)
Mutual labels:  attention
DeepLearningReading
Deep Learning and Machine Learning mini-projects. Current Project: Deepmind Attentive Reader (rc-data)
Stars: ✭ 78 (+239.13%)
Mutual labels:  attention
bert attn viz
Visualize BERT's self-attention layers on text classification tasks
Stars: ✭ 41 (+78.26%)
Mutual labels:  attention

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]: https://github.com/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 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].