/XNOR-Net-PyTorch

PyTorch Implementation of XNOR-Net

Primary LanguagePython

XNOR-Net-Pytorch

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

Dataset Network Accuracy
CIFAR-10 Network-in-Network (NIN) 86.28%
ImageNet AlexNet Top-1: 44.87% Top-5: 69.70%

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 jiecaoyu@umich.edu.
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 sign function

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

equation