Quantizing YOLOv7: A Comprehensive Study

Mohammadamin Baghbanbashi,Mohsen Raji,Behnam Ghavami
DOI: https://doi.org/10.1109/CSICC58665.2023.10105310
2024-07-06
Abstract:YOLO is a deep neural network (DNN) model presented for robust real-time object detection following the one-stage inference approach. It outperforms other real-time object detectors in terms of speed and accuracy by a wide margin. Nevertheless, since YOLO is developed upon a DNN backbone with numerous parameters, it will cause excessive memory load, thereby deploying it on memory-constrained devices is a severe challenge in practice. To overcome this limitation, model compression techniques, such as quantizing parameters to lower-precision values, can be adopted. As the most recent version of YOLO, YOLOv7 achieves such state-of-the-art performance in speed and accuracy in the range of 5 FPS to 160 FPS that it surpasses all former versions of YOLO and other existing models in this regard. So far, the robustness of several quantization schemes has been evaluated on older versions of YOLO. These methods may not necessarily yield similar results for YOLOv7 as it utilizes a different architecture. In this paper, we conduct in-depth research on the effectiveness of a variety of quantization schemes on the pre-trained weights of the state-of-the-art YOLOv7 model. Experimental results demonstrate that using 4-bit quantization coupled with the combination of different granularities results in ~3.92x and ~3.86x memory-saving for uniform and non-uniform quantization, respectively, with only 2.5% and 1% accuracy loss compared to the full-precision baseline model.
Computer Vision and Pattern Recognition,Hardware Architecture,Machine Learning
What problem does this paper attempt to address?
This paper attempts to solve the high memory - occupancy problem faced by the YOLOv7 model in actual deployment. Specifically, although YOLOv7 performs excellently in terms of speed and accuracy, due to its deep neural network (DNN) architecture and containing millions of parameters, its deployment on memory - constrained devices is very challenging. To overcome this limitation, the author has studied different quantization methods to reduce the memory - occupancy of the model while maintaining the detection performance of the model as much as possible. ### Main problems 1. **High memory - occupancy**: Due to the large number of parameters in the YOLOv7 model, it is difficult to deploy on devices with limited memory. 2. **Effectiveness of quantization methods**: The previous research results on the early versions of YOLO are not necessarily applicable to YOLOv7, because YOLOv7 adopts different architectures and parameter precisions. ### Solutions The author solves the above problems through the following methods: - **Uniform Quantization**: Use affine quantization and symmetric quantization to compress the weights from 32 - bit floating - point numbers to lower - precision integers (such as 4 - bit integers). - **Non - uniform Quantization**: Adopt piece - wise linear quantization (PWLQ). This method can better adapt to the characteristics of the weight distribution and reduce quantization errors. - **Quantization Granularity at Different Levels**: Research quantization methods at different levels such as layer - level, filter - level, channel - level, F - shape - level and C - shape - level to find the best quantization strategy. ### Experimental results The experimental results show that: - Using 4 - bit affine quantization can achieve approximately 3.93 times of memory savings with only about 3.4% mAP loss. - Using 4 - bit PWLQ can achieve approximately 3.88 times of memory savings with only about 1.1% mAP loss. - Combining quantization methods at multiple levels can further balance memory savings and accuracy loss. ### Conclusion This research shows that the combination of quantization methods at filter - level, F - shape - level and C - shape - level is the best choice for deploying YOLOv7, especially for resource - constrained devices such as mobile CPUs/GPUs and FPGAs.