Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
81383916
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看板
提交
81383916
编写于
11月 28, 2018
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add OpBase and unify with VarBase
test=develop
上级
f6f06924
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
69 addition
and
46 deletion
+69
-46
paddle/fluid/imperative/CMakeLists.txt
paddle/fluid/imperative/CMakeLists.txt
+1
-1
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+14
-6
paddle/fluid/imperative/tracer.h
paddle/fluid/imperative/tracer.h
+7
-3
paddle/fluid/pybind/imperative.h
paddle/fluid/pybind/imperative.h
+3
-3
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+14
-5
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+30
-28
未找到文件。
paddle/fluid/imperative/CMakeLists.txt
浏览文件 @
81383916
cc_library
(
layer SRCS layer.cc
)
cc_library
(
layer SRCS layer.cc
DEPS proto_desc
)
cc_library
(
tracer SRCS tracer.cc DEPS proto_desc
)
cc_library
(
tracer SRCS tracer.cc DEPS proto_desc
)
cc_library
(
engine SRCS engine.cc
)
cc_library
(
engine SRCS engine.cc
)
paddle/fluid/imperative/layer.h
浏览文件 @
81383916
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#pragma once
#pragma once
#include <vector>
#include <vector>
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/var_desc.h"
#include "paddle/fluid/framework/var_desc.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/enforce.h"
...
@@ -22,21 +23,28 @@
...
@@ -22,21 +23,28 @@
namespace
paddle
{
namespace
paddle
{
namespace
imperative
{
namespace
imperative
{
class
Var
iable
Base
{
class
VarBase
{
public:
public:
Var
iable
Base
()
{}
VarBase
()
{}
virtual
~
Var
iable
Base
()
{}
virtual
~
VarBase
()
{}
framework
::
VarDesc
*
var_desc_
;
framework
::
VarDesc
*
var_desc_
;
};
};
class
OpBase
{
public:
OpBase
()
{}
virtual
~
OpBase
()
{}
framework
::
OpDesc
*
op_desc_
;
};
class
Layer
{
class
Layer
{
public:
public:
virtual
~
Layer
()
{}
virtual
~
Layer
()
{}
virtual
std
::
vector
<
VariableBase
>
Forward
(
virtual
std
::
vector
<
VarBase
>
Forward
(
const
std
::
vector
<
VarBase
>&
inputs
)
{
const
std
::
vector
<
VariableBase
>&
inputs
)
{
std
::
vector
<
VarBase
>
vars
;
std
::
vector
<
VariableBase
>
vars
;
return
vars
;
return
vars
;
}
}
...
...
paddle/fluid/imperative/tracer.h
浏览文件 @
81383916
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#pragma once
#pragma once
#include <map>
#include <string>
#include <string>
#include <vector>
#include <vector>
...
@@ -21,6 +22,7 @@
...
@@ -21,6 +22,7 @@
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/imperative/engine.h"
#include "paddle/fluid/imperative/engine.h"
#include "paddle/fluid/imperative/layer.h"
namespace
paddle
{
namespace
paddle
{
namespace
imperative
{
namespace
imperative
{
...
@@ -29,11 +31,13 @@ class Tracer {
...
@@ -29,11 +31,13 @@ class Tracer {
public:
public:
Tracer
()
{}
Tracer
()
{}
void
Trace
(
framework
::
OpDesc
*
op_desc
)
{
void
Trace
(
OpBase
*
op
,
const
std
::
map
<
std
::
string
,
VarBase
*>&
inputs
,
const
std
::
map
<
std
::
string
,
VarBase
*>&
outputs
)
{
framework
::
OpDesc
*
op_desc
=
op
->
op_desc_
;
LOG
(
ERROR
)
<<
"tracer tracing "
<<
op_desc
->
Type
();
LOG
(
ERROR
)
<<
"tracer tracing "
<<
op_desc
->
Type
();
op_desc
->
InferShape
(
*
block_
);
op_desc
->
InferShape
(
*
block_
);
op_desc
->
InferVarType
(
block_
);
op_desc
->
InferVarType
(
block_
);
std
::
unique_ptr
<
framework
::
OperatorBase
>
op
=
std
::
unique_ptr
<
framework
::
OperatorBase
>
op
_base
=
framework
::
OpRegistry
::
CreateOp
(
*
op_desc
);
framework
::
OpRegistry
::
CreateOp
(
*
op_desc
);
for
(
const
std
::
string
&
vname
:
op_desc
->
InputArgumentNames
())
{
for
(
const
std
::
string
&
vname
:
op_desc
->
InputArgumentNames
())
{
framework
::
Variable
*
var
=
scope_
->
Var
(
vname
);
framework
::
Variable
*
var
=
scope_
->
Var
(
vname
);
...
@@ -57,7 +61,7 @@ class Tracer {
...
@@ -57,7 +61,7 @@ class Tracer {
}
}
}
}
}
}
op
->
Run
(
*
scope_
,
platform
::
CPUPlace
());
op
_base
->
Run
(
*
scope_
,
platform
::
CPUPlace
());
}
}
void
SetScope
(
framework
::
Scope
*
scope
)
{
scope_
=
scope
;
}
void
SetScope
(
framework
::
Scope
*
scope
)
{
scope_
=
scope
;
}
...
...
paddle/fluid/pybind/imperative.h
浏览文件 @
81383916
...
@@ -26,9 +26,9 @@ class PyLayer : public imperative::Layer {
...
@@ -26,9 +26,9 @@ class PyLayer : public imperative::Layer {
public:
public:
using
imperative
::
Layer
::
Layer
;
// Inherit constructors
using
imperative
::
Layer
::
Layer
;
// Inherit constructors
std
::
vector
<
imperative
::
Var
iable
Base
>
Forward
(
std
::
vector
<
imperative
::
VarBase
>
Forward
(
const
std
::
vector
<
imperative
::
Var
iable
Base
>&
inputs
)
override
{
const
std
::
vector
<
imperative
::
VarBase
>&
inputs
)
override
{
PYBIND11_OVERLOAD
(
std
::
vector
<
imperative
::
Var
iable
Base
>
,
Layer
,
Forward
,
PYBIND11_OVERLOAD
(
std
::
vector
<
imperative
::
VarBase
>
,
Layer
,
Forward
,
inputs
);
// NOLINT
inputs
);
// NOLINT
}
}
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
81383916
...
@@ -101,21 +101,30 @@ PYBIND11_MODULE(core, m) {
...
@@ -101,21 +101,30 @@ PYBIND11_MODULE(core, m) {
BindException
(
&
m
);
BindException
(
&
m
);
py
::
class_
<
imperative
::
Var
iableBase
>
(
m
,
"Variable
Base"
,
py
::
class_
<
imperative
::
Var
Base
>
(
m
,
"Var
Base"
,
R"DOC()DOC"
)
R"DOC()DOC"
)
.
def_property
(
.
def_property
(
"desc"
,
"desc"
,
[](
const
imperative
::
Var
iable
Base
&
self
)
{
return
self
.
var_desc_
;
},
[](
const
imperative
::
VarBase
&
self
)
{
return
self
.
var_desc_
;
},
[](
imperative
::
Var
iable
Base
&
self
,
framework
::
VarDesc
*
var_desc
)
{
[](
imperative
::
VarBase
&
self
,
framework
::
VarDesc
*
var_desc
)
{
self
.
var_desc_
=
var_desc
;
self
.
var_desc_
=
var_desc
;
},
},
py
::
return_value_policy
::
reference
);
py
::
return_value_policy
::
reference
);
py
::
class_
<
imperative
::
OpBase
>
(
m
,
"OpBase"
,
R"DOC()DOC"
)
.
def_property
(
"desc"
,
[](
const
imperative
::
OpBase
&
self
)
{
return
self
.
op_desc_
;
},
[](
imperative
::
OpBase
&
self
,
framework
::
OpDesc
*
op_desc
)
{
self
.
op_desc_
=
op_desc
;
},
py
::
return_value_policy
::
reference
);
py
::
class_
<
imperative
::
Layer
,
PyLayer
/* <--- trampoline*/
>
layer
(
m
,
"Layer"
);
py
::
class_
<
imperative
::
Layer
,
PyLayer
/* <--- trampoline*/
>
layer
(
m
,
"Layer"
);
layer
.
def
(
py
::
init
<>
())
layer
.
def
(
py
::
init
<>
())
.
def
(
"forward"
,
.
def
(
"forward"
,
[](
imperative
::
Layer
&
self
,
[](
imperative
::
Layer
&
self
,
const
std
::
vector
<
imperative
::
Var
iable
Base
>
&
inputs
)
{
const
std
::
vector
<
imperative
::
VarBase
>
&
inputs
)
{
return
self
.
Forward
(
inputs
);
return
self
.
Forward
(
inputs
);
})
})
.
def
(
"backward"
,
&
imperative
::
Layer
::
Backward
);
.
def
(
"backward"
,
&
imperative
::
Layer
::
Backward
);
...
...
python/paddle/fluid/framework.py
浏览文件 @
81383916
...
@@ -212,7 +212,7 @@ def _debug_string_(proto, throw_on_error=True):
...
@@ -212,7 +212,7 @@ def _debug_string_(proto, throw_on_error=True):
return
proto
.
__str__
()
return
proto
.
__str__
()
class
Variable
(
core
.
Var
iable
Base
):
class
Variable
(
core
.
VarBase
):
"""
"""
In Fluid, every input and output of an operator is a variable. In most
In Fluid, every input and output of an operator is a variable. In most
cases, variables are used for holding different kinds of data or training
cases, variables are used for holding different kinds of data or training
...
@@ -507,7 +507,7 @@ class OpProtoHolder(object):
...
@@ -507,7 +507,7 @@ class OpProtoHolder(object):
}
}
class
Operator
(
object
):
class
Operator
(
core
.
OpBase
):
"""
"""
In Fluid, all the operation are represented by Operator, and Operator
In Fluid, all the operation are represented by Operator, and Operator
is regarded as a build in an instruction of a Block. Users can use the
is regarded as a build in an instruction of a Block. Users can use the
...
@@ -602,32 +602,33 @@ class Operator(object):
...
@@ -602,32 +602,33 @@ class Operator(object):
return
True
return
True
return
False
return
False
if
inputs
is
not
None
:
self
.
inputs
=
[]
if
not
inputs
else
inputs
for
in_proto
in
proto
.
inputs
:
for
in_proto
in
proto
.
inputs
:
found
=
find_name
(
inputs
,
in_proto
.
name
)
found
=
find_name
(
self
.
inputs
,
in_proto
.
name
)
assert
found
or
in_proto
.
dispensable
,
"Input {} not found"
.
format
(
assert
found
or
in_proto
.
dispensable
,
"Input {} not found"
.
format
(
in_proto
.
name
)
in_proto
.
name
)
if
found
:
if
found
:
in_args
=
inputs
[
in_proto
.
name
]
in_args
=
self
.
inputs
[
in_proto
.
name
]
if
not
isinstance
(
in_args
,
list
):
if
not
isinstance
(
in_args
,
list
):
in_args
=
[
in_args
]
in_args
=
[
in_args
]
if
not
in_proto
.
duplicable
and
len
(
in_args
)
>
1
:
if
not
in_proto
.
duplicable
and
len
(
in_args
)
>
1
:
raise
ValueError
(
raise
ValueError
(
"Input %s expects only one input, but %d are given."
"Input %s expects only one input, but %d are given."
%
%
(
in_proto
.
name
,
len
(
in_args
)))
(
in_proto
.
name
,
len
(
in_args
)))
in_arg_names
=
[]
in_arg_names
=
[]
for
arg
in
in_args
:
for
arg
in
in_args
:
if
isinstance
(
arg
,
six
.
string_types
):
if
isinstance
(
arg
,
six
.
string_types
):
in_arg_names
.
append
(
arg
)
in_arg_names
.
append
(
arg
)
elif
isinstance
(
arg
,
six
.
binary_type
):
elif
isinstance
(
arg
,
six
.
binary_type
):
in_arg_names
.
append
(
arg
.
decode
())
in_arg_names
.
append
(
arg
.
decode
())
else
:
else
:
in_arg_names
.
append
(
cpt
.
to_text
(
arg
.
name
))
in_arg_names
.
append
(
cpt
.
to_text
(
arg
.
name
))
self
.
desc
.
set_input
(
in_proto
.
name
,
in_arg_names
)
self
.
desc
.
set_input
(
in_proto
.
name
,
in_arg_names
)
else
:
else
:
self
.
desc
.
set_input
(
in_proto
.
name
,
[])
self
.
desc
.
set_input
(
in_proto
.
name
,
[])
self
.
outputs
=
[]
if
not
outputs
else
outputs
if
outputs
is
not
None
:
if
outputs
is
not
None
:
given
=
set
()
given
=
set
()
need
=
set
()
need
=
set
()
...
@@ -1222,7 +1223,8 @@ class Block(object):
...
@@ -1222,7 +1223,8 @@ class Block(object):
if
_in_imperative_mode
():
if
_in_imperative_mode
():
op_desc
=
core
.
OpDesc
()
op_desc
=
core
.
OpDesc
()
op
=
Operator
(
block
=
self
,
desc
=
op_desc
,
*
args
,
**
kwargs
)
op
=
Operator
(
block
=
self
,
desc
=
op_desc
,
*
args
,
**
kwargs
)
_imperative_tracer
().
trace
(
op
.
desc
)
sys
.
stderr
.
write
(
'%s %s!!!
\n
'
%
(
type
(
op
.
inputs
),
type
(
op
.
outputs
)))
_imperative_tracer
().
trace
(
op
,
op
.
inputs
,
op
.
outputs
)
return
return
op_desc
=
self
.
desc
.
append_op
()
op_desc
=
self
.
desc
.
append_op
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录