Coder Social home page Coder Social logo

xnor-net-pytorch's Introduction

XNOR-Net-Pytorch

This a PyTorch implementation of the XNOR-Net. I implemented Binarized Neural Network (BNN) for:

Dataset Network                 Accuracy                   Accuracy of floating-point
MNIST LeNet-5 99.23% 99.34%
CIFAR-10 Network-in-Network (NIN) 86.28% 89.67%
ImageNet AlexNet Top-1: 44.87% Top-5: 69.70% Top-1: 57.1% Top-5: 80.2%

MNIST

I implemented the LeNet-5 structure for the MNIST dataset. I am using the dataset reader provided by torchvision. To run the training:

$ cd <Repository Root>/MNIST/
$ python main.py

Pretrained model can be downloaded here. To evaluate the pretrained model:

$ cp <Pretrained Model> <Repository Root>/MNIST/models/
$ python main.py --pretrained models/LeNet_5.best.pth.tar --evaluate

CIFAR-10

I implemented the NIN structure for the CIFAR-10 dataset. You can download the training and validation datasets here and uncompress the .zip file. To run the training:

$ cd <Repository Root>/CIFAR_10/
$ ln -s <Datasets Root> data
$ python main.py

Pretrained model can be downloaded here. To evaluate the pretrained model:

$ cp <Pretrained Model> <Repository Root>/CIFAR_10/models/
$ python main.py --pretrained models/nin.best.pth.tar --evaluate

ImageNet

I implemented the AlexNet for the ImageNet dataset. You can download the preprocessed dataset here and uncompress it. However, to use this dataset, you have to install Caffe first. Support with torchvision data reader will soon be added. If you need the function now, please contact [email protected].
To set up the dataset:

$ cd <Repository Root>/ImageNet/networks/
$ ln -s <Datasets Root> data

AlexNet

To train the network:

$ cd <Repository Root>/ImageNet/networks/
$ python main.py

Pretrained model can be downloaded here. To evaluate the pretrained model:

$ cp <Pretrained Model> <Repository Root>/ImageNet/networks/
$ python main.py --resume alexnet.baseline.pth.tar --evaluate

The training log can be found here.

Todo

  • Generate new dataset without caffe support.
  • NIN for ImageNet.

Notes

Gradients of scaled sign function

In the paper, the gradient in backward after the scaled sign function is

equation

However, this equation is actually inaccurate. The correct backward gradient should be

equation

Details about this correction can be found in the notes (section 1).

xnor-net-pytorch's People

Contributors

jiecaoyu avatar

Watchers

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