You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/10/03 04:34:28 UTC
[GitHub] sandeep-krishnamurthy commented on a change in pull request #12625:
[MXNET-979] Add fix_beta support in BatchNorm
sandeep-krishnamurthy commented on a change in pull request #12625: [MXNET-979] Add fix_beta support in BatchNorm
URL: https://github.com/apache/incubator-mxnet/pull/12625#discussion_r222178605
##########
File path: src/operator/nn/batch_norm.cc
##########
@@ -164,18 +164,42 @@ void BatchNormForwardImpl(mshadow::Stream<cpu> *,
// note that var is still invstd
if (!param_.fix_gamma) {
- if (IsBNWriting(req[batchnorm::kData])) {
- ForEachFast(inputData, outputData, channel,
- [thisWeight, thisBias, thisMean, thisInvstd](const DType *in_data,
- DType *out_data) {
- *out_data = static_cast<DType>(
- ((*in_data - thisMean) * thisInvstd) * thisWeight + thisBias);
- });
+ if (!param_.fix_beta) {
+ // Case 1
+ // fix_gamma = False
+ // fix_beta = False
+ if (IsBNWriting(req[batchnorm::kData])) {
+ ForEachFast(inputData, outputData, channel,
+ [thisWeight, thisBias, thisMean, thisInvstd](const DType *in_data,
+ DType *out_data) {
+ *out_data = static_cast<DType>(
+ ((*in_data - thisMean) * thisInvstd) * thisWeight + thisBias);
+ });
+ }
+ } else {
+ // Case 2
+ // fix_gamma = False
+ // fix_beta = True
+ if (IsBNWriting(req[batchnorm::kBeta])) {
+ b[channel] = AccReal(0);
+ }
+ if (IsBNWriting(req[batchnorm::kData])) {
+ ForEachFast(inputData, outputData, channel,
+ [thisWeight, thisBias, thisMean, thisInvstd](const DType *in_data,
+ DType *out_data) {
+ *out_data = static_cast<DType>(
+ ((*in_data - thisMean) * thisInvstd) * thisWeight);
+ });
+ }
}
} else {
if (IsBNWriting(req[batchnorm::kGamma])) {
w[channel] = AccReal(1);
}
+ if (!param_.fix_beta) {
+ // Case 3
+ // fix_gamma = True
+ // fix_beta = False
if (IsBNWriting(req[batchnorm::kData])) {
Review comment:
fixed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services