Coder Social home page Coder Social logo

xzhaogit / bmxnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hpi-xnor/bmxnet

0.0 2.0 0.0 31.45 MB

License: Apache License 2.0

CMake 0.49% Makefile 0.37% R 2.52% C++ 35.28% Python 29.21% Java 0.15% Shell 0.99% Jupyter Notebook 11.02% Cuda 5.18% C 0.99% Batchfile 0.10% MATLAB 0.27% Perl 5.68% Perl 6 0.04% Scala 7.72% Groovy 0.01%

bmxnet's Introduction

xnor enhanced neural nets // Hasso Plattner Institute

A fork of the deep learning framework mxnet to study and implement quantization and binarization in neural networks.

Our current efforts are focused on binarizing the inputs and weights of convolutional layers, enabling the use of performant bit operations instead of expensive matrix multiplications as described in:

Setup

We use cmake to build the project. Make sure to install all the dependencies described here.

Adjust settings in cmake (build-type Release or Debug, configure CUDA, OpenBLAS, OpenCV, OpenMP etc.)

$ git clone --recursive https://github.com/hpi-xnor/mxnet.git # remember to include the --recursive
$ mkdir build && cd build
$ ccmake .. # or cmake, or GUI cmake
$ make -j `nproc`

This will generate the mxnet library. To be able to use it from python, be sure to add the location of the libray to your LD_LIBRARY_PATH as well as the mxnet python folder to your PYTHONPATH:

$ export LD_LIBRARY_PATH=<mxnet-root>/build
$ export PYTHONPATH=<mxnet-root>/python

Docker

There is a simple Dockerfile that you can use to ease the setup process. Once running, find mxnet at /mxnet and the build folder at /mxnet/release. (Be warned though, CUDA will not work inside the container so training process can be quite tedious)

$ cd <mxnet-root>/smd_hpi/tools/docker
$ docker build -t mxnet
$ docker run -t -i mxnet

You probably also want to map a folder to share files (trained models) inside docker (-v <absolute local path>:/shared).

Usage

Our main contribution are drop-in replacements for the Convolution, FullyConnected and Activation layers of mxnet called QConvoluion, QFullyConnected and QActivation.

These can be used when specifying a model. They extend the parameters of their corresponding original layer of mxnet with act_bit.

Quantization

Set the parameter act_bit to a value between 1 and 32 to quantize the weights and activation to that bit width.

The quantization on bit widths ranging from 2 to 31 bit is available mainly for scientific purpose. There is no speed or memory gain (rather the opposite since there are conversion steps) as the quantized values are still stored in full precision float variables.

Binarization

To binarize the weights first set act_bit=1. Then train your network (you can use CUDA). The resulting .params file will contain binary weights, but still store a single weight in one float.

To convert your trained and saved network, call the model converter with your .params file:

$ <mxnet-root>smd_hpi/tools/model_converter mnist-0001.params

This will generate a .params and .json file with prepended binarized_. This model file will use only 1 bit of runtime memory and storage for every weight in the convolutional layers.

We have example python scripts to train and validate resnet18 (cifar10, imagenet) and lenet (mnist) neural networks with binarized layers.

There are example applications running on iOS and Android that can utilize binarized networks. Find them in the following repos:

Have a look at our source, tools and examples to find out more.

Citing BMXNet

Please cite BMXNet in your publications if it helps your research work:

@article{HPI_xnor,
  Author = {Haojin Yang, Martin Fritzsche, Christian Bartz, Christoph Meinel},
  journal = {ArXiv e-prints},
  archivePrefix = "arXiv",
  eprint = {1705.09864},
  Title = {BMXNet: An Open-Source Binary Neural Network Implementation Based on MXNet},
  Year = {2017}
}

Reference

bmxnet's People

Contributors

tqchen avatar mli avatar antinucleon avatar piiswrong avatar pluskid avatar yzhliu avatar mtin avatar sneakerkg avatar terrytangyuan avatar yajiedesign avatar winstywang avatar sxjscience avatar hotpxl avatar hjk41 avatar kevinthesun avatar ldpe2g avatar mavenlin avatar jermainewang avatar sandeep-krishnamurthy avatar hetong007 avatar tornadomeet avatar yanqingmen avatar qiaohaijun avatar vchuravy avatar howard0su avatar yzhang87 avatar szha avatar roshrini avatar thirdwing avatar nswamy avatar

Watchers

James Cloos avatar ZombieGo 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.