From 20fc2ca24029e9c2a86bb9a513bb40793eb8cbea Mon Sep 17 00:00:00 2001 From: chenzhuo Date: Sat, 17 Apr 2021 16:56:10 +0800 Subject: [PATCH] fix momentum of batchnorm in quantization --- mindspore/compression/quant/qat.py | 6 +++--- mindspore/nn/layer/quant.py | 2 +- model_zoo/official/cv/yolov3_darknet53_quant/src/darknet.py | 2 +- model_zoo/official/cv/yolov3_darknet53_quant/src/yolo.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mindspore/compression/quant/qat.py b/mindspore/compression/quant/qat.py index 57d2f1b9ffa..95ea298a39e 100644 --- a/mindspore/compression/quant/qat.py +++ b/mindspore/compression/quant/qat.py @@ -316,7 +316,7 @@ class QuantizationAwareTraining(Quantizer): dilation=conv_inner.dilation, group=conv_inner.group, eps=bn_inner.eps, - momentum=bn_inner.momentum, + momentum=1 - bn_inner.momentum, has_bias=conv_inner.has_bias, bias_init=conv_inner.bias_init, quant_config=self.quant_config, @@ -332,7 +332,7 @@ class QuantizationAwareTraining(Quantizer): dilation=conv_inner.dilation, group=conv_inner.group, eps=bn_inner.eps, - momentum=bn_inner.momentum, + momentum=1 - bn_inner.momentum, has_bias=conv_inner.has_bias, bias_init=conv_inner.bias_init, freeze_bn=self.freeze_bn, @@ -358,7 +358,7 @@ class QuantizationAwareTraining(Quantizer): dilation=conv_inner.dilation, group=conv_inner.group, eps=bn_inner.eps, - momentum=bn_inner.momentum, + momentum=1 - bn_inner.momentum, has_bias=conv_inner.has_bias, bias_init=conv_inner.bias_init, quant_config=self.quant_config, diff --git a/mindspore/nn/layer/quant.py b/mindspore/nn/layer/quant.py index 6b20e25f3e2..4abc23d7485 100644 --- a/mindspore/nn/layer/quant.py +++ b/mindspore/nn/layer/quant.py @@ -496,7 +496,7 @@ class Conv2dBnFoldQuantOneConv(Cell): self.dilation = twice(dilation) self.group = group self.eps = eps - self.momentum = momentum + self.momentum = 1 - momentum self.has_bias = has_bias self.fake = fake self.quant_config = quant_config diff --git a/model_zoo/official/cv/yolov3_darknet53_quant/src/darknet.py b/model_zoo/official/cv/yolov3_darknet53_quant/src/darknet.py index 0cfcd43a687..adc207f8ddd 100644 --- a/model_zoo/official/cv/yolov3_darknet53_quant/src/darknet.py +++ b/model_zoo/official/cv/yolov3_darknet53_quant/src/darknet.py @@ -32,7 +32,7 @@ def conv_block(in_channels, padding=padding, dilation=dilation, has_bn=True, - momentum=0.1, + momentum=0.9, activation='relu') diff --git a/model_zoo/official/cv/yolov3_darknet53_quant/src/yolo.py b/model_zoo/official/cv/yolov3_darknet53_quant/src/yolo.py index dad97b3f4fb..d62f1dd9330 100644 --- a/model_zoo/official/cv/yolov3_darknet53_quant/src/yolo.py +++ b/model_zoo/official/cv/yolov3_darknet53_quant/src/yolo.py @@ -36,7 +36,7 @@ def _conv_bn_relu(in_channel, padding=0, dilation=1, alpha=0.1, - momentum=0.9, + momentum=0.1, eps=1e-5, pad_mode="same"): """Get a conv2d batchnorm and relu layer"""