Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5917e09c
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5917e09c
编写于
10月 04, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tmp work
上级
ab9545aa
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
49 addition
and
12 deletion
+49
-12
paddle/framework/op_registry.h
paddle/framework/op_registry.h
+4
-0
paddle/framework/operator.h
paddle/framework/operator.h
+1
-1
paddle/framework/shape_inference_map.cc
paddle/framework/shape_inference_map.cc
+6
-3
paddle/framework/shape_inference_map.h
paddle/framework/shape_inference_map.h
+0
-8
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+9
-0
python/paddle/v2/framework/tests/test_infer_shape.py
python/paddle/v2/framework/tests/test_infer_shape.py
+29
-0
未找到文件。
paddle/framework/op_registry.h
浏览文件 @
5917e09c
...
...
@@ -55,6 +55,10 @@ class OpRegistry {
const
std
::
string
&
grad_op_type
)
{
OperatorRegistrar
<
OpType
,
ProtoMakerType
>
reg
(
op_type
.
c_str
());
reg
.
info
.
grad_op_type_
=
grad_op_type
;
auto
proto
=
reg
.
info
.
Proto
();
std
::
cout
<<
"====== "
<<
op_type
<<
" ======="
<<
std
::
endl
;
std
::
cout
<<
proto
.
SerializeAsString
()
<<
std
::
endl
;
std
::
cout
<<
"============="
<<
std
::
endl
;
ShapeInferenceMap
::
Instance
().
CreateOpWithKernel
(
reg
.
info
,
op_type
);
// register gradient op
if
(
!
grad_op_type
.
empty
())
{
...
...
paddle/framework/operator.h
浏览文件 @
5917e09c
...
...
@@ -598,9 +598,9 @@ class OperatorWithKernel : public OperatorBase {
});
}
protected:
virtual
void
InferShape
(
InferShapeContextBase
*
ctx
)
const
=
0
;
protected:
// indicate kernel DataType by input data. Defaultly all input data must be
// same.
virtual
DataType
IndicateDataType
(
const
ExecutionContext
&
ctx
)
const
{
...
...
paddle/framework/shape_inference_map.cc
浏览文件 @
5917e09c
...
...
@@ -37,10 +37,13 @@ ShapeInferenceMap& ShapeInferenceMap::Instance() {
void
ShapeInferenceMap
::
CreateOpWithKernel
(
const
OpInfo
&
op_info
,
const
std
::
string
&
op_type
)
{
const
VariableNameMap
inputs
=
ConvertOpProtoVarsToVarNameMap
(
op_info
.
Proto
().
inputs
());
auto
proto
=
op_info
.
Proto
();
std
::
cout
<<
"========= "
<<
op_type
<<
" in======"
<<
std
::
endl
;
std
::
cout
<<
proto
.
SerializeAsString
()
<<
std
::
endl
;
std
::
cout
<<
"========= "
<<
op_type
<<
" out======"
<<
std
::
endl
;
const
VariableNameMap
inputs
=
ConvertOpProtoVarsToVarNameMap
(
proto
.
inputs
());
const
VariableNameMap
outputs
=
ConvertOpProtoVarsToVarNameMap
(
op_info
.
Proto
()
.
outputs
());
ConvertOpProtoVarsToVarNameMap
(
proto
.
outputs
());
auto
*
op
=
op_info
.
Creator
()(
op_type
,
inputs
,
outputs
,
{});
auto
*
op_with_kernel
=
dynamic_cast
<
OperatorWithKernel
*>
(
op
);
auto
it
=
op_shape_inference_map_
.
find
(
op_type
);
...
...
paddle/framework/shape_inference_map.h
浏览文件 @
5917e09c
...
...
@@ -27,14 +27,6 @@ class ShapeInferenceMap {
public:
static
ShapeInferenceMap
&
Instance
();
const
OperatorBase
*
GetOperator
(
const
std
::
string
&
op_type
)
{
auto
it
=
op_shape_inference_map_
.
find
(
op_type
);
if
(
it
==
op_shape_inference_map_
.
end
())
{
PADDLE_THROW
(
"op with kernel for Op(%s) is not registered"
,
op_type
);
}
return
it
->
second
;
}
void
CreateOpWithKernel
(
const
OpInfo
&
op_info
,
const
std
::
string
&
op_type
);
OperatorWithKernel
*
GetOpWithKernel
(
const
std
::
string
&
op_type
)
{
...
...
paddle/pybind/pybind.cc
浏览文件 @
5917e09c
...
...
@@ -223,6 +223,15 @@ All parameter, weight, gradient are variables in Paddle.
desc
.
InitializationErrorString
());
return
OpRegistry
::
CreateOp
(
desc
);
})
.
def
(
"infer_shape"
,
[](
const
OpDescBind
&
op_desc
,
BlockDescBind
&
block
)
{
auto
&
shape_inference_map
=
ShapeInferenceMap
::
Instance
();
auto
*
op
=
shape_inference_map
.
GetOpWithKernel
(
op_desc
.
Type
());
if
(
op
!=
nullptr
)
{
auto
ctx
=
CompileTimeInferShapeContext
(
op_desc
,
block
);
op
->
InferShape
(
&
ctx
);
}
})
.
def
(
"backward"
,
[](
const
OperatorBase
&
forwardOp
,
const
std
::
unordered_set
<
std
::
string
>
&
no_grad_vars
)
{
...
...
python/paddle/v2/framework/tests/test_infer_shape.py
0 → 100644
浏览文件 @
5917e09c
import
unittest
import
paddle.v2.framework.core
as
core
from
paddle.v2.framework.op
import
Operator
class
TestInferShape
(
unittest
.
TestCase
):
def
test_sum_op
(
self
):
prog
=
core
.
ProgramDesc
.
__create_program_desc__
()
self
.
assertIsNotNone
(
prog
)
block
=
prog
.
block
(
0
)
self
.
assertIsNotNone
(
block
)
# prepare input/output
x1
=
block
.
new_var
(
"x1"
)
x1
.
set_shape
([
10
,
20
])
x2
=
block
.
new_var
(
"x2"
)
x2
.
set_shape
([
10
,
20
])
out
=
block
.
new_var
(
"out"
)
# prepare the operator
sum_op_desc
=
block
.
append_op
()
sum_op_desc
.
set_type
(
"sum"
)
sum_op_desc
.
set_input
(
"X"
,
[
"x1"
,
"x2"
])
sum_op_desc
.
set_output
(
"Out"
,
[
"out"
])
sum_op
=
Operator
(
"sum"
,
X
=
[
"x1"
,
"x2"
],
Out
=
"out"
)
sum_op
.
infer_shape
(
sum_op_desc
,
block
)
print
(
out
.
shape
())
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录