From e92705d810ad5f4562496baf56ae2b834cd13999 Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Mon, 12 Jul 2021 12:04:00 +0000 Subject: [PATCH 1/2] fix div 0 --- paddle/fluid/operators/batch_norm_op.cc | 9 +++++++++ paddle/fluid/operators/instance_norm_op.cc | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/paddle/fluid/operators/batch_norm_op.cc b/paddle/fluid/operators/batch_norm_op.cc index edad20435b41c9..e5e4029fa27bc5 100644 --- a/paddle/fluid/operators/batch_norm_op.cc +++ b/paddle/fluid/operators/batch_norm_op.cc @@ -55,6 +55,15 @@ void BatchNormOp::InferShape(framework::InferShapeContext *ctx) const { "Variance and VarianceOut should share the same memory")); const auto x_dims = ctx->GetInputDim("X"); + + PADDLE_ENFORCE_NE(framework::product(x_dims), 0, + platform::errors::PreconditionNotMet( + "The Input variable X(%s) has not " + "been initialized. You may need to confirm " + "if you put exe.run(startup_program) " + "after optimizer.minimize function.", + ctx->Inputs("X").front())); + const DataLayout data_layout = framework::StringToDataLayout( ctx->Attrs().Get("data_layout")); diff --git a/paddle/fluid/operators/instance_norm_op.cc b/paddle/fluid/operators/instance_norm_op.cc index 28643ac1c0d832..0a850400686c49 100644 --- a/paddle/fluid/operators/instance_norm_op.cc +++ b/paddle/fluid/operators/instance_norm_op.cc @@ -32,6 +32,13 @@ void InstanceNormOp::InferShape(framework::InferShapeContext *ctx) const { "InstanceNorm"); const auto x_dims = ctx->GetInputDim("X"); + PADDLE_ENFORCE_NE(framework::product(x_dims), 0, + platform::errors::PreconditionNotMet( + "The Input variable X(%s) has not " + "been initialized. You may need to confirm " + "if you put exe.run(startup_program) " + "after optimizer.minimize function.", + ctx->Inputs("X").front())); PADDLE_ENFORCE_GE( x_dims.size(), 2, platform::errors::InvalidArgument( From 64c85fd965b82520c7a393cca4986aaaf9ad57eb Mon Sep 17 00:00:00 2001 From: ceci3 <592712189@qq.com> Date: Wed, 18 Aug 2021 12:09:47 +0000 Subject: [PATCH 2/2] fix bn --- paddle/fluid/operators/batch_norm_op.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/paddle/fluid/operators/batch_norm_op.cc b/paddle/fluid/operators/batch_norm_op.cc index e5e4029fa27bc5..1e3fa044f32ab4 100644 --- a/paddle/fluid/operators/batch_norm_op.cc +++ b/paddle/fluid/operators/batch_norm_op.cc @@ -56,13 +56,14 @@ void BatchNormOp::InferShape(framework::InferShapeContext *ctx) const { const auto x_dims = ctx->GetInputDim("X"); - PADDLE_ENFORCE_NE(framework::product(x_dims), 0, - platform::errors::PreconditionNotMet( - "The Input variable X(%s) has not " - "been initialized. You may need to confirm " - "if you put exe.run(startup_program) " - "after optimizer.minimize function.", - ctx->Inputs("X").front())); + for (int i = 0; i < x_dims.size(); i++) { + PADDLE_ENFORCE_EQ( + (x_dims[i] == -1) || (x_dims[i] > 0), true, + platform::errors::InvalidArgument( + "Each dimension of input tensor is expected to be -1 or a " + "positive number, but recieved %d. Input's shape is [%s].", + x_dims[i], x_dims)); + } const DataLayout data_layout = framework::StringToDataLayout( ctx->Attrs().Get("data_layout"));