Home

Awesome

Generative Data Free Model Quantization with Knowledge Matching for Classification

We provide PyTorch implementation for "Generative Data Free Model Quantization with Knowledge Matching for Classification".

<br/>

Dependencies

<br/>

Getting Started

Installation

  1. Clone this repo:

     git clone https://github.com/ZSHsh98/KMDFQ.git
     cd KMDFQ
    
  2. Install pytorch and other dependencies.

     pip install -r requirements.txt
    

Set the paths of datasets for testing

  1. Set the "dataPath" in "cifar100_resnet20.hocon" as the path root of your CIFAR-100 dataset. For example:

     dataPath = "/home/datasets/Datasets/cifar"
    
  2. Set the "dataPath" in "imagenet_resnet18.hocon" as the path root of your ImageNet dataset. For example:

     dataPath = "/home/datasets/Datasets/imagenet"
    

Training

To quantize the pretrained ResNet-20 on CIFAR-10 to 4-bit:

python main.py 
--conf_path ./cifar10_resnet20.hocon \
--id 1 \
--CE_WEIGHT 1 \
--BNS_WEIGHT 1 \ 
--FEATURE_WEIGHT 1  
--warmup_epochs 20 \ 
--visible_devices 0 \
--qw 4 \
--qa 4

To quantize the pretrained ResNet-20 on CIFAR-100 to 5-bit:

python main.py 
--conf_path ./cifar100_resnet20.hocon \
--id 1 \
--CE_WEIGHT 1 \
--BNS_WEIGHT 1 \ 
--FEATURE_WEIGHT 1  
--warmup_epochs 20 \ 
--visible_devices 0 \
--qw 5 \
--qa 5

To quantize the pretrained ResNet-18 on ImageNet to 6-bit:

python main.py 
--conf_path ./imagenet_resnet18.hocon \
--id 1 \
--CE_WEIGHT 1 \
--BNS_WEIGHT 1  \
--FEATURE_WEIGHT 1 \
--warmup_epochs 50 \
--visible_devices 6 \
--selenet resnet18 \
--qw 6 \
--qa 6
<br/>

Results

DatasetModelPretrain Top1 Acc(%)W8A8W6A6W5A5W4A4
CIFAR-10ResNet-2093.8994.0593.9493.6792.24
CIFAR-100ResNet-2070.3370.5370.3569.6867.15
ImageNetResNet-1871.5870.7370.6169.9364.39
ImageNetBN-VGG1674.3872.3372.2971.8968.79
ImageNetInception v377.6376.4576.4375.5471.22
ImageNetMobileNet v273.0872.5872.2171.0363.48
ImageNetShuffleNet65.1661.9060.9556.7328.26
ImageNetResNet-5077.7677.5077.2175.6768.84

Note that we use the pretrained models from pytorchcv.

Citation

If this work is useful for your research, please cite our paper:

@article{xu2023KMDFQ,
title = {Generative Data Free Model Quantization with Knowledge Matching for Classification},
author = {Shoukai Xu, Shuhai Zhang, Jing Liu, Bohan Zhuang, Yaowei Wang , Mingkui Tan},
journal={IEEE Transactions on Circuits and Systems for Video technology},
publisher={IEEE},
year = {2023}
}