GithubHelp home page GithubHelp logo

apresunreve / shufflenet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mg2033/shufflenet

0.0 1.0 0.0 196 KB

ShuffleNet Implementation in TensorFlow

License: Apache License 2.0

Python 100.00%

shufflenet's Introduction

ShuffleNet

An implementation of ShuffleNet introduced in TensorFlow. According to the authors, ShuffleNet is a computationally efficient CNN architecture designed specifically for mobile devices with very limited computing power. It outperforms Google MobileNet by small error percentage at much lower FLOPs.

Link to the original paper: ShuffleNet: An Extremely Efficient Convolutional Neural Network for Mobile Devices

ShuffleNet Unit



Group Convolutions

The paper uses the group convolution operator. However, that operator is not implemented in TensorFlow backend. So, I implemented the operator using graph operations.

This issue was discussed here: Support Channel groups in convolutional layers #10482

Channel Shuffling



Channel Shuffling can be achieved by applying three operations:

  1. Reshaping the input tensor from (N, H, W, C) into (N, H, W, G, C').

  2. Performing matrix transpose operation on the two dimensions (G, C').

  3. Reshaping the tensor back into (N, H, W, C).

    N: Batch size, H: Feature map height, W: Feature map width, C: Number of channels, G: Number of groups, C': Number of channels / Number of groups

    Note that: The number of channels should be divisible by the number of groups.

Usage

Main Dependencies

Python 3 or above
tensorflow 1.3.0
numpy 1.13.1
tqdm 4.15.0
easydict 1.7
matplotlib 2.0.2

Train and Test

  1. Prepare your data, and modify the data_loader.py/DataLoader/load_data() method.
  2. Modify the config/test.json to meet your needs.

Run

python main.py --config config/test.json

Results

The model have successfully overfitted TinyImageNet-200 that was presented in CS231n - Convolutional Neural Networks for Visual Recognition. I'm working on ImageNet training..

Benchmarking

The paper has achieved 140 MFLOPs using the vanilla version. Using the group convolution operator implemented in TensorFlow, I have achieved approximately 270 MFLOPs. The paper counts multiplication+addition as one unit, so roughly dividing 270 by two, I have achieved what the paper proposes.

To calculate the FLOPs in TensorFlow, make sure to set the batch size equal to 1, and execute the following line when the model is loaded into memory.

tf.profiler.profile(
        tf.get_default_graph(),
        options=tf.profiler.ProfileOptionBuilder.float_operation(), cmd='scope')

TODO

  • Training on ImageNet dataset. In progress...

Updates

  • Inference and training are working properly.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

Thanks for all who helped me in my work and special thanks for my colleagues: Mo'men Abdelrazek, and Mohamed Zahran.

shufflenet's People

Contributors

mg2033 avatar msiam avatar pomonam avatar

Watchers

 avatar

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.