GithubHelp home page GithubHelp logo

binary-nets's Introduction

Binary neural networks

Implementation of some architectures from Structured Binary Neural Networks for Accurate Image Classification and Semantic Segmentation in Pytorch

Models

All architectures are based on ResNet18 now.

There are two groups of models:

  • torchvision ResNet compatible. The only difference is BasicBlock that is used inside.
  • deep-person-reid compatible. Models with small change in the forward method to be easily integrated with deep-person-reid project.

Note about binary NN training

When we train binary neural networks we usually use quantized weights and activations for forward and backward passes and full-precision weights for update. That's why usual backward pass and weights update

optimizer.zero_grad()
loss.backward()
optimizer.step()

should be changed with:

optimizer.zero_grad()
loss.backward()
for p in list(model.parameters()):
    if hasattr(p, 'original'):
        p.data.copy_(p.original)
optimizer.step()
for p in list(model.parameters()):
    if hasattr(p, 'original'):
        p.original.copy_(p.data.clamp_(-1, 1))

ONNX compatibility:

Some changes were made into models with fusion gate to make them ONNX-compatible. Models for training use modules with custom backward function, that can't be converted with ONNX, that's why they are changed with simple sign function for inference. To create inference model you should pass freeze=True flag.

TODO:

Proper initialization for inference models:

  • Mean of weights should be merged into batchnorms
  • Weights binarization should be done

binary-nets's People

Contributors

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