Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
734a9eea
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
734a9eea
编写于
9月 07, 2017
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct the definition of Operator in TestFCGradOp, and rename the output name
of identity to Y.
上级
3285b00d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
32 addition
and
28 deletion
+32
-28
paddle/operators/fc_op.cc
paddle/operators/fc_op.cc
+12
-12
paddle/operators/identity_op.cc
paddle/operators/identity_op.cc
+2
-2
paddle/operators/minus_op.cc
paddle/operators/minus_op.cc
+1
-1
python/paddle/v2/framework/tests/CMakeLists.txt
python/paddle/v2/framework/tests/CMakeLists.txt
+1
-0
python/paddle/v2/framework/tests/gradient_checker.py
python/paddle/v2/framework/tests/gradient_checker.py
+0
-4
python/paddle/v2/framework/tests/test_fc_op.py
python/paddle/v2/framework/tests/test_fc_op.py
+12
-5
python/paddle/v2/framework/tests/test_minus_op.py
python/paddle/v2/framework/tests/test_minus_op.py
+2
-2
python/paddle/v2/framework/tests/test_scale_and_identity_op.py
...n/paddle/v2/framework/tests/test_scale_and_identity_op.py
+2
-2
未找到文件。
paddle/operators/fc_op.cc
浏览文件 @
734a9eea
...
...
@@ -24,30 +24,30 @@ class FCOp : public NetOp {
const
framework
::
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
// mul_out = X * W
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"mul"
,
{{
"X"
,
{
Input
(
"X"
)}},
{
"Y"
,
{
Input
(
"W"
)}}},
{{
"Out"
,
{
Output
(
"mul_out"
)}}},
{}));
std
::
string
add_out_name
=
"mul_out"
;
auto
b
=
Input
(
"b"
);
if
(
b
!=
framework
::
kEmptyVarName
)
{
// add_out = mul_out + b
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"rowwise_add"
,
{{
"X"
,
{
Output
(
"mul_out"
)}},
{
"b"
,
{
Input
(
"b"
)}}},
{{
"Out"
,
{
Output
(
"add_out"
)}}},
{}));
add_out_name
=
"add_out"
;
}
else
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"identity"
,
{{
"X"
,
{
Output
(
"mul_out"
)}}},
{{
"Out"
,
{
Output
(
"add_out"
)}}},
{}));
auto
add_out
=
Output
(
"add_out"
);
if
(
add_out
!=
framework
::
kEmptyVarName
)
{
this
->
Rename
(
add_out
,
framework
::
kEmptyVarName
);
}
}
auto
activation
=
GetAttr
<
std
::
string
>
(
"activation"
);
if
(
activation
==
"identity"
)
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
Output
(
"add_out"
)}}},
{{
"Out"
,
{
Output
(
"Out"
)}}},
{}));
}
else
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
Output
(
"add_out"
)}}},
{{
"Y"
,
{
Output
(
"Out"
)}}},
{}));
}
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
activation
,
{{
"X"
,
{
Output
(
add_out_name
)}}},
{{
"Y"
,
{
Output
(
"Out"
)}}},
{}));
CompleteAddOp
(
false
);
}
};
...
...
paddle/operators/identity_op.cc
浏览文件 @
734a9eea
...
...
@@ -27,7 +27,7 @@ class IdentityOpMaker : public framework::OpProtoAndCheckerMaker {
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"input tensor of identity op"
);
AddOutput
(
"
Out
"
,
"output tensor of identity op"
);
AddOutput
(
"
Y
"
,
"output tensor of identity op"
);
AddComment
(
"identity operator. Just a alias of scale op which scale = 1.0"
);
}
};
...
...
@@ -40,7 +40,7 @@ class IdentityOp : public NetOp {
const
framework
::
AttributeMap
&
attrs
)
:
NetOp
(
type
,
inputs
,
outputs
,
attrs
)
{
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"scale"
,
{{
"X"
,
{
Input
(
"X"
)}}},
{{
"Out"
,
{
Output
(
"
Out
"
)}}},
"scale"
,
{{
"X"
,
{
Input
(
"X"
)}}},
{{
"Out"
,
{
Output
(
"
Y
"
)}}},
{{
"scale"
,
static_cast
<
AttrType
>
(
1
)}}));
CompleteAddOp
(
false
);
}
...
...
paddle/operators/minus_op.cc
浏览文件 @
734a9eea
...
...
@@ -65,7 +65,7 @@ class MinusGradOp : public NetOp {
// x_grad = out_grad
AppendOp
(
framework
::
OpRegistry
::
CreateOp
(
"identity"
,
{{
"X"
,
{
out_grad
}}},
{{
"
Out
"
,
{
x_grad
}}},
{}));
{{
"
Y
"
,
{
x_grad
}}},
{}));
framework
::
AttributeMap
scale_attr
;
scale_attr
[
"scale"
]
=
static_cast
<
AttrType
>
(
-
1
);
...
...
python/paddle/v2/framework/tests/CMakeLists.txt
浏览文件 @
734a9eea
...
...
@@ -18,6 +18,7 @@ py_test(test_gather_op SRCS test_gather_op.py)
py_test
(
test_scatter_op SRCS test_scatter_op.py
)
py_test
(
test_fill_zeros_like_op SRCS test_fill_zeros_like_op.py
)
py_test
(
test_fc_op SRCS test_fc_op.py
)
py_test
(
test_minus_op SRCS test_minus_op.py
)
py_test
(
gradient_checker SRCS gradient_checker.py
)
...
...
python/paddle/v2/framework/tests/gradient_checker.py
浏览文件 @
734a9eea
...
...
@@ -277,10 +277,6 @@ class GradientChecker(unittest.TestCase):
if
no_grad_set
is
None
:
no_grad_set
=
set
()
no_tmp_out
=
forward_op
.
no_intermediate_outputs
()
if
len
(
no_tmp_out
)
!=
1
:
raise
ValueError
(
"non temp out_names should be 1"
)
inputs
=
forward_op
.
inputs
()
in_names
=
[
item
for
k
in
inputs
for
item
in
inputs
[
k
]]
for
no_grad
in
no_grad_set
:
...
...
python/paddle/v2/framework/tests/test_fc_op.py
浏览文件 @
734a9eea
...
...
@@ -29,13 +29,20 @@ class TestFCOp(unittest.TestCase):
class
TestFCGradOp
(
GradientChecker
):
def
test_normal
(
self
):
self
.
inputs
=
{
"X"
:
np
.
random
.
random
((
4
,
4
)).
astype
(
"float32"
),
"W"
:
np
.
random
.
random
((
4
,
4
)).
astype
(
"float32"
),
"b"
:
np
.
random
.
random
(
4
).
astype
(
"float32"
)
"X"
:
np
.
random
.
random
((
32
,
256
)).
astype
(
"float32"
),
"W"
:
np
.
random
.
random
((
256
,
100
)).
astype
(
"float32"
),
"b"
:
np
.
random
.
random
(
100
).
astype
(
"float32"
)
}
op
=
Operator
(
"fc"
,
X
=
"X"
,
W
=
"W"
,
b
=
"b"
,
Out
=
"Out"
,
activation
=
"sigmoid"
)
#self.check_grad(op, self.inputs, ["X", "W", "b"], "Out")
"fc"
,
X
=
"X"
,
W
=
"W"
,
b
=
"b"
,
Out
=
"Out"
,
mul_out
=
"mul_out"
,
add_out
=
"add_out"
,
activation
=
"sigmoid"
)
self
.
check_grad
(
op
,
self
.
inputs
,
[
"X"
,
"W"
,
"b"
],
"Out"
)
if
__name__
==
'__main__'
:
...
...
python/paddle/v2/framework/tests/test_minus_op.py
浏览文件 @
734a9eea
...
...
@@ -4,7 +4,7 @@ from gradient_checker import GradientChecker, create_op
from
op_test_util
import
OpTestMeta
class
MinusOpTest
(
unittest
.
TestCase
):
class
TestMinusOp
(
unittest
.
TestCase
):
__metaclass__
=
OpTestMeta
def
setUp
(
self
):
...
...
@@ -16,7 +16,7 @@ class MinusOpTest(unittest.TestCase):
self
.
outputs
=
{
'Out'
:
(
self
.
inputs
[
'X'
]
-
self
.
inputs
[
'Y'
])}
class
MinusGradTest
(
GradientChecker
):
class
TestMinusGrad
(
GradientChecker
):
def
test_left
(
self
):
op
=
create_op
(
"minus"
)
inputs
=
{
...
...
python/paddle/v2/framework/tests/test_scale_and_identity_op.py
浏览文件 @
734a9eea
...
...
@@ -11,14 +11,14 @@ class IdentityTest(unittest.TestCase):
def
setUp
(
self
):
self
.
type
=
"identity"
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
32
,
784
)).
astype
(
"float32"
)}
self
.
outputs
=
{
'
Out
'
:
self
.
inputs
[
'X'
]}
self
.
outputs
=
{
'
Y
'
:
self
.
inputs
[
'X'
]}
class
IdentityGradOpTest
(
GradientChecker
):
def
test_normal
(
self
):
op
=
create_op
(
"identity"
)
inputs
=
{
"X"
:
np
.
random
.
random
((
10
,
10
)).
astype
(
"float32"
)}
self
.
check_grad
(
op
,
inputs
,
set
(
"X"
),
"
Out
"
)
self
.
check_grad
(
op
,
inputs
,
set
(
"X"
),
"
Y
"
)
class
ScaleTest
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录