From 0cef33a4683835553e2c212b5d37e345964c5938 Mon Sep 17 00:00:00 2001 From: chenweihang Date: Tue, 3 Jul 2018 06:08:32 +0000 Subject: [PATCH] adjust the dims range to [1,6] and fix some problem --- paddle/fluid/operators/squeeze_op.cc | 6 ++--- paddle/fluid/operators/squeeze_op.cu | 2 -- .../fluid/tests/unittests/test_squeeze_op.py | 26 +++++++++---------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/paddle/fluid/operators/squeeze_op.cc b/paddle/fluid/operators/squeeze_op.cc index 639480aba..29648cdd9 100644 --- a/paddle/fluid/operators/squeeze_op.cc +++ b/paddle/fluid/operators/squeeze_op.cc @@ -33,10 +33,10 @@ class SqueezeOp : public framework::OperatorWithKernel { "Output(Out) of SqueezeOp should not be null."); const auto& x_dims = ctx->GetInputDim("X"); - // Check input tensor dims (<9). - PADDLE_ENFORCE(x_dims.size() <= 9, + // Check input tensor dims (<6) Eigen limit. + PADDLE_ENFORCE(x_dims.size() <= 6, "Invalid dimnesions, dynamic dimensions must have " - "between [1, 9] dimensions."); + "between [1, 6] dimensions (Eigen limit)."); const auto& axes = ctx->Attrs().Get>("axes"); for (int a : axes) { diff --git a/paddle/fluid/operators/squeeze_op.cu b/paddle/fluid/operators/squeeze_op.cu index 1096907da..275257450 100644 --- a/paddle/fluid/operators/squeeze_op.cu +++ b/paddle/fluid/operators/squeeze_op.cu @@ -12,8 +12,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#define EIGEN_USE_GPU - #include "paddle/fluid/operators/squeeze_op.h" namespace ops = paddle::operators; diff --git a/python/paddle/fluid/tests/unittests/test_squeeze_op.py b/python/paddle/fluid/tests/unittests/test_squeeze_op.py index 58c87ea3c..6ef5204b7 100644 --- a/python/paddle/fluid/tests/unittests/test_squeeze_op.py +++ b/python/paddle/fluid/tests/unittests/test_squeeze_op.py @@ -27,7 +27,7 @@ class TestSqueezeOp1(OpTest): self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": False} + self.attrs = {"axes": axes, "inplace": False} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -46,7 +46,7 @@ class TestSqueezeOp2(OpTest): self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": False} + self.attrs = {"axes": axes, "inplace": False} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -65,7 +65,7 @@ class TestSqueezeOp3(OpTest): self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": False} + self.attrs = {"axes": axes, "inplace": False} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -78,13 +78,13 @@ class TestSqueezeOp3(OpTest): # Correct: Just part of axes be squeezed. class TestSqueezeOp4(OpTest): def setUp(self): - ori_shape = (1, 3, 1, 5, 1, 4, 1) - axes = (2, 6) - new_shape = (1, 3, 5, 1, 4) + ori_shape = (3, 1, 5, 1, 4, 1) + axes = (1, -1) + new_shape = (3, 5, 1, 4) self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": False} + self.attrs = {"axes": axes, "inplace": False} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -122,7 +122,7 @@ class TestSqueezeOpInplace2(OpTest): self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": True} + self.attrs = {"axes": axes, "inplace": True} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -141,7 +141,7 @@ class TestSqueezeOpInplace3(OpTest): self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": True} + self.attrs = {"axes": axes, "inplace": True} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): @@ -154,13 +154,13 @@ class TestSqueezeOpInplace3(OpTest): # Correct: Inpalce. Just part of axes be squeezed. class TestSqueezeOpInplace4(OpTest): def setUp(self): - ori_shape = (1, 3, 1, 5, 1, 4, 1) - axes = (2, 6) - new_shape = (1, 3, 5, 1, 4) + ori_shape = (3, 1, 5, 1, 4, 1) + axes = (1, -1) + new_shape = (3, 5, 1, 4) self.op_type = "squeeze" self.inputs = {"X": np.random.random(ori_shape).astype("float32")} - self.attrs = {"axes": axes, "inpalce": True} + self.attrs = {"axes": axes, "inplace": True} self.outputs = {"Out": self.inputs["X"].reshape(new_shape)} def test_check_output(self): -- GitLab