Giter Site home page Giter Site logo

xnornet's Introduction

XnorNet-Pytorch

This is a Pytorch implementation of the XNOR-Networks for the MNIST dataset. The model structure is LeNet-5. The dataset is provided by torchvision.

Requirements

  • Python3, Numpy
  • Pytorch 0.3.1

Usage

$ git clone https://github.com/buaabai/XnorNet
$ python main.py --epochs 100

You can use

$ python main.py -h

to check other parameters.

Todo

  • LeNet-5 for MNIST

Notes

In the paper, the gradient in backward after the scaled sign function is inaccurate. The correct equation is here.

How It Works

  • model.py This file contains four classes, BinAvtiv, BinConv2d, BinLinear and LeNet5_Bin. BinActiv is used to compute the binary activations and alpha and as a module in BinConv2d and BinLinear. LeNet5_Bin is composed of BinConv2d and BinLinear.And only the activations is binarized now.
  • utils.py This file contains binarized operation and update operation for both convolution layer and linear layer on weights. The binarized operation includes clamp, save and binarize(the clamp operation refers to this paper). The update operation computes the gradients from binarized weights.
  • main.py This file is the main function, which includes training, testing and saving the best model. When we are training the network, firstly, we binarize the weights of the model, secondly we use the model with binarized activations and weights, and then we call the backward of loss, lastly we update the weights in binary way.

Reference

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.