百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
F

FracBNN

> 编程语言
开源

FracBNN: 具有分数激活的精确且 FPGA 高效的二进制神经网络

100 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

FracBNN: 具有分数激活的精确且 FPGA 高效的二进制神经网络

FracBNN

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.

Citation

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}
}

Structure

|   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

Dependency

Python 3.6.8
torch 1.6.0
torchvision 0.7.0
numpy 1.16.4

Run

Pretrained Model Release

  • Pretrained CIFAR-10 model
  • Pretrained ImageNet model

Test Only

  • For CIFAR-10, run python cifar10.py -gpu 0 -t -r /path/to/pretrained-cifar10-model.pt -d /path/to/cifar10-data
  • For ImageNet, run python imagenet.py -gpu 0,1,2,3 -t -r /path/to/pretrained-imagenet-model.pt -d /path/to/imagenet-data

Train (Two Step Training):

Please refer to the paper for details such as hyperparameters.

  • Step 1: Binary activations, floating-point weights.
    • In utils/quantization.py, use self.binarize = nn.Sequential() in BinaryConv2d(), or modify self.binarize(self.weight) to self.weight in PGBinaryConv2d().
    • Run python cifar10.py -gpu 0 -s
  • Step 2: Binary activations, binary weights.
    • In utils/quantization.py, use self.binarize = FastSign() in BinaryConv2d(), or self.binarize(self.weight) in PGBinaryConv2d().
    • Run python cifar10.py -gpu 0 -f -r /path/to/model_checkpoint.pt -s
    • Use -g to set the gating target if training with PGBinaryConv2d

Model Accuracy

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

CIFAR-10 Accelerator

Compile the HLS code

cd ./xcel-cifar10/source/
make hls

Generate the Bitstream

This step should be done after compiling the HLS code. Assume you are in the directory of ./xcel-cifar10/source/.

make vivado

Deploy on Xilinx Ultra96v2

To test the bitstream on the board, the following files (sample images and labels) are needed:

  • conv1-input.bin
  • conv1-input-uint64.npy
  • labels.bin

To deploy the bitstream:

  • Step1: Download the files and move them to /xcel-cifar10/deploy/
  • Step2: Move the generated bitstream and hardware definition files to /xcel-cifar10/deploy/
  • Step3: Upload the entire directory /xcel-cifar10/deploy/ to the board
  • Step4: Go to deploy/, run sudo python3 FracNet-CIFAR10.py on the board

ImageNet Accelerator

Compile HLS and Generate Bitstream

Please run the compilation flow using Vivado HLS. The top function is FracNet() in xcel-imagenet/source/bnn.cc.

Deploy on Xilinx Ultra96v2

To test the bitstream on the board, the following files (sample images, weights) are needed:

  • sample image
  • conv1x1 weights
  • conv3x3 weights
  • classifier bias
  • classifier weights
  • batchnorm/BPReLU weights

To deploy the bitstream:

  • Step1: Download the files and move them to /xcel-imagenet/deploy/
  • Step2: Move the generated bitstream and hardware definition files to /xcel-imagenet/deploy/
  • Step3: Upload the entire directory /xcel-imagenet/deploy/ to the board
  • Step4: Go to deploy/, run sudo python3 FracNet-ImageNet.py on the board

Issues· 4 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言