Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
81a352af
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
81a352af
编写于
7月 20, 2017
作者:
D
dongzhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"test fc without gradient"
上级
14424f31
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
32 addition
and
9 deletion
+32
-9
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+1
-1
paddle/framework/net.cc
paddle/framework/net.cc
+0
-2
paddle/framework/net_op_test.cc
paddle/framework/net_op_test.cc
+11
-5
paddle/framework/op_registry.h
paddle/framework/op_registry.h
+7
-1
paddle/operators/softmax_op.cc
paddle/operators/softmax_op.cc
+13
-0
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
81a352af
...
@@ -29,4 +29,4 @@ add_dependencies(framework_py_proto framework_py_proto_init)
...
@@ -29,4 +29,4 @@ add_dependencies(framework_py_proto framework_py_proto_init)
proto_library
(
net_proto SRCS net_proto.proto DEPS op_proto
)
proto_library
(
net_proto SRCS net_proto.proto DEPS op_proto
)
# cc_library(net SRCS net.cc DEPS operator net_proto op_registry fc_op)
# cc_library(net SRCS net.cc DEPS operator net_proto op_registry fc_op)
cc_library
(
net SRCS net.cc DEPS operator net_proto op_registry
)
cc_library
(
net SRCS net.cc DEPS operator net_proto op_registry
)
cc_test
(
net_op_test SRCS net_op_test.cc DEPS net add_op mul_op sigmoid_op
)
cc_test
(
net_op_test SRCS net_op_test.cc DEPS net add_op mul_op sigmoid_op
softmax_op fc_op
)
paddle/framework/net.cc
浏览文件 @
81a352af
...
@@ -22,8 +22,6 @@ namespace framework {
...
@@ -22,8 +22,6 @@ namespace framework {
std
::
shared_ptr
<
PlainNet
>
AddBackwardOp
(
std
::
shared_ptr
<
PlainNet
>
ForwardOps
)
{
std
::
shared_ptr
<
PlainNet
>
AddBackwardOp
(
std
::
shared_ptr
<
PlainNet
>
ForwardOps
)
{
auto
grad_ops
=
std
::
make_shared
<
PlainNet
>
();
auto
grad_ops
=
std
::
make_shared
<
PlainNet
>
();
// std::shared_ptr<PlainNet> grad_ops;
// grad_ops.reset(new PlainNet);
for
(
auto
&
op
:
ForwardOps
->
ops_
)
{
for
(
auto
&
op
:
ForwardOps
->
ops_
)
{
auto
op_grad
=
OpRegistry
::
CreateGradOp
(
op
);
auto
op_grad
=
OpRegistry
::
CreateGradOp
(
op
);
grad_ops
->
AddOp
(
op_grad
);
grad_ops
->
AddOp
(
op_grad
);
...
...
paddle/framework/net_op_test.cc
浏览文件 @
81a352af
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
USE_OP
(
add_two
);
USE_OP
(
add_two
);
USE_OP
(
mul
);
USE_OP
(
mul
);
USE_OP
(
sigmoid
);
USE_OP
(
sigmoid
);
USE_OP
(
softmax
);
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
...
@@ -75,16 +76,21 @@ TEST(AddBackwardOp, TestGradOp) {
...
@@ -75,16 +76,21 @@ TEST(AddBackwardOp, TestGradOp) {
net
->
AddOp
(
net
->
AddOp
(
framework
::
OpRegistry
::
CreateOp
(
"add_two"
,
{
"X"
,
"Y"
},
{
"Out"
},
{}));
framework
::
OpRegistry
::
CreateOp
(
"add_two"
,
{
"X"
,
"Y"
},
{
"Out"
},
{}));
net
->
AddOp
(
framework
::
OpRegistry
::
CreateOp
(
"add_two"
,
{
"X"
,
"Y"
},
{
""
},
{}));
net
->
AddOp
(
framework
::
OpRegistry
::
CreateOp
(
"add_two"
,
{
"X"
,
"Y"
},
{
""
},
{}));
// net->AddOp(framework::OpRegistry::CreateOp("fc"), {
// Input("X"), Input("W"), Input("b")},
// {Output("Y")},
// {}
// );
auto
grad_ops
=
AddBackwardOp
(
net
);
auto
grad_ops
=
AddBackwardOp
(
net
);
for
(
auto
&
op
:
grad_ops
->
ops_
)
{
for
(
auto
&
op
:
grad_ops
->
ops_
)
{
op
->
DebugString
();
op
->
DebugString
();
}
}
}
}
// TODO(zhihong): add fc grad without registering.
// TEST(AddBackwardOp, TestNoGradOp) {
// auto net = std::make_shared<PlainNet>();
// ASSERT_NE(net, nullptr);
// net->AddOp(framework::OpRegistry::CreateOp("fc", {"X", "W", "b"}, {"Y"},
// {})); auto grad_ops = AddBackwardOp(net); for (auto& op : grad_ops->ops_) {
// op->DebugString();
// }
// }
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
paddle/framework/op_registry.h
浏览文件 @
81a352af
...
@@ -286,7 +286,13 @@ class OpRegistry {
...
@@ -286,7 +286,13 @@ class OpRegistry {
}
}
static
OperatorPtr
CreateGradOp
(
OperatorPtr
op
)
{
static
OperatorPtr
CreateGradOp
(
OperatorPtr
op
)
{
OperatorPtr
grad_op
(
grad_creators
().
at
(
op
->
type_
)());
auto
it
=
grad_creators
().
find
(
op
->
type_
);
if
(
it
==
grad_creators
().
end
())
{
LOG
(
INFO
)
<<
op
->
type_
<<
"does not has gradient op"
;
return
nullptr
;
}
// OperatorPtr grad_op(grad_creators().at(op->type_)());
OperatorPtr
grad_op
(
it
->
second
());
grad_op
->
type_
=
op
->
type_
;
grad_op
->
type_
=
op
->
type_
;
AssembleGradInOut
(
op
,
grad_op
);
AssembleGradInOut
(
op
,
grad_op
);
...
...
paddle/operators/softmax_op.cc
浏览文件 @
81a352af
...
@@ -40,10 +40,23 @@ public:
...
@@ -40,10 +40,23 @@ public:
}
}
};
};
class
SoftmaxOpGrad
:
public
framework
::
OperatorWithKernel
{
protected:
void
InferShape
(
const
std
::
vector
<
const
framework
::
Tensor
*>
&
inputs
,
const
std
::
vector
<
framework
::
Tensor
*>
&
outputs
)
const
override
{}
std
::
string
DebugString
()
const
override
{
LOG
(
INFO
)
<<
"SoftmaxOpGrad"
;
return
""
;
}
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
(
softmax
,
ops
::
SoftmaxOp
,
ops
::
SoftmaxOpMaker
);
REGISTER_OP
(
softmax
,
ops
::
SoftmaxOp
,
ops
::
SoftmaxOpMaker
);
REGISTER_GRADIENT_OP
(
softmax
,
paddle
::
operators
::
SoftmaxOpGrad
);
REGISTER_OP_CPU_KERNEL
(
softmax
,
ops
::
SoftmaxKernel
<
paddle
::
platform
::
CPUPlace
>
);
REGISTER_OP_CPU_KERNEL
(
softmax
,
ops
::
SoftmaxKernel
<
paddle
::
platform
::
CPUPlace
>
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录