Skip to content

Repository files navigation

EasyQuant: Post-training Quantization via Scale Optimization

EasyQuant(EQ) is an efficient and simple post-training quantization method via effectively optimizing the scales of weights and activations. Our paper is available on arXiv

Requirements

eq-ncnn

caffe

pip install -r requirements.txt

Updates:

  • 06/25/2020: We have released EasyQuant.pdf paper and eq-ncnn.
  • 06/24/2020: We have released VGG16 example.

Data Preparation

First, for ImageNet1k classification task, please download ImageNet2012. We random sampled 3000 calibration images from ImageNet val set to data/calib.txt for KLD quantization and select 50 samples from calib to data/list50.txt for EasyQuant scale finetuning. Then we will evaluate quantified models on val set.

How to Run

  1. Get caffe and ncnn ready
  2. Build python_ncnn
# cd python_ncnn
# modify ncnn build path in Makefile
make -j8
  1. Run VGG16 example
cd ..
sh example/vgg16/run.sh

This following 6 steps will be performed in run.sh.

# download vgg16 model and upgrade proto and caffemodel files
sh model/vgg16/net_file_upgrade.sh
# generate scale of weight and activation use quantation tools
sh example/vgg16/run_scale_quantation.sh
# get ncnn param bin from scale table
sh example/vgg16/run_caffe2ncnn.sh
# infer layer blob shape
sh example/vgg16/run_infer_shape.sh
# run scale fine tuning
sh example/vgg16/run_scale_fine_tuning.sh
# run validtion on imagenet val
sh example/vgg16/run_validation.sh

Results

Validation Results

1. Classification on ImageNet2012 validation dataset for different convolutional models in context of both INT8 and INT7 post-training quantization.

ModelsFP32INT8-TRTINT8-EQINT7-TRTINT7-EQ
SqueezeNetV1.156.5656.2456.2854.8856.08
MobileNetV169.3368.7468.8466.9768.26
VGG1670.9770.9570.9770.9270.96
ResNet5075.2075.0475.1372.7875.04

2. Object detection on VOC2007 task for SSD models with bachbone SqueezeNet and MobileNet V1.

ModelsFP32INT8-TRTINT8-EQINT7-TRTINT7-EQ
SqueezeNet-SSD62.0061.4562.0560.0161.62
MobileNet-SSD72.0469.7971.3963.8868.79

3. Verification performance for InsightFace model MobileFaceNet on 7 most common validation dataset

ModelsFP32INT8-TRTINT8-EQINT7-TRTINT7-EQ
lfw99.4599.3699.4899.2899.36
agedb_3095.7895.2395.3895.0395.73
calfw95.0594.7694.8894.7594.68
cfp_ff99.5099.5099.6199.4499.60
cfp_fp89.7789.1790.0488.4789.87
cplfw86.4585.5886.0385.9186.76
vgg2_fp90.6489.7090.5089.6490.44

4. Compare our method with more complex QAT(quantization aware trainin) approach in 8 bit width.

MethodsMobileNetV1-FP32MobileNetV1-INT8ResNet50-FP32ResNet50-INT8
EQ69.3368.8475.2075.13
QAT70.9070.7075.2075.00

Speed Tests

INT7 Post-training Inference VS INT8 on real devices. We implement our efficient designs on INT7 post-training inference which well be released in eq-ncnn

1. The latency (ms) performance on RK3399, whose inside is a 1.5 GHz 64-bit Quad-core ARM Cortex-A53. #k means k threads.

ModelsTRT-INT8(#1)EQ-INT7(#1)TRT-INT8(#4)EQ-INT7(#4)
SqueezeNetV1.11801206644
MobileNetV12341896557
VGG163326287314231252
ResNet501264993415300

2. The latency (ms) performance on RK3399, which inside is a 1.8 GHz 64-bit Dual-core ARM Cortex-A72. #k means k threads.

ModelsTRT-INT8(#1)EQ-INT7(#1)TRT-INT8(#2)EQ-INT7(#2)
SqueezeNetV1.179575437
MobileNetV1105845646
VGG16165913851034849
ResNet50559463338262

Contributing

PRs accepted.

License and Citation

BSD3 © DeepGlint

@inproceedings{easyquant,
title={EasyQuant: Post-training Quantization via Scale Optimization},
author={Di Wu, Qi Tang, Yongle Zhao, Ming Zhang, Debing Zhang, Ying Fu},
year={2020}
}

About

EasyQuant(EQ) is an efficient and simple post-training quantization method via effectively optimizing the scales of weights and activations.

Resources

Stars

407 stars

Watchers

15 watching

Forks

Releases

Packages

Used by

Contributors

Languages