Back to Simplicity How to Train Accurate BNNs from Scratch

Back to Simplicity: How to Train Accurate BNNs from Scratch?


文章链接
代码链接

Introduction

主要贡献在于:

1:对于如何训练出一个高精度的二值化网络提供了具体的方式,说明了原来的一些方式的效果没有那么好

2:提出了设计BNNs的一些普适的准则,在此基础上,提出了BinaryDenseNet

3:提供了开源的代码

Related Work

最近的工作主要分为三类:紧凑的网络结构设计,量化权重的网络,量化权重和激活值的网络

Compact Network Design :将 3 × 3 3\times 3 3×3的滤波器换成 1 × 1 1\times 1 1×1的滤波器,depth-wise separable convolution 、channel shuffling,不过这些方式都必须使用GPU,不能在CPU上加速

Quantized Weights and Real-valued Activations:BinaryConnect (BC) , Binary Weight Network (BWN) , and Trained Ternary Quantization (TTQ) ,内存减少,精度损失小,但是加速不多

Quantized Weights and Activations:DoReFa-Net, High-Order Residual Quantization (HORQ) and SYQ ,用1-bit的权值和多bit的激活值取得了较好的效果

Binary Weights and Activations:Binarized Neural Network (BNN) ,XNOR-Net ,ABC-Nets

Study on Common Techniques

Implementation of Binary Layers

用符号函数来二值化,然后使用STE进行反传:
sign ⁡ ( x ) = { + 1  if  x ≥ 0 − 1  otherwise  (1) \operatorname{sign}(x)=\left\{\begin{array}{l}{+1 \text { if } x \geq 0} \\ {-1 \text { otherwise }}\end{array}\right.\tag{1} sign(x)={+1 if x01 otherwise (1)

 Forward:  r o = sign ⁡ ( r i )  Backward:  ∂ c ∂ r i = ∂ c ∂ r o 1 ∣ r i ∣ ≤ t clip  (2) \begin{array}{c}{\text { Forward: } r_{o}=\operatorname{sign}\left(r_{i}\right)} \\ {\text { Backward: } \frac{\partial c}{\partial r_{i}}=\frac{\partial c}{\partial r_{o}} 1_{\left|r_{i}\right| \leq t_{\text {clip }}}}\end{array}\tag{2}  Forward: ro=sign(ri) Backward: ric=roc1ritclip (2)

Scaling Methods

作者经过试验认识BN层已经包括了尺度放缩的效果,因此,尺度+BN的效果和单纯的BN的效果是一样的,因此,作者就不使用scaling factor。

Full-Precision Pre-Training

作者对比了训练的三种方式,fully from scratch、by fine-tuning a fullprecision ResNetE18 with ReLU 、and clip as activation function。结果发现clip 的效果最差,from scratch的效果比用ReLU的效果稍微好一点,作者认为是因为BNN中我们并不使用ReLU,所以与训练模型不太适用。

Backward Pass of the Sign Function
∂ c ∂ r i = ∂ c ∂ r o 1 ∣ r i ∣ ≤ t clip  ⋅ { 2 − 2 r i  if  r i ≥ 0 2 + 2 r i  otherwise.  (3) \frac{\partial c}{\partial r_{i}}=\frac{\partial c}{\partial r_{o}} 1_{\left|r_{i}\right| \leq t_{\text {clip }}} \cdot\left\{\begin{array}{l}{2-2 r_{i} \text { if } r_{i} \geq 0} \\ {2+2 r_{i} \text { otherwise. }}\end{array}\right.\tag{3} ric=roc1ritclip {22ri if ri02+2ri otherwise. (3)
这个好像在fine-tune的时候比较好使,一般情况下作用也不大。

Proposed Approach

Golden Rules for Training Accurate BNNs

核心是保留网络中丰富的信息流 maintaining rich information flow of the network

不是是所有的real-value网络都合适用来二值化,如一些紧凑型的网络就不适合,因为这两种网络的设计理念是互斥的,一个是较少冗余eliminating redundancy,一个是补偿信息的损失compensating information loss

少用Bottleneck design(bottleneck: 1 × 1 1\times 1 1×1的卷积可以用于降维)

为保存信息流,慎用全精度的降采样层

使用shortcut connections 对BNNs来说尤为重要

为了克服信息流的瓶颈,应该适当增加网络和宽度和深度

原来的scaling factor、approxsign、FP pre-training都没有什么用,可以直接从头训

考虑下BNN的缺点,理论上讲,同全精度网络相比,它的信息密度是低32倍的,因此需要用其他的方法来补偿:

1:使用shortcut connection

2:减少bottlenecks

3:某些关键层还是用全精度代替

ResNetE

在resnet上面做了两点改变,
1:删去了bottleneck层,将三个滤波器(kernel size 1,3,1)变为两个 3 × 3 3\times3 3×3的滤波器。(会增加模型的大小个参数)
2:使用full precision downsampling convolution layer
在这里插入图片描述

BinaryDenseNet

既然用resnet有好的效果,作者就想试试densenet,因为densenet中的shortcut比resnet更多。不过,在减少bottleneck层时,发现对densenet的效果并不好。作者说这是因为the limited representation capacity of binary layers。解决这个问题有两种方法,一个是增加the growth rate parameter k, which is the number of newly concatenated features from each layer。或者是用很多的blocks。

BinaryDenseNet和ResNetE 的另一个不同点在于降采样层。也有两种方案:一是使用全精度的降采样层,为了减少计算量,使用 M a x P o o l → R e L U → 1×1-Conv ⁡ MaxPool\rightarrow ReLU\rightarrow \operatorname{1×1-Conv} MaxPoolReLU1×1-Conv代替了 1×1-Conv ⁡ → AvgPool ⁡ \operatorname{1×1-Conv}\rightarrow \operatorname{AvgPool} 1×1-ConvAvgPool。另一种是使用binary downsampling conv-layer with a lower reduction rate, or even no reduction at all 代替full-precision layer。
在这里插入图片描述

Main Results

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值