All Projects → mzemlyanikin → binary-nets

mzemlyanikin / binary-nets

Licence: other
PyTorch implementation of binary neural networks

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to binary-nets

S2-BNN
S2-BNN: Bridging the Gap Between Self-Supervised Real and 1-bit Neural Networks via Guided Distribution Calibration (CVPR 2021)
Stars: ✭ 53 (+35.9%)
Mutual labels:  binary-neural-networks
ios-image-classification
No description or website provided.
Stars: ✭ 12 (-69.23%)
Mutual labels:  binary-neural-networks
Binary-Neural-Networks
Implemented here a Binary Neural Network (BNN) achieving nearly state-of-art results but recorded a significant reduction in memory usage and total time taken during training the network.
Stars: ✭ 55 (+41.03%)
Mutual labels:  binary-neural-networks

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].