From 207ab6cf0a664c4f94e375c3db368e4a0b7842d4 Mon Sep 17 00:00:00 2001 From: huangxu96 Date: Thu, 10 Sep 2020 02:57:19 +0000 Subject: [PATCH] Added save_quant_model function --- paddleslim/quant/dy_quanter.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/paddleslim/quant/dy_quanter.py b/paddleslim/quant/dy_quanter.py index 7b946362..4e0df284 100644 --- a/paddleslim/quant/dy_quanter.py +++ b/paddleslim/quant/dy_quanter.py @@ -133,4 +133,26 @@ def dy_quant_aware(model, imperative_qat.quantize(model) - return model \ No newline at end of file + return model + +def save_quant_model(model, + path, + input_shape, + input_dtype=['float32']): + + imperative_qat = ImperativeQuantAware( + weight_quantize_type='abs_max', + activation_quantize_type='moving_average_abs_max', + quantizable_layer_type=[ + 'Conv2D', 'Linear', 'ReLU', 'Pool2D', 'LeakyReLU' + ]) + + imperative_qat.save_quantized_model( + dirname=path, + model=model, + input_shape=input_shape, + input_dtype=['float32'], + feed=[0], + fetch=[0]) + + -- GitLab