All Projects → kobiso → CBAM-tensorflow-slim

kobiso / CBAM-tensorflow-slim

Licence: MIT license
CBAM implementation on TensorFlow Slim

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects
shell
77523 projects

Projects that are alternatives of or similar to CBAM-tensorflow-slim

flexible-yolov5
More readable and flexible yolov5 with more backbone(resnet, shufflenet, moblienet, efficientnet, hrnet, swin-transformer) and (cbam,dcn and so on), and tensorrt
Stars: ✭ 282 (+171.15%)
Mutual labels:  resnet, cbam
Pytorch Cifar100
Practice on cifar100(ResNet, DenseNet, VGG, GoogleNet, InceptionV3, InceptionV4, Inception-ResNetv2, Xception, Resnet In Resnet, ResNext,ShuffleNet, ShuffleNetv2, MobileNet, MobileNetv2, SqueezeNet, NasNet, Residual Attention Network, SENet, WideResNet)
Stars: ✭ 2,423 (+2229.81%)
Mutual labels:  resnet, inception-resnet-v2
Tensorrtx
Implementation of popular deep learning networks with TensorRT network definition API
Stars: ✭ 3,456 (+3223.08%)
Mutual labels:  resnet, senet
clockwork-firefox
Clockwork - php dev tools integrated to your browser - Firefox add-on
Stars: ✭ 22 (-78.85%)
Mutual labels:  slim
Slim-Console
Slim Framework Console
Stars: ✭ 26 (-75%)
Mutual labels:  slim
Deep-Compression.Pytorch
Unofficial Pytorch implementation of Deep Compression in CIFAR10
Stars: ✭ 29 (-72.12%)
Mutual labels:  resnet
resnet-ensemble
Ensemble code for Resnet in Tensorflow slim
Stars: ✭ 14 (-86.54%)
Mutual labels:  resnet
BMW-IntelOpenVINO-Detection-Inference-API
This is a repository for a No-Code object detection inference API using the OpenVINO. It's supported on both Windows and Linux Operating systems.
Stars: ✭ 66 (-36.54%)
Mutual labels:  resnet
slim-nette-extension
Nette Extension for Slim API micro-framework using middlewares.
Stars: ✭ 17 (-83.65%)
Mutual labels:  slim
framework
A stylish PHP application framework crafted using Slim, Twig, Eloquent and Sentinel designed to get you from clone to production in a matter of minutes.
Stars: ✭ 56 (-46.15%)
Mutual labels:  slim
bird species classification
Supervised Classification of bird species 🐦 in high resolution images, especially for, Himalayan birds, having diverse species with fairly low amount of labelled data
Stars: ✭ 59 (-43.27%)
Mutual labels:  inception-resnet-v2
ModelZoo.pytorch
Hands on Imagenet training. Unofficial ModelZoo project on Pytorch. MobileNetV3 Top1 75.64🌟 GhostNet1.3x 75.78🌟
Stars: ✭ 42 (-59.62%)
Mutual labels:  resnet
REST-Api-with-Slim-PHP
REST API with PHP Slim Framework 3 and MySQL
Stars: ✭ 69 (-33.65%)
Mutual labels:  slim
Look4Face
Demo of Face Recognition web service
Stars: ✭ 23 (-77.88%)
Mutual labels:  resnet
TrackNet-Badminton-Tracking-tensorflow2
TrackNet for badminton tracking using tensorflow2
Stars: ✭ 37 (-64.42%)
Mutual labels:  resnet
SlimREST
An app skeleton for building a REST API with the Slim PHP Micro-Framework
Stars: ✭ 22 (-78.85%)
Mutual labels:  slim
resnet-cifar10
ResNet for Cifar10
Stars: ✭ 21 (-79.81%)
Mutual labels:  resnet
slim-php-di
Slim Framework PHP-DI container integration
Stars: ✭ 13 (-87.5%)
Mutual labels:  slim
middleman-startae
A starter template ready to run on Netlify or Heroku. Comes with several helpers, partials and a nice basic structure to the HTML, Sass, Webpack and ES2015. Bottom line, a template that uses all the modern tools.
Stars: ✭ 43 (-58.65%)
Mutual labels:  slim
neural-dream
PyTorch implementation of DeepDream algorithm
Stars: ✭ 110 (+5.77%)
Mutual labels:  resnet

CBAM-TensorFlow-Slim

This is a Tensorflow implementation of "CBAM: Convolutional Block Attention Module" aiming to be compatible on the TensorFlow-Slim image classification model library. This repository includes the implementation of "SENet-tensorflow-slim".

If you want to use simpler implementation, check the repository "CBAM-TensorFlow" which includes simple tensorflow implementation of ResNext, Inception-V4, and Inception-ResNet-V2 on Cifar10 dataset.

CBAM: Convolutional Block Attention Module

CBAM proposes an architectural unit called "Convolutional Block Attention Module" (CBAM) block to improve representation power by using attention mechanism: focusing on important features and supressing unnecessary ones. This research can be considered as a descendant and an improvement of "Squeeze-and-Excitation Networks".

Diagram of a CBAM_block

Diagram of each attention sub-module

Classification results on ImageNet-1K

Prerequisites

Prepare Data set

You should prepare your own dataset or open dataset (Cifar10, flowers, MNIST, ImageNet). For preparing dataset, you can follow the 'preparing the datasets' part in TF-Slim image models README.

CBAM_block and SE_block Supportive Models

This project is based on TensorFlow-Slim image classification model library. Every image classification model in TensorFlow-Slim can be run the same. And, you can run CBAM_block or SE_block added models in the below list by adding one argument --attention_module=cbam_block or --attention_module=se_block when you train or evaluate a model.

  • Inception V4 + CBAM / + SE
  • Inception-ResNet-v2 + CBAM / + SE
  • ResNet V1 50 + CBAM / + SE
  • ResNet V1 101 + CBAM / + SE
  • ResNet V1 152 + CBAM / + SE
  • ResNet V1 200 + CBAM / + SE
  • ResNet V2 50 + CBAM / + SE
  • ResNet V2 101 + CBAM / + SE
  • ResNet V2 152 + CBAM / + SE
  • ResNet V2 200 + CBAM / + SE

Change Reduction ratio

To change reduction ratio, you have to manually set the ratio on def cbam_block(input_feature, name, ratio=16) method for cbam_block or def se_block(residual, name, ratio=8) method for se_block in CBAM-tensorflow-slim/nets/attention_module.py.

Train a Model

You can find example of training script in CBAM-tensorflow-slim/scripts/.

Train a model with CBAM_block

Below script gives you an example of training a model with CBAM_block.

DATASET_DIR=/DIRECTORY/TO/DATASET
TRAIN_DIR=/DIRECTORY/TO/TRAIN
CUDA_VISIBLE_DEVICES=0 python train_image_classifier.py \
    --train_dir=${TRAIN_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=train \
    --dataset_dir=${DATASET_DIR} \
    --model_name=resnet_v1_50 \
    --batch_size=100 \
    --attention_module=cbam_block

Train a model with SE_block

Below script gives you an example of training a model with SE_block.

DATASET_DIR=/DIRECTORY/TO/DATASET
TRAIN_DIR=/DIRECTORY/TO/TRAIN
CUDA_VISIBLE_DEVICES=0 python train_image_classifier.py \
    --train_dir=${TRAIN_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=train \
    --dataset_dir=${DATASET_DIR} \
    --model_name=resnet_v1_50 \
    --batch_size=100 \
    --attention_module=se_block

Train a model without attention module

Below script gives you an example of training a model without attention module.

DATASET_DIR=/DIRECTORY/TO/DATASET
TRAIN_DIR=/DIRECTORY/TO/TRAIN
CUDA_VISIBLE_DEVICES=0 python train_image_classifier.py \
    --train_dir=${TRAIN_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=train \
    --dataset_dir=${DATASET_DIR} \
    --model_name=resnet_v1_50 \
    --batch_size=100

Evaluate a Model

You can find example of evaluation script in CBAM-tensorflow-slim/scripts/. To keep track of validation accuracy while training, you can use eval_image_classifier_loop.py which evaluate the performance at multiple checkpoints during training. If you want to just evaluate a model once, you can use eval_image_classifier.py.

Evaluate a model with CBAM_block

Below script gives you an example of evaluating a model with CBAM_block during training.

DATASET_DIR=/DIRECTORY/TO/DATASET
CHECKPOINT_FILE=/DIRECTORY/TO/CHECKPOINT
EVAL_DIR=/DIRECTORY/TO/EVAL
CUDA_VISIBLE_DEVICES=0 python eval_image_classifier_loop.py \
    --alsologtostderr \
    --checkpoint_path=${CHECKPOINT_FILE} \
    --dataset_dir=${DATASET_DIR} \
    --eval_dir=${EVAL_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=validation \
    --model_name=resnet_v1_50 \
    --batch_size=100 \
    --attention_module=cbam_block

Evaluate a model with SE-block

Below script gives you an example of evaluating a model with SE_block during training.

DATASET_DIR=/DIRECTORY/TO/DATASET
CHECKPOINT_FILE=/DIRECTORY/TO/CHECKPOINT
EVAL_DIR=/DIRECTORY/TO/EVAL
CUDA_VISIBLE_DEVICES=0 python eval_image_classifier_loop.py \
    --alsologtostderr \
    --checkpoint_path=${CHECKPOINT_FILE} \
    --dataset_dir=${DATASET_DIR} \
    --eval_dir=${EVAL_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=validation \
    --model_name=resnet_v1_50 \
    --batch_size=100 \
    --attention_module=se_block

Evaluate a model without attention module

Below script gives you an example of evaluating a model without attention module during training.

DATASET_DIR=/DIRECTORY/TO/DATASET
CHECKPOINT_FILE=/DIRECTORY/TO/CHECKPOINT
EVAL_DIR=/DIRECTORY/TO/EVAL
CUDA_VISIBLE_DEVICES=0 python eval_image_classifier_loop.py \
    --alsologtostderr \
    --checkpoint_path=${CHECKPOINT_FILE} \
    --dataset_dir=${DATASET_DIR} \
    --eval_dir=${EVAL_DIR} \
    --dataset_name=imagenet \
    --dataset_split_name=validation \
    --model_name=resnet_v1_50 \
    --batch_size=100 

Related Works

Reference

Author

Byung Soo Ko / [email protected]

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