Quantization for deep learning is the process of approximating a neural network that uses floating-point numbers by a neural network of low bit width numbers. This dramatically reduces both the memory requirement and computational cost of using neural networks.
In this repository, I have implemented static quantization strategy for Alexnet, MobileNet and Resnet-50 trained on a Retina based Diabetes Classification dataset and also have proven the benefits occuring from doing so by giving relevant statistics and evaluation metrics.
To install requirements:
pip install -r requirements.txt
Download the dataset from the links given below.
- Download the dataset from the link above.
- Be sure to change the file directory paths in all the required places as per your convenience.
- Run the quant python files to train your model on the diabetes classification dataset.
- Both the normal model and the quantized models will be saved in the events folder, the predictions in the predictions folder and event logs in the event folder.
- Statistics such as Accuracy, Model size and CPU inference latency are all in built for evaluation in the quant python files.
From the statistics given below, my quantization strategy reduced the model size, and the inference latency multiple folds while maintaining the accuracy of the model without any noticeble decline.
Model | Top 1 Acc (%) | Model size | CPU Inference Latency |
---|---|---|---|
Alexnet | 42.537 | 90 MB | 37.94 ms/sample |
Quantized Alexnet | 42.537 | 23.2 MB | 29.65 ms/sample |
Model | Top 1 Acc (%) | Model size | CPU Inference Latency |
---|---|---|---|
MobileNet | 58.46 | 8.7 MB | 10.23 ms/sample |
Quantized MobileNet | 58.41 | 2.8 MB | 6.27 ms/sample |
Model | Top 1 Acc (%) | Model size | CPU Inference Latency |
---|---|---|---|
Resnet50 | 62.44 | 90 MB | 162.19 ms/sample |
Quantized Resnet50 | 63.41 | 23.2 MB | 101.07 ms/sample |
Pretrained models for the all the mentioned models can be downloaded from this link for inference.
For any queries, feel free to contact at vignesh.nitt10@gmail.com.