Paper commentary
XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks
Binary weights and inputs let convolutional networks run on cheap hardware
- Problem Standard convolutional networks need large memory and many high precision operations, so they are hard to run on cell phones and embedded devices. Earlier binarization methods lost too much accuracy on ImageNet.
- Method XNOR-Net replaces each filter with its sign pattern and a scale, and also binarizes the inputs. Convolutions then run on XNOR and bitcount operations instead of multiplications.
- Results Binary-Weight-Network reached 56.8 top-1 and 79.4 top-5 on ImageNet with AlexNet, against 56.6 and 80.2 for full precision.
Why compress CNNs for small devices
Convolutional networks have reached strong results in object recognition and detection, but the authors want those models on hardware far smaller than a GPU server. AlexNet alone has 61M parameters, which occupy 249MB of memory, and it needs 1.5B high precision operations to classify one image. Deeper networks such as VGG push both figures higher, which is why cost matters on cell phones and embedded electronics.
The approach therefore targets two limits at once: the memory a model occupies and the arithmetic cost of each convolution.
Where this sits among compression and binarization work
Pruning, hashed weight sharing and low-rank factorization shrink or reshape a trained network. Compact layer designs reduce cost by restructuring the architecture, whereas the authors keep the standard deep architectures and change only the numerical form of the parameters. Quantization work is the closest neighbour, and the authors' quantization is the extreme case in which values are +1 or -1.
Among binarization methods, BinaryConnect keeps real-valued weights for the updates and BinaryNet binarizes activations as well, and the authors compare directly against both on ImageNet. The networks here are trained from scratch rather than starting from a pretrained network.
Binarizing weights with a closed-form scale
Each real-valued filter W is approximated by a binary filter B with entries in \( \{+1,-1\} \) and a positive scalar \( \alpha \), so that \( W \approx \alpha B \). The pair is chosen to minimize the squared error \( \lVert W-\alpha B\rVert^{2} \) over B and \( \alpha \). Expanding the error leaves a term in B that depends only on \( W^{T}B \), and because \( B^{T}B = n \) for any binary B, the best B maximizes \( W^{T}B \) under the sign constraint, which gives \( B^{*} = \mathrm{sign}(W) \).
Setting the derivative with respect to \( \alpha \) to zero gives \( \alpha^{*} = \frac{1}{n}\lVert W\rVert_{\ell_1} \) with \( n = c\times w\times h \), so the scale is the mean absolute weight of the filter. Storing the binary filter cuts filter memory by about 32× relative to single precision, and a convolution with binary weights needs only additions and subtractions, which the authors estimate gives about 2× speed-up.
Binarizing inputs for XNOR operations
XNOR-Net extends binarization to the inputs, so every operand of a convolution is binary. A convolution is a repeated shift followed by a dot product, so the dot product is the piece that must be made binary; for binary vectors it can be computed with XNOR and bitcounting. For vectors X and W in \( \mathbb{R}^{n} \), the method approximates \( X^{T}W \approx \beta\alpha H^{T}B \) with H and B in \( \{+1,-1\}^{n} \), and merges the two scales into \( \gamma = \beta\alpha \).
The sign vector of the product is \( C^{*} = \mathrm{sign}(Y) = \mathrm{sign}(X)\odot\mathrm{sign}(W) \), where \( Y_i = X_i W_i \). The best \( \gamma \) is the mean of \( |Y_i| \), and treating \( |X_i| \) and \( |W_i| \) as independent turns it into the product of the two mean absolute values, \( \gamma^{*} \approx \frac{1}{n}\lVert X\rVert_{\ell_1}\cdot\frac{1}{n}\lVert W\rVert_{\ell_1} \).
Computing this scale for every overlapping input window would repeat work, so the method averages absolute input values across channels into one map A and convolves A with a two-dimensional filter whose entries are all equal, which yields a scale K for each window position. The full operation is \( I * W \approx (\mathrm{sign}(I)\circledast\mathrm{sign}(W))\odot K\alpha \), where the circled convolution uses XNOR and bitcount, and K and \( \alpha \) rescale the output elementwise; only this scaling step uses non-binary arithmetic.
Training, block order and binary gradients
A typical block runs convolution, batch normalization, activation and pooling in that order. That order fits binary inputs poorly, because pooling binary values, such as taking a maximum, returns mostly +1 entries and loses information, so pooling moves after the convolution. The input is normalized before binarization, which gives it zero mean so that thresholding at zero adds less quantization error.
The resulting ordering, B-A-C-P, places batch normalization and binary activation before the binary convolution, with pooling last; a non-binary activation such as ReLU may follow the convolution, which the authors say helps with AlexNet or VGG-type networks. Training uses the same procedure as Algorithm 1, with the real-valued weights updated and the binary forward and backward passes computed from them.
The backward convolution between weight filters and input gradients can be binarized in the same way. Taking the mean-absolute scale from equation 6 for these gradients would weaken the direction of largest change for SGD, so the authors scale by the maximum absolute gradient instead. With a binary gradient, XNOR-Net loses 1.4% top-1 accuracy in the reported experiment.
The k-bit extension replaces the sign function with a rounding function defined on inputs in [-1, 1], which allows more than one bit per value. All reported results use the 1-bit binarization, so the k-bit form is introduced without an evaluation in the text.
ImageNet setup and baselines
Evaluation uses ImageNet (ILSVRC2012), with about 1.2M training images from 1K categories and 50K validation images, reported as Top-1 and Top-5 accuracy. Three base architectures are binarized: AlexNet, ResNet and a GoogLenet variant. The baselines are BinaryConnect, used with deterministic binarization because the authors found stochastic binarization inefficient, and BinaryNet, evaluated under the settings discussed in its source.
AlexNet has five convolutional layers and two fully connected layers, and the authors train it with batch normalization but without local response normalization. Training images are resized so the smaller side is 256 pixels and then cropped at random to 224×224, and the test uses a 224×224 center crop. Training runs for 16 epochs at batch size 512 with negative log-likelihood over the softmax outputs.
Binary-Weight-Network and BinaryConnect are updated with SGD using momentum 0.9, while XNOR-Net and BinaryNet use ADAM, which the authors say converges faster for binary inputs. The learning rate starts at 0.1 and has a learning-rate decay of 0.01 applied every 4 epochs.
ResNet-18 uses short-cut type B, and its images are resized between 256 and 480 pixels on the smaller side before a 224×224 crop; it trains for 58 epochs at batch size 256 with the learning-rate decay of 0.01 applied at epochs 30 and 40. The GoogLenet variant has 21 convolutional layers with filter sizes alternating between 1×1 and 3×3 and no branching, trains for 80 epochs at batch size 128, and uses a polynomial rate decay written with β = 4.
AlexNet accuracy and ablations
Table 1 gives Binary-Weight-Network 56.8 top-1 and 79.4 top-5, while full-precision AlexNet reached 56.6 and 80.2. XNOR-Net reached 44.2 and 69.2, BinaryConnect 35.4 and 61.0, and BinaryNet 27.9 and 50.42 under the same AlexNet setup. The binary-weight version therefore matches full precision on top-1 and sits slightly below it on top-5.
The introduction states a margin of more than 16% top-1 over BinaryConnect and BinaryNet, and the body gives 16.3% over BinaryNet on ILSVRC2012. The epoch curves show Binary-Weight-Network and XNOR-Net about 17% above BinaryConnect and BinaryNet at every epoch. The authors' experiments indicate that BinaryConnect is not very successful on a large-scale dataset such as ImageNet.
Removing the input scale β lowers AlexNet top-1 accuracy by less than 1%, so the authors find the weight scale α matters much more than the input scale. Computing α through a separate learned layer instead of equation 6 gives Binary-Weight-Network 46.2 top-1 and 69.5 top-5, against 56.8 and 79.4 with the closed-form scale. Ordering the XNOR-Network block as C-B-A-P gives 30.3 top-1 and 57.5 top-5, against 44.2 and 69.2 for B-A-C-P.
ResNet-18 and GoogLenet results
On ResNet-18, Binary-Weight-Network reached 60.8 top-1 and 83.0 top-5, XNOR-Network reached 51.2 and 73.2, and full precision reached 69.3 and 89.2. Figure 6 plots these ResNet-18 accuracies over the epochs for training and validation.
On the GoogLenet variant only Binary-Weight-Network is reported, at 65.5 top-1 and 86.1 top-5, against 71.3 and 90.0 for full precision. The XNOR-Network entries for this variant are marked N/A, so no XNOR-Net result is given for it.
Speed and memory estimates
A standard convolution needs c N_W N_I operations, with \( N_W = wh \) and \( N_I = w_{in}h_{in} \), while the binary approximation needs c N_W N_I binary operations and only N_I non-binary operations. Assuming a CPU performs 64 binary operations per clock, the speedup works out to \( S = \frac{64\,cN_W}{cN_W+64} \), which depends on channel count and filter size but not on input size.
For the reference setting with c = 256 and 3×3 filters, the theoretical speedup is 62.27×. The authors' CPU implementation reached 58× for one convolution, excluding memory allocation and memory access. The introduction states the 58× as a CPU speedup in number of high precision operations, and the body measures it on one convolution.
With a channel size of 3 or a 1×1 filter the speedup is not high, so the first and last layers are kept without binarization. The weight-only speed-up of about 2× assumes that multiplication and addition take separate cycles; on CPUs that fuse them into one cycle, Binary-Weight-Networks give no speedup. Binary-weight networks are small enough to fit portable devices, while the full-precision AlexNet occupies 249MB.
Limitations
The evaluation covers ImageNet with AlexNet, ResNet-18 and one GoogLenet variant. The CIFAR-10 comparison is given only as error rates for the same architecture as BinaryConnect and BinaryNet, 9.88% for Binary-Weight-Network and 10.17% for XNOR-Network. Accuracies are single final values per setting, and the text gives no seeds or intervals.
Stochastic binarization for BinaryConnect was not used in the comparisons. The speed figures are per-convolution CPU measurements under the 64-operations-per-clock assumption and exclude memory allocation and access. XNOR-Network trails full precision on ResNet-18 by a wide margin, and the text does not analyze its cause. k-bit quantization is introduced without evaluation.
Paper info
- Authors
- Mohammad Rastegari, Vicente Ordonez, Joseph Redmon, Ali Farhadi
- Venue
- arXiv · Preprint
- First published
- 2016-3-16
- Added
- 2026-11-12
- Updated
- 2016-8-2
- Version
- v4
- arXiv
- 1603.05279
- Category
- cs.CV
- Original paper terms
- arXiv non-exclusive 1.0
- What we show
- Paper info and commentary
AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.
Quote from the paper
Mohammad Rastegari, Vicente Ordonez, Joseph Redmon, Ali Farhadi (2016). XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks. arXiv:1603.05279v4. https://arxiv.org/abs/1603.05279v4
BibTeX
@misc{rastegari2016xnor,
title = {{XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks}},
author = {Mohammad Rastegari and Vicente Ordonez and Joseph Redmon and Ali Farhadi},
year = {2016},
eprint = {1603.05279},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1603.05279v4}
}