Giter Site home page Giter Site logo

kobiso / senet-tensorflow-slim Goto Github PK

View Code? Open in Web Editor NEW
58.0 2.0 26.0 1.32 MB

SENet implementation on TensorFlow Slim

License: MIT License

Python 80.64% Shell 0.17% Jupyter Notebook 19.19%
senet tensorflow resnet inception slim inception-resnet-v2

senet-tensorflow-slim's Introduction

SENet-TensorFlow-Slim

This is a Tensorflow implementation of "Squeeze-and-Excitation Networks" aiming to be compatible on the TensorFlow-Slim image classification model library.

Squeeze-and-Excitation Networks

SENet proposes an architectural unit called "Squeeze-and-Excitation" (SE) block to improve the representational power of a network by explicitly modelling the interdependencies between the channels of its convolutional features.

Diagram of a SE-Block

Schema of SE-Inception and SE-ResNet modules

ย 

Single-crop error rates (%) on the ImageNet validation set

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.

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 SE-block added models in the below list by adding one argument --attention_module='se_block' when you train or evaluate a model.

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

Change Reduction ratio

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

Single-crop error rates (%) on ImageNet validation set at different reduction ratios

Train a Model

Train a model with SE-block

Below script gives you an example of training a model with SE-block. Don't forget to put an argument --attention_module=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 SE-block

Below script gives you an example of training a model without 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

Evaluate a Model

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 SE-block

Below script gives you an example of evaluating a model with SE-block during training. Don't forget to put an argument --attention_module=se_block.

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 SE-block

Below script gives you an example of evaluating a model without 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 

Related Works

Reference

Author

Byung Soo Ko / [email protected]

senet-tensorflow-slim's People

Contributors

kobiso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

senet-tensorflow-slim's Issues

SE-net module placement in inception resnet

Hi there,
I notice that the original paper says that for resnet, the SE-block is applied to "The non-identity branch of the residual nodule". And in the inception network after each inception block.

In you inception-resnet implementation, you seem to have applied the SE module to the identity branch of each block instead. (i.e) to the net variable rather than the (up*scale) variable.

Is there any reason for this? Did this configuration work for you?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.