Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
a0669ead
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看板
提交
a0669ead
编写于
7月 27, 2017
作者:
D
dongzhihong
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'reyoung/feature/backward' into feature/backward
上级
5713266f
d4ab70a7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
20 deletion
+28
-20
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+1
-1
paddle/framework/net.h
paddle/framework/net.h
+9
-0
paddle/framework/net_op_test.cc
paddle/framework/net_op_test.cc
+18
-19
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
a0669ead
...
@@ -30,7 +30,7 @@ add_custom_target(framework_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch
...
@@ -30,7 +30,7 @@ add_custom_target(framework_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch
add_dependencies
(
framework_py_proto framework_py_proto_init
)
add_dependencies
(
framework_py_proto framework_py_proto_init
)
cc_library
(
net SRCS net.cc DEPS op_registry
)
cc_library
(
net SRCS net.cc DEPS op_registry
)
cc_test
(
net_op_test SRCS net_op_test.cc DEPS net
add_op mul_op sigmoid_op softmax_op fc_op
)
cc_test
(
net_op_test SRCS net_op_test.cc DEPS net
)
cc_library
(
backward SRCS backward.cc DEPS net
)
cc_library
(
backward SRCS backward.cc DEPS net
)
cc_test
(
backward_test SRCS backward_test.cc DEPS backward
)
cc_test
(
backward_test SRCS backward_test.cc DEPS backward
)
paddle/framework/net.h
浏览文件 @
a0669ead
...
@@ -73,9 +73,18 @@ class NetOp : public OperatorBase {
...
@@ -73,9 +73,18 @@ class NetOp : public OperatorBase {
*/
*/
void
AddOp
(
const
std
::
shared_ptr
<
OperatorBase
>&
op
)
{
void
AddOp
(
const
std
::
shared_ptr
<
OperatorBase
>&
op
)
{
PADDLE_ENFORCE
(
!
add_op_done_
,
"Cannot AddOp when this network is sealed"
);
PADDLE_ENFORCE
(
!
add_op_done_
,
"Cannot AddOp when this network is sealed"
);
PADDLE_ENFORCE
(
op
!=
nullptr
,
"Cannot Insert Null op"
);
ops_
.
push_back
(
op
);
ops_
.
push_back
(
op
);
}
}
void
InsertOp
(
size_t
pos
,
const
std
::
shared_ptr
<
OperatorBase
>&
op
)
{
PADDLE_ENFORCE
(
!
add_op_done_
,
"Cannot InsertOp when this network is sealed"
);
PADDLE_ENFORCE
(
op
!=
nullptr
,
"Cannot Insert Null op"
);
PADDLE_ENFORCE
(
pos
<=
ops_
.
size
(),
"Out of range"
);
ops_
.
insert
(
ops_
.
begin
()
+
pos
,
op
);
}
void
CompleteAddOp
(
bool
calculate
=
true
);
void
CompleteAddOp
(
bool
calculate
=
true
);
std
::
string
DebugString
()
const
override
;
std
::
string
DebugString
()
const
override
;
...
...
paddle/framework/net_op_test.cc
浏览文件 @
a0669ead
...
@@ -3,11 +3,6 @@
...
@@ -3,11 +3,6 @@
#include <paddle/framework/op_registry.h>
#include <paddle/framework/op_registry.h>
#include <paddle/framework/operator.h>
#include <paddle/framework/operator.h>
USE_OP
(
add_two
);
USE_OP
(
mul
);
USE_OP
(
sigmoid
);
USE_OP
(
softmax
);
namespace
paddle
{
namespace
paddle
{
namespace
framework
{
namespace
framework
{
...
@@ -26,6 +21,13 @@ class TestOp : public OperatorBase {
...
@@ -26,6 +21,13 @@ class TestOp : public OperatorBase {
}
}
};
};
class
EmptyOp
:
public
OperatorBase
{
public:
void
InferShape
(
const
std
::
shared_ptr
<
Scope
>&
scope
)
const
override
{}
void
Run
(
const
std
::
shared_ptr
<
Scope
>&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{}
};
template
<
typename
T
>
template
<
typename
T
>
void
AssertSameVectorWithoutOrder
(
const
std
::
vector
<
T
>&
expected
,
void
AssertSameVectorWithoutOrder
(
const
std
::
vector
<
T
>&
expected
,
const
std
::
vector
<
T
>&
actual
)
{
const
std
::
vector
<
T
>&
actual
)
{
...
@@ -72,20 +74,17 @@ TEST(OpKernel, all) {
...
@@ -72,20 +74,17 @@ TEST(OpKernel, all) {
ASSERT_THROW
(
net
->
AddOp
(
op2
),
paddle
::
platform
::
EnforceNotMet
);
ASSERT_THROW
(
net
->
AddOp
(
op2
),
paddle
::
platform
::
EnforceNotMet
);
}
}
//! TODO(yuyang18): Refine Backward Op.
TEST
(
Net
,
insert_op
)
{
// TEST(AddBackwardOp, TestGradOp) {
NetOp
net
;
// auto net = std::make_shared<NetOp>();
auto
op1
=
std
::
make_shared
<
EmptyOp
>
();
// ASSERT_NE(net, nullptr);
op1
->
inputs_
=
{
"x"
,
"w1"
,
"b1"
};
// net->AddOp(framework::OpRegistry::CreateOp("mul", {"X", "Y"}, {"Out"}, {}));
op1
->
outputs_
=
{
"y"
};
// net->AddOp(
net
.
AddOp
(
op1
);
// framework::OpRegistry::CreateOp("add_two", {"X", "Y"}, {"Out"}, {}));
net
.
InsertOp
(
0
,
op1
);
// net->AddOp(framework::OpRegistry::CreateOp("add_two", {"X", "Y"}, {""},
ASSERT_EQ
(
2UL
,
net
.
ops_
.
size
());
// {}));
net
.
InsertOp
(
2
,
op1
);
// auto grad_ops = AddBackwardOp(net);
ASSERT_EQ
(
3UL
,
net
.
ops_
.
size
());
// for (auto& op : grad_ops->ops_) {
}
// op->DebugString();
// }
//}
}
// namespace framework
}
// namespace framework
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录