This repository serves as the official code release of the paper FracBNN: Accurate and FPGA-Efficient Binary Neural Networks with Fractional Activations (pubilished at FPGA 2021).
FracBNN, as a binary neural network, achieves MobileNetV2-level accuracy by leveraging fractional activations. In the meantime, its input layer is binarized using a novel thermometer encoding with minimal accuracy degradation, which improves the hardware resource efficiceny.
If FracBNN helps your research, please consider citing:
@article{Zhang2021fracbnn,
title = "{FracBNN: Accurate and FPGA-Efficient Binary Neural Networks with Fractional Activations}",
author = {Zhang, Yichi and Pan, Junhao and Liu, Xinheng and Chen, Hongzheng and Chen, Deming and Zhang, Zhiru},
journal = {The 2021 ACM/SIGDA International Symposium on Field-Programmable Gate Arrays},
year = {2021}
}
| cifar10.py (training script)
| imagenet.py (training script)
|
└── models/
| | fracbnn_cifar10.py
| | fracbnn_imagenet.py
|
└───utils/
| | quantization.py
| | utils.py
|
└───xcel-cifar10/
| | High-level synthesis code for FracBNN CIFAR-10 accelerator
|
└───xcel-imagenet/
| | High-level synthesis code for FracBNN ImageNet accelerator
Python 3.6.8
torch 1.6.0
torchvision 0.7.0
numpy 1.16.4
python cifar10.py -gpu 0 -t -r /path/to/pretrained-cifar10-model.pt -d /path/to/cifar10-data
python imagenet.py -gpu 0,1,2,3 -t -r /path/to/pretrained-imagenet-model.pt -d /path/to/imagenet-data
Please refer to the paper for details such as hyperparameters.
utils/quantization.py
, use self.binarize = nn.Sequential()
in BinaryConv2d()
, or modify self.binarize(self.weight)
to self.weight
in PGBinaryConv2d()
.python cifar10.py -gpu 0 -s
utils/quantization.py
, use self.binarize = FastSign()
in BinaryConv2d()
, or self.binarize(self.weight)
in PGBinaryConv2d()
.python cifar10.py -gpu 0 -f -r /path/to/model_checkpoint.pt -s
-g
to set the gating target if training with PGBinaryConv2d
Dataset | Precision (W/A) | 1-bit Input Layer | Top-1 % |
---|---|---|---|
CIFAR-10 | 1/1.4 (PG) | Yes | 89.1 |
ImageNet | 1/1.4 (PG) | Yes | 71.7 |
cd ./xcel-cifar10/source/
make hls
This step should be done after compiling the HLS code. Assume you are in the directory of ./xcel-cifar10/source/
.
make vivado
To test the bitstream on the board, the following files (sample images and labels) are needed:
To deploy the bitstream:
/xcel-cifar10/deploy/
/xcel-cifar10/deploy/
/xcel-cifar10/deploy/
to the boarddeploy/
, run sudo python3 FracNet-CIFAR10.py
on the boardPlease run the compilation flow using Vivado HLS. The top function is FracNet()
in xcel-imagenet/source/bnn.cc
.
To test the bitstream on the board, the following files (sample images, weights) are needed:
To deploy the bitstream:
/xcel-imagenet/deploy/
/xcel-imagenet/deploy/
/xcel-imagenet/deploy/
to the boarddeploy/
, run sudo python3 FracNet-ImageNet.py
on the board