arXiv:1611.06539v1 [] 20 Nov 2016

Efficient Stochastic Inference of Bitwise Deep Neural
Networks
Sebastian Vogel∗
Robert Bosch GmbH
Corporate Research Campus
71272 Renningen, Germany
sebastian.vogel@de.bosch.com

Christoph Schorn∗
Robert Bosch GmbH
Corporate Research Campus
71272 Renningen, Germany
christoph.schorn@de.bosch.com
Gerd Ascheid†
Institute for Communication
Technologies and Embedded Systems
RWTH Aachen University, Germany
ascheid@ice.rwth-aachen.de

Andre Guntoro
Robert Bosch GmbH
Corporate Research Campus
71272 Renningen, Germany
andre.guntoro@de.bosch.com

Abstract
Recently published methods enable training of bitwise neural networks which
allow reduced representation of down to a single bit per weight. We present a
method that exploits ensemble decisions based on multiple stochastically sampled
network models to increase performance figures of bitwise neural networks in terms
of classification accuracy at inference. Our experiments with the CIFAR-10 and
GTSRB datasets show that the performance of such network ensembles surpasses
the performance of the high-precision base model. With this technique we achieve
5.81% best classification error on CIFAR-10 test set using bitwise networks. Concerning inference on embedded systems we evaluate these bitwise networks using a
hardware efficient stochastic rounding procedure. Our work contributes to efficient
embedded bitwise neural networks.

1

Introduction

Research results in recent years have shown tremendous advances in solving complex problems
using deep learning approaches. Especially classification tasks based on image data have been a
major target for deep neural networks (DNNs) [8, 14]. A challenge for leveraging the strengths of
deep learning methods in embedded systems is their massive computational cost. Even relatively
small DNNs often require millions of parameters and billions of operations for performing a single
classification. Model compression approaches can help to relax memory requirements as well as
to reduce the number of required operations of DNNs. While some approaches consider special
network topologies [8, 11], another stream of research focuses on precision reduction of the model
parameters. Recent publications of bitwise neural networks (BNNs) have shown that network weights
and activations can be reduced from a high-precision floating-point down to a binary representation,
while maintaining classification accuracy on benchmark datasets [5]. Stochastic projection of the
network weights during training is a key component that enables this strong quantization. Studies
∗
†

These authors contributed equally to this work.
Professor Gerd Ascheid is Senior Member IEEE.

Submitted to 1st International Workshop on Efficient Methods for Deep Neural Networks at 30th Conference
on Neural Information Processing Systems (NIPS 2016), Barcelona, Spain. Copyright c 2016 Robert Bosch
GmbH. Rights reserved.

which employed this training method have so far only analyzed deterministic projections during
test-time [4, 5, 15].
With techniques presented in this paper, we contribute to stochastic inference of bitwise neural
networks on hardware. We show that stochastic rounding at test-time improves classification accuracy
of networks that were trained with stochastic weight projections (Section 3). Furthermore, we present
a method which efficiently realizes stochastic rounding of network weights in a dedicated hardware
accelerator (Section 4). We start off with a brief review of the literature on weight discretization
(Section 2).

2

Related Work

Some recent studies have shown that weights (and activations) of DNNs can be discretized to a
very low number of quantization levels while maintaining high classification performance [1, 4,
5, 10, 12, 15, 16]. They employ a method which has already been sketched out by [6]. For each
iteration of the back-propagation learning algorithm the high-precision weights of the network are
projected to discretized values. The discrete weights are used to compute gradient descent based
weight updates, which are then applied to the high-precision weights. This method can be used either
as a fine-tuning step for several epochs after regular training [1, 10, 12] or from the beginning of
the training [4, 5, 15, 16]. [4] has recently introduced clipping followed by stochastic rounding as a
method for projecting high-precision to binary (-1, +1) weights. Before, [7] used a similar method
but with a relatively large number of discretization levels and presented a neural network hardware
accelerator using multiply-accumulate-units for stochastic rounding. Instead, we present a method
avoiding multipliers.

3

Stochastic Inference

Our methods are based on neural networks which are trained with stochastic weight projections.
In this section, we show that by applying these projections at test-time, a stochastic ensemble of
BNNs can be created whose aggregated classification performance surpasses that of the underlying
high-precision floating-point model, while maintaining the benefits of bitwise and multiplierless
computations.
3.1

Stochastic Network Ensembles

We employ the method introduced in [4] during training and inference. Depending on the number of
discrete values we speak of binary or ternary network weights. Clipping limits the numerical range
of the weights to the interval [−1, 1] and the projection W 7→ W d is done by stochastic rounding:

sround(w) =


dwe, with probability p =
bwc,

with probability 1 −

bwc−w
bwc−dwe
dwe−w
p = bwc−dwe

.

(1)

Best test-time results in [4] were achieved with the high-precision neural network parameters W .
However, discretized values are much better suited for dedicated hardware accelerators, which is
why we investigate inference based on W d . One approach is to perform inference at test-time with
the same weight discretization projections as in the training procedure. The reasoning behind this is
that the network has been optimized for these projections when minimizing the loss function. With
Eqn. (1) as projection function, experiments show a high variance in classification accuracy when the
projection is performed only once. Ensembles of classifiers can be used to lower the classification
variance of the aggregated classification decision. Using multiple stochastic projections W 7→ W d we
sample different versions of our neural network and combine their outputs as visualized in Figure 1.
The ensemble classification decision is then taken based on this accumulated network output.
3.2

Experimental Results

For the first evaluation of our method, we train a ConvNet on the CIFAR-10 classification dataset [13],
which contains 60 000 images in 32×32 pixel RGB resolution and 10 different classes. We use
2

+

bitwise NN
𝒘𝒅𝟐

bitwise NN
𝒘𝒅𝟏
high-precision NN
𝒘𝒑𝒓𝒆𝒄

accumulated
network output

input data

bitwise NN
𝒘𝒅𝑵

stochastic
projection

Figure 1: Based on a high-precision network, an ensemble of networks is created. The outputs of the
ensemble members are used in conjunction.
the setup described in [4] for training, but with sign3 activation function as in [5] and stochastic
ternary weights. The network structure is 128C3–128C3–MP2–256C3–256C3–MP2–512C3–512C3–
MP2–1024FC–1024FC–10SVM4 . After training the model for 500 epochs with hyperparameters
from [4] and without any preprocessing or augmentations on the dataset, we select high-precision
model parameters which have the lowest error on the validation set. These weights are used to
generate multiple instances of the network by rounding the weights stochastically to ternary values
(see Section 3.1). Classification error rates on the CIFAR-10 test set based on the ensemble decision
for different accumulation lengths, i. e. numbers of ensemble members, are plotted in Figure 2a.
Since classification results are not deterministic in this case, we run the whole experiment 20× and
provide mean and standard deviation. In our experiment, a stochastic BNN ensemble with at least
four members always performs better than the floating-point reference model, which achieves a
classification error of 10.74%.
Figure 2: We evaluated ensembles of networks which were generated by stochastically projecting the
high-precision model parameters to ternary values.

13

13.15%

high-precision reference (10.74%)
mean and std. of 20 evaluations

12
11
10

10.44%

10.16% 9.95%

7.5

Classification error rate
on test set [%]

Classification error rate
on test set [%]

14

7.0
6.5

9.92%

9.79%

high-precision reference (6.13%)
mean and std. of 20 evaluations

6.91%

6.21%

6.12%

6.06%

6.04%

6.04%

6.0

9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

number of networks in ensemble

number of networks in ensemble

(a) The network has sign activation. Our best result (b) The network uses ReLU activation. The best result
was 9.41% with an ensemble of 23 networks.
of 5.81% was achieved for an ensemble of 29 networks.

Better classification results can be achieved when the same network is trained with ReLU activation
function, binary projections, global contrast normalization and ZCA whitening, as well as augmentations on the training data. We apply a commonly used simple data augmentation method [9],
consisting of a random translation of up to 4 pixels in the image plane and a random flip around the
vertical axis. Classification results for this setup using ternary projections at test-time are shown in
Figure 2b. The best result of 5.81% was reached with an ensemble of 29 networks. To the best of our
knowledge we are the first to report a classification error of less than 6% on the CIFAR-10 benchmark
using bitwise neural networks.
In addition, we test our method on the German Traffic Sign Recognition Benchmark dataset [17].
The resulting high-precision network with sign activation leads to 2.19% classification error. For
3

sign(x): 1 for ≥ 0, −1 otherwise.
Preceding numbers indicate the number of channels, C3 denotes a convolution layer with 3×3 kernel, MP2
abbreviates spatial max-pooling with a receptive field of 2×2, FC stands for fully connected layers and SVM for
a square hinge loss output layer.
4

3

20 evaluations, a single projected bitwise network results in 2.73% mean error rate (0.092% std.)
whereas ensembles of 11 networks reach 1.79% mean error rate (0.042% std.). The best result of
1.63% was achieved with 16 ensemble members.
Interestingly, the mean performance of discretized ensembles reach better classification results than
the high-precision base model. We believe that due to the gradient descent optimization of the loss
function which is evaluated for discrete values, best results are achieved with projected versions of
the base model.

4

Efficient Stochastic Rounding in Hardware

In order to fully exploit the performance of bitwise neural networks in terms of accuracy, the BNN
needs to be evaluated more than once and therefore an efficient integration of a stochastic rounding
engine is necessary. Based on the publications [2] and [3], a simple multiplexer can be used to
perform sround(x) (see Eqn. (1)). Assuming the probability of the select signal sel of an N-to-1
multiplexer to route signal ini ∈ {0, 1} to the output is equally distributed, the probability of the
output signal out being 1 can be written as

P (out = 1) =

N
X

ini P (sel = i) =

i=1

N
X
i=1

ini

1
.
N

(2)

Hence, the probability P (out = 1) is determined by the number of ones at the input in. However, if
the probability function P (sel = i) is chosen to be

P (sel = i) =

2i−1
,
2N − 1

(3)

the probability P (out = 1) is directly related to the input in. Additionally, considering in as a binary
coded5 fractional number ∈ [0, 1) then P (out = 1) ≈ in with a maximum error of 21N . In order to
use this technique in hardware, the corresponding signal for sel has to be generated by individual
select wires selj . Whereas [2] considers the N equations (3) as an overdetermined problem and
proposes a numerical solution, we present an analytic solution to the problem. There are log2 (N )
individual select bits selj with
j−1

22

1
22j−1 + 1
log2 (N )
log2 (M ) 

Y
Y
k−1
P (selj ) = P (sel), because
22
⇒
+ 1 = 2M − 1.
P (selj = 1) =

22j−1 + 1

, P (selj = 0) =

j=1

(4)

k=1

Bitstreams for selj with the corresponding frequencies can be generated using a linear feedback shift
register (LFSR) in combination with Daalen modulators [18].
In order to verify the concept of stochastic rounding engines for neural networks using the method
presented above, we evaluated the network for road sign recognition with weights stochastically
projected in hardware. The results presented in Section 3.2 have been reproduced using this approach.
To take a potential hardware parallelization into consideration, we also performed projections in
parallel over the dimension of output features. As the generation of random bitstreams using LFSRs
is expensive in terms of energy and hardware resources, we evaluated the classification performance
when using a single pseudo random bitstream (PRBS) generator to provide the same select signal
for all stochastic rounders (i.e. multiplexers) in the network. We found that relying on a single
PRBS generator retains mean classification accuracy. Moreover, the mean network performance is
preserved when only a single LFSR is used to generate a random base bitstream which is then subject
to different modulations [18] to generate PRBS with appropriate frequencies of 1’s (see Eqn. (4)).
5

inN corresponds to the most significant bit (MSB).

4

5

Conclusion and Outlook

We investigated bitwise neural networks with stochastically projected weights during inference.
Results show that an ensemble-based decision of multiple versions of such a BNN enhances performance compared to the inference based on the high-precision shadow weights. Furthermore, we
presented a hardware efficient stochastic rounding procedure for the first time used on bitwise DNNs.
Our results show that this technique can be used for test-time inference enabling efficient hardware
implementation in embedded systems.
The methods proposed in [4] and [5] rely on stochastic projections during training. Future research
will investigate the integration of our generalized form of stochastic rounding into the training process.

References
[1] S. Anwar, K. Hwang, and W. Sung. Fixed point optimization of deep convolutional neural
networks for object recognition. In 2015 IEEE International Conference on Acoustics, Speech
and Signal Processing (ICASSP), pages 1131–1135, April 2015.
[2] S. L. Bade. Lookup table based neural network using fpga. Master’s thesis, Brigham Young
University, 1994.
[3] S. L. Bade and B. L. Hutchings. Fpga-based stochastic neural networks-implementation. In
Proceedings of the IEEE Workshop on FPGAs for Custom Computing Machines 1994, pages
189–198, Apr 1994.
[4] M. Courbariaux, Y. Bengio, and J.-P. David. BinaryConnect: Training Deep Neural Networks
with binary weights during propagations. ArXiv e-prints, November 2015. arXiv:1511.00363.
[5] M. Courbariaux, I. Hubara, D. Soudry, R. El-Yaniv, and Y. Bengio. Binarized Neural Networks:
Training Deep Neural Networks with Weights and Activations Constrained to +1 or -1. ArXiv
e-prints, February 2016. arXiv:1602.02830.
[6] E. Fiesler, A. Choudry, and H. J. Caulfield. Weight discretization paradigm for optical neural
networks. In Proceedings of SPIE, volume 1281, pages 164–173, 1990.
[7] S. Gupta, A. Agrawal, K. Gopalakrishnan, and P. Narayanan. Deep Learning with Limited
Numerical Precision. In Proceedings of The 32nd International Conference on Machine
Learning, pages 1737–1746, 2015.
[8] K. He, X. Zhang, S. Ren, and J. Sun. Deep Residual Learning for Image Recognition. ArXiv
e-prints, December 2015. arXiv:1512.03385.
[9] G. Huang, Y. Sun, Z. Liu, D. Sedra, and K. Weinberger. Deep Networks with Stochastic Depth.
ArXiv e-prints, March 2016. arXiv:1603.09382.
[10] K. Hwang and W. Sung. Fixed-point feed forward deep neural network design using weights
+1, 0 and -1. In 2014 IEEE Workshop on Signal Processing Systems (SiPS), 2014.
[11] F. N. Iandola, S. Han, M. W. Moskewicz, K. Ashraf, W. J. Dally, and K. Keutzer. SqueezeNet:
AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size. ArXiv e-prints,
February 2016. arXiv:1602.07360.
[12] J. Kim, K. Hwang, and W. Sung. X1000 real-time phoneme recognition vlsi using feed-forward
deep neural networks. In 2014 IEEE International Conference on Acoustics, Speech and Signal
Processing (ICASSP), pages 7510–7514, May 2014.
[13] A. Krizhevsky. Learning Multiple Layers of Features from Tiny Images. Technical report,
Department of Computer Science, University of Toronto, 2009.
[14] A. Krizhevsky, I. Sutskever, and G. E. Hinton. ImageNet Classification with Deep Convolutional
Neural Networks. In Advances in Neural Information Processing Systems, pages 1097–1105,
2012.
5

[15] P. Merolla, R. Appuswamy, J. Arthur, S. K. Esser, and D. Modha. Deep neural networks
are robust to weight binarization and other non-linear distortions. ArXiv e-prints, June 2016.
1606.01981.
[16] M. Rastegari, V. Ordonez, J. Redmon, and A. Farhadi. XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks. ArXiv e-prints, March 2016. arXiv:1603.05279.
[17] J. Stallkamp, M. Schlipsing, J. Salmen, and C. Igel. The German Traffic Sign Recognition
Benchmark: A multi-class classification competition. In 2011 IEEE International Joint Conference on Neural Networks, pages 1453–1460, 2011.
[18] M. van Daalen, P. Jeavons, J. Shawe-Taylor, and D. Cohen. Device for generating binary
sequences for stochastic computing. In Electronics Letters, volume 29, page 80, Jan 1993.

6

