diff --git a/python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py b/python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py index 3926ee95036aaf47d6b3f719d2e2696bf5f79093..f1da3990a36be89c966f5f495fc713192ad46d2c 100644 --- a/python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py +++ b/python/paddle/fluid/contrib/slim/quantization/post_training_quantization.py @@ -657,7 +657,7 @@ class PostTrainingQuantization(object): s += 0.02 bins = 2**(self._activation_bits - 1) - 1 if self._onnx_format: - quant_var = np.clip(distribution(var_tensor / scale * bins), + quant_var = np.clip(np.round(var_tensor / scale * bins), -bins - 1, bins) quant_dequant_var = quant_var / bins * scale else: @@ -701,7 +701,7 @@ class PostTrainingQuantization(object): s += 0.02 bins = 2**(self._activation_bits - 1) - 1 if self._onnx_format: - quant_var = np.clip(distribution(var_tensor / scale * bins), + quant_var = np.clip(np.round(var_tensor / scale * bins), -bins - 1, bins) quant_dequant_var = quant_var / bins * scale else: diff --git a/python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py b/python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py index 9c076d85fd2d58f9333494478a69baa908f93828..25707d0c8c91ef7b4a39ae2862d64961a422bebb 100644 --- a/python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py +++ b/python/paddle/fluid/contrib/slim/tests/test_post_training_quantization_mobilenetv1.py @@ -425,7 +425,7 @@ class TestPostTrainingAvgONNXFormatForMobilenetv1(TestPostTrainingQuantization): def test_post_training_onnx_format_mobilenetv1(self): model = "MobileNet-V1" - algo = "avg" + algo = "emd" round_type = "round" data_urls = [ 'http://paddle-inference-dist.bj.bcebos.com/int8/mobilenetv1_int8_model.tar.gz'