Adaptive Global Power-of-Two Ternary Quantization Algorithm Based on Unfixed Boundary Thresholds
Abstract
:1. Introduction
1.1. Background
1.2. Existing Methods and Problems
1.3. Contributions of This Paper
- This paper analyzes the nonglobal quantization and fixed quantization threshold problems in existing ternary quantization methods and formulates a new power-of-two ternary quantization strategy with unfixed boundary thresholds based on the global CNN quantization architecture proposed in our previous study [46]. This new quantization strategy decomposes each filter in a CNN model into two subfilters. By minimizing the Euclidean distance, the two subfilters are binarized into a power-of-two form. According to the matrix additivity, the two binary filters are combined into one ternary filter to complete the power-of-two CNN ternary quantization, and the restrictions on CNN performance due to fixed boundary thresholds and intervals are removed.
- This paper formulates a general power-of-two quantization strategy based on unfixed thresholds. By decomposing each filter into multiple filters and performing binarization and accumulation, the power-of-two ternary quantization strategy with unfixed thresholds can be extended to any bit width quantization.
- Ternary and other bit width quantization experiments were conducted on mainstream CNN models, such as VGG-16 [7], ResNet-18, ResNet-20, ResNet-56 [60], and GoogLeNet [61], in two image classification data sets: CIFAR10 [62] and Mini-ImageNet [63]. The results were compared and evaluated quantitatively and qualitatively with some state-of-the-art algorithms in order to verify the effectiveness and versatility of the proposed APTQ and APQ algorithms.
2. Proposed Method
2.1. Global Power-of-Two Ternary Quantization Based on Unfixed Boundary Thresholds (APTQ)
2.1.1. APTQ Quantization Strategy
2.1.2. Weight Distribution Characteristics of APTQ Quantization Strategy
2.1.3. APTQ Global Retraining Process
Algorithm 1: Adaptive Global Power-of-two Ternary Quantization Based on Unfixed Boundary Thresholds (APTQ) |
Input: 32-bit floating-point CNN model |
Output: Power-of-two ternary quantization CNN model |
1: Grou** weights by layer: Sort filters by their L1 norm and divide them into M groups |
2: for do |
3: Split all filters in the same layer into two subfilters using Formulas (8) and (9) |
4: for do |
5: Determine the optimal quantization scale factor using Formulas (12)–(14), (16) and (17), and complete power-of-two binary quantization of the two subfilters |
6: Remerge the subfilters using Formula (18) to complete the power-of-two ternary quantization based on unfixed boundary thresholds |
7: Retrain the network, keep the quantized layers fixed, and update unquantized weights in other layers |
8: end for |
9: end for |
2.2. Universal Global Power-of-Two Quantization Based on Unfixed Boundary Thresholds (APQ)
Algorithm 2: Universal Global Power-of-Two Quantization Based on Unfixed Boundary Thresholds (APQ) |
Input: 32-bit floating-point CNN model |
Output: Power-of-two h-bit quantization CNN model |
1: Grou** weights by layer: Sort filters by their L1 norm and divide them into M groups |
2: for do |
3: Split all filters in the same layer into subfilters using Formulas (19) and (20) |
4: for do |
5: Determine the optimal quantization scale factor using Formulas (21)–(23), and complete power-of-two binary quantization of the H subfilters |
6: Merge the binary subfilters and approximate all values to the nearest power-of-two by using Formulas (24)–(26), completing the h-bit power-of-two quantization of the original filter. |
7: Retrain the network, keep the quantized layers fixed, and update unquantized weights in other layers |
8: end for |
9: end for |
2.3. APTQ and APQ Dedicated Convolutional Computation Module in Edge Chips
3. Experiments
3.1. APTQ Quantization Performance Testing
3.1.1. Implementation Details
3.1.2. APTQ Quantization Performance Comparison
3.2. APQ Quantization Performance Testing
3.3. Hardware Performance Evaluation
3.3.1. Implementation Details
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Yan, S.-R.; Pirooznia, S.; Heidari, A.; Navimipour, N.J.; Unal, M. Implementation of a Product-Recommender System in an IoT-Based Smart Shop** Using Fuzzy Logic and Apriori Algorithm. In IEEE Transactions on Engineering Management; IEEE: Toulouse, France, 2022. [Google Scholar]
- Garcia, A.J.; Aouto, A.; Lee, J.-M.; Kim, D.-S. CNN-32DC: An Improved Radar-Based Drone Recognition System Based on Convolutional Neural Network. ICT Express 2022, 8, 606–610. [Google Scholar] [CrossRef]
- Saha, D.; De, S. Practical Self-Driving Cars: Survey of the State-of-the-Art. Preprints 2022. [Google Scholar] [CrossRef]
- Lyu, Y.; Bai, L.; Huang, X. ChipNet: Real-Time LiDAR Processing for Drivable Region Segmentation on an FPGA. IEEE Trans. Circuits Syst. I Regul. Pap. 2019, 66, 1769–1779. [Google Scholar] [CrossRef]
- Shi, W.; Cao, J.; Zhang, Q.; Li, Y.; Xu, L. Edge Computing: Vision and Challenges. Internet Things J. IEEE 2016, 3, 637–646. [Google Scholar] [CrossRef]
- McEnroe, P.; Wang, S.; Liyanage, M. A Survey on the Convergence of Edge Computing and AI for UAVs: Opportunities and Challenges. IEEE Internet Things J. 2022, 9, 15435–15459. [Google Scholar] [CrossRef]
- Simonyan, K.; Zisserman, A. Very Deep Convolutional Networks for Large-Scale Image Recognition. ar** Activation for Quantized Neural Networks. ar**+Activation+for+Quantized+Neural+Networks&author=Choi,+J.&author=Wang,+Z.&author=Venkataramani,+S.&author=Chuang,+P.I.-J.&author=Srinivasan,+V.&author=Gopalakrishnan,+K.&publication_year=2018&journal=ar** Regular and Irregular Convolutional Neural Networks on FPGAs. IEEE Trans. Neural Netw. Learn. Syst. 2018, 30, 326–342. [Google Scholar] [CrossRef]
- Zhu, C.; Huang, K.; Yang, S.; Zhu, Z.; Zhang, H.; Shen, H. An Efficient Hardware Accelerator for Structured Sparse Convolutional Neural Networks on FPGAs. IEEE Trans. Very Large Scale Integr. (VLSI) Syst. 2020, 28, 1953–1965. [Google Scholar] [CrossRef]
- Li, Y.; Dong, X.; Wang, W. Additive Powers-of-Two Quantization: An Efficient Non-Uniform Discretization for Neural Networks. In Proceedings of the International Conference on Learning Representations (ICLR), Addis Ababa, Ethiopia, 26–30 April 2020. [Google Scholar]
- He, K.; Zhang, X.; Ren, S.; Sun, J. Deep Residual Learning for Image Recognition. In Proceedings of the 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Las Vegas, NV, USA, 27–30 June 2016. [Google Scholar]
- Szegedy, C.; Liu, W.; Jia, Y.; Sermanet, P.; Reed, S.; Anguelov, D.; Erhan, D.; Vanhoucke, V.; Rabinovich, A. Going Deeper with Convolutions. In Proceedings of the 2015 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Boston, MA, USA, 7–12 June 2015; pp. 1–9. [Google Scholar]
- Krizhevsky, A.; Hinton, G. Learning Multiple Layers of Features from Tiny Images. In Handbook of Systemic Autoimmune Diseases; University of Toronto: Toronto, ON, Canada, 2009. [Google Scholar]
- Vinyals, O.; Blundell, C.; Lillicrap, T.; Wierstra, D. Matching Networks for One Shot Learning. In Proceedings of the 30th Conference on Neural Information Processing Systems (NIPS 2016), Barcelona, Spain, 5–10 December 2016; Volume 29. [Google Scholar]
- Vanholder, H. Efficient Inference with Tensorrt. In Proceedings of the GPU Technology Conference, San Jose, CA, USA, 4–7 April 2016; Volume 1. [Google Scholar]
- Nagel, M.; van Baalen, M.; Blankevoort, T.; Welling, M. Data-Free Quantization through Weight Equalization and Bias Correction. In Proceedings of the IEEE/CVF International Conference on Computer Vision, Seoul, Republic of Korea, 27 October–2 November 2019; pp. 1325–1334. [Google Scholar]
- Krizhevsky, A.; Sutskever, I.; Hinton, G. ImageNet Classification with Deep Convolutional Neural Networks. Adv. Neural Inf. Process. Syst. 2012, 60, 84–90. [Google Scholar] [CrossRef]
- Paszke, A.; Gross, S.; Massa, F.; Lerer, A.; Bradbury, J.; Chanan, G.; Killeen, T.; Lin, Z.; Gimelshein, N.; Antiga, L.; et al. PyTorch: An Imperative Style, High-Performance Deep Learning Library. In Proceedings of the Conference and Workshop on Neural Information Processing Systems 2019, Vancouver, BC, Canada, 8–14 December 2019; Volume 32. [Google Scholar]
- Zhang, D.; Yang, J.; Ye, D.; Hua, G. Lq-Nets: Learned Quantization for Highly Accurate and Compact Deep Neural Networks. In Proceedings of the European Conference on Computer Vision (ECCV), Munich, Germany, 8–14 September 2018; pp. 365–382. [Google Scholar]
- Zhou, S.; Ni, Z.; Zhou, X.; Wen, H.; Wu, Y.; Zou, Y. DoReFa-Net: Training Low Bitwidth Convolutional Neural Networks with Low Bitwidth Gradients. ar**v 2016, ar**v:1606.06160. [Google Scholar]
- Bai, Y.; Wang, Y.-X.; Liberty, E. Proxquant: Quantized Neural Networks via Proximal Operators. ar**v 2018, ar**v:1810.00861. [Google Scholar]
- Asim, F.; Park, J.; Azamat, A.; Lee, J. CSQ: Centered Symmetric Quantization for Extremely Low Bit Neural Networks. In Proceedings of the International Conference on Learning Representations 2022, New Orleans, LA, USA, 19–20 June 2022. [Google Scholar]
- Kulkarni, U.; Hosamani, A.S.; Masur, A.S.; Hegde, S.; Vernekar, G.R.; Chandana, K.S. A Survey on Quantization Methods for Optimization of Deep Neural Networks. In Proceedings of the 2022 International Conference on Automation, Computing and Renewable Systems (ICACRS), Pudukkottai, India, 13–15 December 2022; pp. 827–834. [Google Scholar]
- **linx. Vivado Design Suite User Guide: Synthesis. White Pap. 2021, 5, 30. [Google Scholar]
- Li, J.; Un, K.-F.; Yu, W.-H.; Mak, P.-I.; Martins, R.P. An FPGA-Based Energy-Efficient Reconfigurable Convolutional Neural Network Accelerator for Object Recognition Applications. IEEE Trans. Circuits Syst. II Express Briefs 2021, 68, 3143–3147. [Google Scholar] [CrossRef]
- Yuan, T.; Liu, W.; Han, J.; Lombardi, F. High Performance CNN Accelerators Based on Hardware and Algorithm Co-Optimization. IEEE Trans. Circuits Syst. I Regul. Pap. 2020, 68, 250–263. [Google Scholar] [CrossRef]
- Bouguezzi, S.; Fredj, H.B.; Belabed, T.; Valderrama, C.; Faiedh, H.; Souani, C. An Efficient FPGA-Based Convolutional Neural Network for Classification: Ad-MobileNet. Electronics 2021, 10, 2272. [Google Scholar] [CrossRef]
- Renda, A.; Frankle, J.; Carbin, M. Comparing Fine-Tuning and Rewinding in Neural Network Pruning. In Proceedings of the International Conference on Learning Representations, Addis Ababa, Ethiopia, 26–30 April 2020. [Google Scholar]
Quantized Weight | Recoding Weight |
---|---|
01 | |
0 | 00 |
11 |
Quantized Weight | Recoding Weight |
---|---|
001 | |
010 | |
011 | |
0 | 000 |
111 | |
110 | |
101 |
CNN | Weight Decay | Momentum | Learning Rate | Batch Size |
---|---|---|---|---|
AlexNet | 0.0005 | 0.9 | 0.01 | 256 |
VGG-16 | 0.0005 | 0.9 | 0.01 | 128 |
ResNet-18 | 0.0005 | 0.9 | 0.01 | 128 |
ResNet-20 | 0.0001 | 0.9 | 0.1 | 256 |
ResNet-56 | 0.0001 | 0.9 | 0.1 | 128 |
GoogLeNet | 0.0002 | 0.9 | 0.01 | 128 |
CNN | Method | Top-1 Accuracy | Top-5 Accuracy | Decrease in Top-1/Top-5 Error |
---|---|---|---|---|
AlexNet | Baseline | 82.96% | 99.09% | |
GSNQ | 80.95% | 98.71% | −2.01%/−0.38% | |
APTQ | 82.25% | 99.01% | −0.71%/−0.08% | |
VGG-16 | Baseline | 88.74% | 99.59% | |
GSNQ | 87.14% | 99.28% | −1.60%/−0.31% | |
APTQ | 88.18% | 99.46% | −0.56%/−0.13% | |
ResNet-18 | Baseline | 89.72% | 99.69% | |
GSNQ | 88.91% | 99.40% | −0.81%/−0.29% | |
APTQ | 89.20% | 99.60% | −0.52%/−0.09% | |
ResNet-20 | Baseline | 91.60% | 99.76% | |
GSNQ | 90.91% | 99.61% | −0.69%/−0.15% | |
APTQ | 91.21% | 99.66% | −0.39%/−0.10% | |
ResNet-56 | Baseline | 93.20% | 99.80% | |
GSNQ | 92.92% | 99.69% | −0.28%/−0.11% | |
APTQ | 93.07% | 99.74% | −0.13%/−0.06% | |
GoogLeNet | Baseline | 90.04% | 99.91% | |
GSNQ | 89.02% | 99.66% | −1.02%/−0.25% | |
APTQ | 89.63% | 99.75% | −0.41%/−0.16% |
CNN | Method | Top-1 Accuracy | Top-5 Accuracy | Decrease in Top-1/Top-5 Error |
---|---|---|---|---|
AlexNet | Baseline | 70.11% | 88.18% | |
GSNQ | 67.12% | 87.77% | −2.99%/−0.41% | |
APTQ | 68.99% | 88.18% | −1.12%/0.00% | |
VGG-16 | Baseline | 72.03% | 91.25% | |
GSNQ | 70.00% | 90.85% | −2.03%/−0.40% | |
APTQ | 71.11% | 91.10% | −0.92%/−0.15% | |
ResNet-18 | Baseline | 74.16% | 91.96% | |
GSNQ | 73.17% | 91.40% | −0.99%/−0.56% | |
APTQ | 73.79% | 91.71% | −0.37%/−0.25% | |
GoogLeNet | Baseline | 76.68% | 92.01% | |
GSNQ | 75.52% | 91.58% | −1.16%/−0.43% | |
APTQ | 75.98% | 91.95% | −0.70%/−0.06% |
CNN | Method | Top-1 Accuracy | Top-5 Accuracy | Decrease in Top-1/Top-5 Error |
---|---|---|---|---|
AlexNet | Baseline | 61.21% | 86.99% | |
GSNQ | 59.03% | 84.65% | −2.18%/−0.51% | |
APTQ | 60.49% | 84.99% | −0.72%/−0.20% | |
VGG-16 | Baseline | 75.09% | 91.56% | |
GSNQ | 73.51% | 90.01% | −1.58%/−1.55% | |
APTQ | 74.66% | 90.52% | −0.43%/−1.04% | |
ResNet-18 | Baseline | 76.76% | 92.16% | |
GSNQ | 75.19% | 91.06% | −1.57%/−1.10% | |
APTQ | 75.98% | 92.00% | −0.78%/−0.16% | |
GoogLeNet | Baseline | 78.91% | 93.10% | |
GSNQ | 77.89% | 92.61% | −1.02%/−0.49% | |
APTQ | 78.29% | 92.96% | −0.62%/−0.14% |
CNN | Method | Top-1 Accuracy | Decrease in Top-1 Error |
---|---|---|---|
VGG-16 | Baseline | 88.74% | |
TWN | 86.19% | −2.55% | |
DSQ | 88.09% | −0.65% | |
LQ-Net | 88.00% | −0.74% | |
APTQ | 88.18% | −0.56% | |
ResNet-18 | Baseline | 89.72% | |
TWN | 87.11% | −2.61% | |
LQ-Net | 87.16% | −2.56% | |
DSQ | 89.25% | −0.47% | |
APTQ | 89.20% | −0.52% | |
ResNet-20 | Baseline | 91.60% | |
DoReFa-Net | 88.20% | −3.40% | |
PACT | 89.70% | −1.90% | |
LQ-Net | 90.20% | −1.40% | |
ProxQuant | 90.06% | −1.54% | |
APoT | 91.00% | −0.60% | |
CSQ | 91.22% | −0.38% | |
APTQ | 91.21% | −0.39% | |
ResNet-56 | Baseline | 93.20% | |
PACT | 92.50% | −0.70% | |
APoT | 92.90% | −0.30% | |
APTQ | 93.07% | −0.13% |
ResNet-20 | TWN | LQ-Net | APoT | GSNQ | APTQ |
---|---|---|---|---|---|
L2 Distance | 12.15 | 11.30 | 11.31 | 10.65 | 9.38 |
CNN | Method | Top-1 Accuracy | ||
---|---|---|---|---|
5-bit | 4-bit | 3-bit | ||
ResNet-20 (baseline: 91.60%) | DoReFa-Net | — | 90.5% | 89.9% |
PACT | — | 91.7% | 91.1% | |
LQ-Net | — | — | 91.6% | |
APoT | — | 92.3% | 92.2% | |
GSNQ | — | 92.42% | 91.96% | |
APQ | 92.42% | 92.36% | 92.16% | |
ResNet-56 (baseline: 93.20%) | APoT | — | 94.0% | 93.9% |
GSNQ | — | 94.0% | 93.62% | |
APQ | 93.99% | 93.88% | 93.67% |
CNNs | CNN Models Storage Space | ||
---|---|---|---|
Baseline | After APQ (3-Bit) | After APTQ (2-Bit) | |
VGG-16 | 114.4 Mb | 10.7 Mb | 7.2 Mb |
ResNet-20 | 4.5 Mb | 0.4 Mb | 0.3 Mb |
ResNet-56 | 14.2 Mb | 1.3 Mb | 0.9 Mb |
Modules | Bit Width | LUT | FF | DSP |
---|---|---|---|---|
Module 1: based on multiplication (implemented using on-chip DSP) | 8-bit | 428 | 392 | 9 |
Module 1: based on multiplication (implemented using on-chip DSP) | 3-bit | 250 | 268 | 9 |
Module 2: based on multiplication (implemented using on-chip LUT) | 3-bit | 402 | 226 | 0 |
Module 3: based on APQ | 3-bit | 263 | 237 | 0 |
Module 1: based on multiplication (implemented using on-chip DSP) | 2-bit | 158 | 191 | 9 |
Module 2: based on multiplication (implemented using on-chip LUT) | 2-bit | 262 | 158 | 0 |
Module 4: based on APTQ | 2-bit | 168 | 167 | 0 |
Modules | Bit Width | LUT | FF | DSP |
---|---|---|---|---|
Module 1: based on multiplication (implemented using on-chip DSP) | 8-bit | 14,548/8.46% | 11,226/3.27% | 288/32.00% |
Module 1: based on multiplication (implemented using on-chip DSP) | 3-bit | 8675/5.05% | 9332/2.71% | 288/32.00% |
Module 2: based on multiplication (implemented using on-chip LUT) | 3-bit | 14,028/8.16% | 7901/2.30% | 0/0.00% |
Module 3: based on APQ | 3-bit | 8510/4.95% | 8270/2.41% | 0/0.00% |
Module 1: based on multiplication (implemented using on-chip DSP) | 2-bit | 5243/3.05% | 6479/1.88% | 288/32.00% |
Module 2: based on multiplication (implemented using on-chip LUT) | 2-bit | 8475/4.93% | 5370/1.56% | 0/0.00% |
Module 4: based on APTQ | 2-bit | 5862/3.41% | 5799/1.69% | 0/0.00% |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Sui, X.; Lv, Q.; Ke, C.; Li, M.; Zhuang, M.; Yu, H.; Tan, Z. Adaptive Global Power-of-Two Ternary Quantization Algorithm Based on Unfixed Boundary Thresholds. Sensors 2024, 24, 181. https://doi.org/10.3390/s24010181
Sui X, Lv Q, Ke C, Li M, Zhuang M, Yu H, Tan Z. Adaptive Global Power-of-Two Ternary Quantization Algorithm Based on Unfixed Boundary Thresholds. Sensors. 2024; 24(1):181. https://doi.org/10.3390/s24010181
Chicago/Turabian StyleSui, Xuefu, Qunbo Lv, Changjun Ke, Mingshan Li, Ming** Zhuang, Haiyang Yu, and Zheng Tan. 2024. "Adaptive Global Power-of-Two Ternary Quantization Algorithm Based on Unfixed Boundary Thresholds" Sensors 24, no. 1: 181. https://doi.org/10.3390/s24010181