Home

Awesome

ECCV2022 Paper - Fine-grained Data Distribution Alignment for Post-Training Quantization paper

Requirements

Reproduce the Experiment Results

  1. The pre-trained model will be downloaded automatically. If the download process fails, please use the URL in the console to download manually.

  2. Randomly select one image per class to generate corresponding BNS centers, selected images will be formulating the calibration dataset, run:

    cd FDDA

    mkdir save_ImageNet

    CUDA_VISIBLE_DEVICES=0 python BNScenters.py --dataPath PathToImageNetDataset --model_name resnet18/mobilenet_w1/mobilenetv2_w1/regnetx_600m

    Noted that a model will generate corresponding BNS centers that can't be used by other model.

  3. Use FDDA to train a quantized model. Modify the qw, qa in imagenet_config.hocon to set desired bit-width. Modify the dataPath in imagenet_config.hocon to the path of ImageNet Dataset. For all layers are quantized to same bit-width, run:

    CUDA_VISIBLE_DEVICES=0 python main_DBNS_CBNS.py --model_name resnet18/mobilenet_w1/mobilenetv2_w1/regnetx_600m --conf_path imagenet_config.hocon --id=0

    For F8L8, run:

    CUDA_VISIBLE_DEVICES=0 python main_DBNS_CBNS_8F8L.py --model_name resnet18/mobilenet_w1/mobilenetv2_w1/regnetx_600m --conf_path imagenet_config.hocon --id=0

Evaluate Our Models

We also provide original (before the code clean up, thus, the logs will be a little messy.) training logs and trained models for test. They can be downloaded from here

Due to different remote servers have different hardware and software constraints, we use different versions of PyTorch to finish our experiments. Noted that the PyTorch version in test should be the same as the PyTorch version in train to fully recover the accuracy. Please use the PyTorch version in train in the first line of train_test.log.

To test our models, download it and then modify the qw, qa in imagenet_config.hocon to set desired bit-width. For all layers are quantized to same bit-width, run:

CUDA_VISIBLE_DEVICES=0 python test.py --conf_path imagenet_config.hocon --model_name resnet18/mobilenet_w1/mobilenetv2_w1/regnetx_600m --model_path PathToModel

For F8L8, run:

CUDA_VISIBLE_DEVICES=0 python test_8F8L.py --conf_path imagenet_config.hocon --model_name resnet18/mobilenet_w1/mobilenetv2_w1/regnetx_600m --model_path PathToModel

Following results can be obtained:

ModelBit-widthDatasetTop-1 Acc.
resnet18W4A4-F4L4ImageNet68.884%
resnet18W4A4-F8L8ImageNet69.758%
resnet18W5A5-F5L5ImageNet70.558%
resnet18W5A5-F8L8ImageNet70.864%
------------------------------------
mobilenetv1W4A4-F4L4ImageNet63.748%
mobilenetv1W4A4-F8L8ImageNet65.760%
mobilenetv1W5A5-F5L5ImageNet70.258%
mobilenetv1W5A5-F8L8ImageNet71.764%
------------------------------------
mobilenetv2W4A4-F4L4ImageNet68.382%
mobilenetv2W4A4-F8L8ImageNet69.322%
mobilenetv2W5A5-F5L5ImageNet71.63%
mobilenetv2W5A5-F8L8ImageNet71.99%
------------------------------------
regnetx600mW4A4-F4L4ImageNet68.960%
regnetx600mW4A4-F8L8ImageNet70.326%
regnetx600mW5A5-F5L5ImageNet73.620%
regnetx600mW5A5-F8L8ImageNet73.996%

Contact

For any question, be free to contact: viper.zhong@gmail.com. The github issue is also welcome.