From 76c4ae856f3acc44ca427aeaaf35453a0f8407ae Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Fri, 27 Apr 2018 15:22:21 +0800 Subject: [PATCH] Fix reshape op. (#10253) --- paddle/fluid/operators/reshape_op.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/operators/reshape_op.h b/paddle/fluid/operators/reshape_op.h index 8320c257c9a..44a91ebd7c2 100644 --- a/paddle/fluid/operators/reshape_op.h +++ b/paddle/fluid/operators/reshape_op.h @@ -93,8 +93,14 @@ class ReshapeOp : public framework::OperatorWithKernel { if (unk_dim_idx != -1) { output_shape[unk_dim_idx] = -in_size / capacity; - PADDLE_ENFORCE_EQ(output_shape[unk_dim_idx] * capacity, -in_size, - "Invalid shape is given."); + // in_size < 0 and is un-determinate in compile time, skip the check, + // for example, in_dims = [-1, 8, 1, 1], shape = [-1, 3, 8], + // capacity = -24, in_size = -8, output_shape[0] = 0 + // the following check will fail. + if (in_size > 0) { + PADDLE_ENFORCE_EQ(output_shape[unk_dim_idx] * capacity, -in_size, + "Invalid shape is given."); + } } else { PADDLE_ENFORCE_EQ(capacity, in_size, "Invalid shape is given."); } -- GitLab