twn (ternary weight networks)

The authors introduced ternary weight networks (TWNs) to address the limited storage and computational resources issues in hardware. The quantization problem can be formulated as follows:
$$
begin{cases}
alpha^, W^{t} = &argmin_{alpha, W^t} J(alpha, W^t) = |W-alpha W^t|_2^2 \
s.t. & age0, W_i^tin{-1,0,1}, i=1,2,dots, n.
end{cases} tag{1}
$$
Here $n$ is the size of filter, $W$ represents weights of the network. With $Wapprox alpha W^t$ and assuming the convolutional layer do not have bias term, forward propagation of ternary weight networks is as follows:
$$
begin{cases}
Z & = &XW approx X(alpha W^t) = (alpha X)oplus W^t \
X^{next} & = & g(Z)
end{cases} tag{2}
$$
where $X$ indicates inputs, $$ indicates convolutional operation, $g$ is the non-linear activation function, $oplus$ indicates the inner product or convolutional operation without any multiplication, $X^{next}$ indicates the outputs.

The approximated solution of $W$ with threshold-based ternary function is as follows:
$$
W_i^t = f_t(W_i|triangle) =
begin{cases}
+1, if~W_i gt triangle \
0, if~|W_i| le triangle \
-1, if~W_i lt -triangle
end{cases} tag{3}
$$
The optimized objective function can be written as:
$$
alpha^
, triangle^ = argmin_{alphage0, trianglegt 0}(|Itriangle|alpha^2-2(sum{iin I_triangle}|W_i|)alpha+c_triangle) tag{4}
$$
where $I_triangle = {i|~|W|gttriangle}$ and $|I_triangle|$ denotes the number of elements in $I_triangle$; $ctriangle = sum{iin I_triangle^c}W_i^2$ is a $alpha$-independent constant. Thus the optimal solutions of the objective function can be computed as follows:
$$
alpha_triangle^
= frac{1}{|Itriangle|}sum{iin I_triangle}|Wi| \
triangle^* = argmax
{trianglegt 0}(sum_{iin I_triangle}|Wi|^2) tag{5}
$$
Here solution of $triangle$ is approximated by $triangle^*approx0.7cdot E(|W|) approx frac{0.7}{n}sum
{i=1}^n|W_i|$.

Training Methods

The training of ternary weight networks can be summarized to three steps: quantization, training and updating. Quantization phase is to quantize the weights of convolutional layers using Equation (5), then apply standard forward and backward propagation to the network, and update parameters using standard SGD. Source code is available on GitHub.

Important Tips

Experimental Results

Three data sets are used in this paper, including MNIST, CIFAR-10, ImageNet. To different data sets, the authors conducted experiments using LeNet-5 (32-C5 + MP2 + 64-C5 + MP2 + 512FC + SVM), VGG-inspired network (2$times$(128-C3) + MP2 + 2$times$(256-C3) + MP2 + 2$times$(512-C3) + MP2 + 1024-FC + Softmax), ResNet-18, respectively. Network architecture and parameters setting for different data sets are shown as follows:

MNIST CIFAR-10 ImageNet
network architecture LeNet-5 VGG-7 ResNet-18 (B)
weight decay 1e-4 1e-4 1e-4
mini-batch size of BN 50 100 64($times$4 GPUs)
initial learning rate 0.01 0.1 0.1
learning rate decay (divided by 10) epochs 15, 25 80, 120 30, 40, 50
momentum 0.9 0.9 0.9

Comparison of the proposed method and the previous methods are shown as follows:

Method MINIST CIFAR-10 ImageNet Top1 (ResNet-18 / ResNet-18B) ImageNet Top5 (ResNet-18 / ResNet-18B)
TWN 99.35 92.56 61.8 / 65.3 84.2 / 86.2
BPWN 99.05 90.18 57.5 / 61.6 81.2 / 83.9
FPWN (full precision) 99.41 92.88 65.4 / 67.6 86.76 / 88.0
Binary Connect 98.82 91.73 - -
Binarized Neural Networks 88.6 89.85 - -
Binary Weight Networks - - 60.8 83.0
XNOR-Net - - 51.2 73.2