提交 4223ff8c 编写于 作者: L Liu Yiqun

Correct the key name of "mul" op in FCOp, and add some annotations for debug.

上级 70e60d73
...@@ -37,7 +37,7 @@ class FCOp : public NetOp { ...@@ -37,7 +37,7 @@ class FCOp : public NetOp {
// mul_out = X[0] * W[0] + ... + X[n-1] * W[n-1] // mul_out = X[0] * W[0] + ... + X[n-1] * W[n-1]
AppendOp( AppendOp(
framework::OpRegistry::CreateOp("mul", {{"X", {x[0]}}, {"W", {w[0]}}}, framework::OpRegistry::CreateOp("mul", {{"X", {x[0]}}, {"Y", {w[0]}}},
{{"Out", {Output("mul_out")}}}, {})); {{"Out", {Output("mul_out")}}}, {}));
for (int i = 1; i < n; i++) { for (int i = 1; i < n; i++) {
...@@ -68,6 +68,8 @@ class FCOp : public NetOp { ...@@ -68,6 +68,8 @@ class FCOp : public NetOp {
AppendOp(framework::OpRegistry::CreateOp( AppendOp(framework::OpRegistry::CreateOp(
activation, {{"X", {Output(add_out)}}}, {{"Y", {Output("Y")}}}, {})); activation, {{"X", {Output(add_out)}}}, {{"Y", {Output("Y")}}}, {}));
CompleteAddOp(false); CompleteAddOp(false);
std::cout << DebugString() << std::endl;
} }
}; };
......
...@@ -36,8 +36,8 @@ def create_op(scope, op_type, inputs, outputs, attrs=None): ...@@ -36,8 +36,8 @@ def create_op(scope, op_type, inputs, outputs, attrs=None):
var = scope.new_var(out_name) var = scope.new_var(out_name)
kwargs[out_name].append(out_name) kwargs[out_name].append(out_name)
for attr_name in Operator.get_op_attr_names(op_type): #for attr_name in Operator.get_op_attr_names(op_type):
kwargs[attr_name] = attrs[attr_name] # kwargs[attr_name] = attrs[attr_name]
return Operator(op_type, **kwargs) return Operator(op_type, **kwargs)
...@@ -186,14 +186,14 @@ class OpTest(unittest.TestCase): ...@@ -186,14 +186,14 @@ class OpTest(unittest.TestCase):
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
actual, expect, atol=1e-05), actual, expect, atol=1e-05),
"output name: " + out_name + "has diff") "output name: " + out_name + " has diff")
else: else:
actual = np.array(self.scope.find_var(out_name).get_tensor()) actual = np.array(self.scope.find_var(out_name).get_tensor())
expect = self.outputs[out_name] expect = self.outputs[out_name]
self.assertTrue( self.assertTrue(
np.allclose( np.allclose(
actual, expect, atol=1e-05), actual, expect, atol=1e-05),
"output name: " + out_name + "has diff") "output name: " + out_name + " has diff")
def check_output(self): def check_output(self):
places = [core.CPUPlace()] places = [core.CPUPlace()]
......
import unittest import unittest
import numpy as np import numpy as np
from op_test import OpTest from op_test import OpTest
import paddle.v2.framework.core as core
from paddle.v2.framework.op import Operator
class TestFCOp(OpTest): class TestFCOp(OpTest):
...@@ -37,8 +35,7 @@ class TestFCOp(OpTest): ...@@ -37,8 +35,7 @@ class TestFCOp(OpTest):
} }
def test_check_output(self): def test_check_output(self):
self.check_output(core.CPUPlace()) self.check_output()
self.check_output(core.GPUPlace(0))
#def test_check_grad(self): #def test_check_grad(self):
# self.check_grad(["X0", "X1", "W0", "W1", "b"], "Y") # self.check_grad(["X0", "X1", "W0", "W1", "b"], "Y")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册