PaddleDetection icon indicating copy to clipboard operation
PaddleDetection copied to clipboard

is it possible to perform QAT on pruned models?

Open ichbing1 opened this issue 5 years ago • 4 comments

Hi,

I trained a pruned model with python tools/train.py --slim_config configs/slim/prune/ppyolo_r50vd_prune_fpgm.yml using a custom dataset.

For further acceleration, I applied int8 post-training quantization with 500 calibration images, but the detection accuracy got considerably worse than fp16 (about 4-5 mAP points lower).

To minimize the drop in accuracy, I would like to perform quantization-aware training on the pruned model, but it seems only one type of slim can be specified at training time.

Does current version of PaddleDetection or PaddleSlim support doing QAT on pruned models? For example, if it's possible to save the pruned model just like a normal model (.pdparams, .pdopt), then it would be possible to do QAT on it by using it as a pretrained model for further training. But I couldn't find a way to save the pruned model as files.

FYI, I'm using PaddleDetection release/2.1. Any advice would be greatly appreciated.

ichbing1 avatar Jul 02 '21 02:07 ichbing1

@ichbing1 Thanks for your feedback, now there is only a combined strategy of distillation and pruning in PaddleDetection, and we will support the combined strategy of pruning and quantification in the future. You can modify the code about slim to increase the mode of PruneQAT: https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/ppdet/slim/init.py#L50

yghstill avatar Jul 02 '21 05:07 yghstill

@ichbing1 Thanks for your feedback, now there is only a combined strategy of distillation and pruning in PaddleDetection, and we will support the combined strategy of pruning and quantification in the future. You can modify the code about slim to increase the mode of PruneQAT: https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/ppdet/slim/init.py#L50

Oh, I had originally thought of modifying the code before giving up, but looking at the code again, it does seem possible to modify it to make it work, by first calling cfg.pruner on the model, loading weights, and then setting cfg.slim = 'QAT' to slim the model. I also built a config file by combining pruning and QAT, and now the training works well. Thanks a lot for your help!

ichbing1 avatar Jul 02 '21 10:07 ichbing1

@ichbing1 你好,请问能具体分享一下你的做法吗?还有你的配置文件

LMR2018 avatar Jan 04 '22 10:01 LMR2018

@ichbing1 Thanks for your feedback, now there is only a combined strategy of distillation and pruning in PaddleDetection, and we will support the combined strategy of pruning and quantification in the future. You can modify the code about slim to increase the mode of PruneQAT: https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.1/ppdet/slim/init.py#L50

Oh, I had originally thought of modifying the code before giving up, but looking at the code again, it does seem possible to modify it to make it work, by first calling cfg.pruner on the model, loading weights, and then setting cfg.slim = 'QAT' to slim the model. I also built a config file by combining pruning and QAT, and now the training works well. Thanks a lot for your help!

Hello, I'm confused about modifying this code in init.py and config file , could you show me your modification ? Thanks a lot!

Jiashuhao518 avatar May 27 '22 11:05 Jiashuhao518