From 669786bfe14690b5c9ee5aed8c271b2cabf6f2c6 Mon Sep 17 00:00:00 2001 From: QI JUN Date: Mon, 30 Oct 2017 17:49:08 -0700 Subject: [PATCH] refine square_error_cost layer (#5216) * reimplement pow operator * add pow_grad operator * fix code style * fix build error * fix op_test bug * revert pow operator * add FIXME comment --- paddle/operators/activation_op.h | 1 + python/paddle/v2/framework/layers.py | 5 +---- python/paddle/v2/framework/tests/op_test.py | 12 +++++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/paddle/operators/activation_op.h b/paddle/operators/activation_op.h index e4c6b2e09cd..ddd966e26c9 100644 --- a/paddle/operators/activation_op.h +++ b/paddle/operators/activation_op.h @@ -547,6 +547,7 @@ struct ELUGradFunctor : public BaseActivationFunctor { } }; +// FIXME(qijun) https://github.com/PaddlePaddle/Paddle/issues/5198 template struct PowFunctor : public BaseActivationFunctor { float factor; diff --git a/python/paddle/v2/framework/layers.py b/python/paddle/v2/framework/layers.py index 57723c4d5aa..70447e0d816 100644 --- a/python/paddle/v2/framework/layers.py +++ b/python/paddle/v2/framework/layers.py @@ -225,10 +225,7 @@ def square_error_cost(input, label, **kwargs): square_out = helper.create_tmp_variable(dtype=input.data_type) helper.append_op( - type='pow', - inputs={'X': [minus_out]}, - outputs={'Y': [square_out]}, - attrs={'factor': 2.0}) + type='square', inputs={'X': [minus_out]}, outputs={'Y': [square_out]}) return square_out diff --git a/python/paddle/v2/framework/tests/op_test.py b/python/paddle/v2/framework/tests/op_test.py index 50360e6e729..2e6710b5fcf 100644 --- a/python/paddle/v2/framework/tests/op_test.py +++ b/python/paddle/v2/framework/tests/op_test.py @@ -281,7 +281,8 @@ class OpTest(unittest.TestCase): type(sub_out)) for sub_out_name, expect in sub_out: idx = find_actual(sub_out_name, fetch_list) - actual_t = np.array(outs[idx]) + actual = outs[idx] + actual_t = np.array(actual) expect_t = expect[0] \ if isinstance(expect, tuple) else expect self.assertTrue( @@ -291,11 +292,12 @@ class OpTest(unittest.TestCase): str(place)) if isinstance(expect, tuple): self.assertListEqual( - actual_t.lod(), expect[1], "Output (" + sub_out_name - + ") has different lod at " + str(place)) + actual.lod(), expect[1], "Output (" + sub_out_name + + ") has different lod at " + str(place)) else: idx = find_actual(out_name, fetch_list) - actual_t = outs[idx] + actual = outs[idx] + actual_t = np.array(actual) expect = self.outputs[out_name] expect_t = expect[0] if isinstance(expect, tuple) else expect self.assertTrue( @@ -303,7 +305,7 @@ class OpTest(unittest.TestCase): actual_t, expect_t, atol=atol), "Output (" + out_name + ") has diff at " + str(place)) if isinstance(expect, tuple): - self.assertListEqual(actual_t.lod(), expect[1], + self.assertListEqual(actual.lod(), expect[1], "Output (" + out_name + ") has different lod at " + str(place)) -- GitLab