diff --git a/modules/dnn/src/layers/conv2_layer.cpp b/modules/dnn/src/layers/conv2_layer.cpp index 1cc436d32a..f8366c87ae 100644 --- a/modules/dnn/src/layers/conv2_layer.cpp +++ b/modules/dnn/src/layers/conv2_layer.cpp @@ -195,8 +195,11 @@ public: virtual bool fuseBatchNorm(const Ptr& bnlayer) override { BatchNorm2Layer* bn = dynamic_cast(bnlayer.get()); + // addResidual means the graph order is conv->add->bn: the residual is added + // before BN, but the conv applies the fused BN scale only to conv(x), not to + // the residual. Refuse so BN stays separate and runs on (conv + residual). if (fusedBatchNorm || !bn || bn->inputs.size() > 1 || - fastActivation != FAST_ACTIV_NONE || !activ.empty()) + fastActivation != FAST_ACTIV_NONE || !activ.empty() || addResidual) return false; fuseBatchNormWeights(bn); fusedBatchNorm = true;