Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
0d0bc612
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看板
提交
0d0bc612
编写于
1月 07, 2019
作者:
X
Xin Pan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update api
test=develop
上级
875a07c3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
42 addition
and
17 deletion
+42
-17
paddle/fluid/imperative/layer.h
paddle/fluid/imperative/layer.h
+4
-1
paddle/fluid/pybind/imperative.h
paddle/fluid/pybind/imperative.h
+5
-3
paddle/fluid/pybind/pybind.cc
paddle/fluid/pybind/pybind.cc
+5
-2
python/paddle/fluid/imperative/layers.py
python/paddle/fluid/imperative/layers.py
+20
-3
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+3
-3
python/paddle/fluid/tests/unittests/test_imperative.py
python/paddle/fluid/tests/unittests/test_imperative.py
+3
-3
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
...paddle/fluid/tests/unittests/test_imperative_optimizer.py
+2
-2
未找到文件。
paddle/fluid/imperative/layer.h
浏览文件 @
0d0bc612
...
...
@@ -153,7 +153,10 @@ class Layer {
return
vars
;
}
virtual
void
Backward
()
{
LOG
(
ERROR
)
<<
"To support customize"
;
}
virtual
std
::
vector
<
VarBase
>
Backward
(
const
std
::
vector
<
VarBase
>&
inputs
)
{
std
::
vector
<
VarBase
>
vars
;
return
vars
;
}
};
}
// namespace imperative
...
...
paddle/fluid/pybind/imperative.h
浏览文件 @
0d0bc612
...
...
@@ -22,7 +22,7 @@ limitations under the License. */
namespace
paddle
{
namespace
pybind
{
class
Py
Layer
:
public
imperative
::
Layer
{
class
Layer
:
public
imperative
::
Layer
{
public:
using
imperative
::
Layer
::
Layer
;
// Inherit constructors
...
...
@@ -32,8 +32,10 @@ class PyLayer : public imperative::Layer {
inputs
);
// NOLINT
}
void
Backward
()
override
{
PYBIND11_OVERLOAD
(
void
,
Layer
,
Backward
,
);
// NOLINT
std
::
vector
<
imperative
::
VarBase
>
Backward
(
const
std
::
vector
<
imperative
::
VarBase
>&
inputs
)
override
{
PYBIND11_OVERLOAD
(
std
::
vector
<
imperative
::
VarBase
>
,
Layer
,
Backward
,
inputs
);
// NOLINT
}
};
...
...
paddle/fluid/pybind/pybind.cc
浏览文件 @
0d0bc612
...
...
@@ -170,14 +170,17 @@ PYBIND11_MODULE(core, m) {
},
py
::
return_value_policy
::
reference
);
py
::
class_
<
imperative
::
Layer
,
Py
Layer
/* <--- trampoline*/
>
layer
(
m
,
"Layer"
);
py
::
class_
<
imperative
::
Layer
,
Layer
/* <--- trampoline*/
>
layer
(
m
,
"Layer"
);
layer
.
def
(
py
::
init
<>
())
.
def
(
"forward"
,
[](
imperative
::
Layer
&
self
,
const
std
::
vector
<
imperative
::
VarBase
>
&
inputs
)
{
return
self
.
Forward
(
inputs
);
})
.
def
(
"backward"
,
&
imperative
::
Layer
::
Backward
);
.
def
(
"backward"
,
[](
imperative
::
Layer
&
self
,
const
std
::
vector
<
imperative
::
VarBase
>
&
inputs
)
{
return
self
.
Backward
(
inputs
);
});
BindTracer
(
&
m
);
py
::
class_
<
Tensor
>
(
m
,
"Tensor"
,
py
::
buffer_protocol
())
...
...
python/paddle/fluid/imperative/layers.py
浏览文件 @
0d0bc612
...
...
@@ -20,10 +20,12 @@ from paddle.fluid import core
from
paddle.fluid
import
framework
from
paddle.fluid.imperative
import
base
__all__
=
[
'
Py
Layer'
]
__all__
=
[
'Layer'
]
class
PyLayer
(
core
.
Layer
):
class
Layer
(
core
.
Layer
):
"""Layers composed of operators."""
def
__init__
(
self
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
,
name
=
None
):
self
.
_once_built
=
False
self
.
_dtype
=
dtype
...
...
@@ -37,8 +39,23 @@ class PyLayer(core.Layer):
self
.
_once_built
=
True
outputs
=
self
.
forward
(
*
inputs
)
return
outputs
def
forward
(
self
,
*
inputs
):
raise
NotImplementedError
def
backward
(
self
,
*
inputs
):
raise
ValueError
(
"Layer shouldn't implement backward"
)
class
PyLayer
(
core
.
Layer
):
"""Layers composed of user-defined python codes."""
def
__call__
(
self
,
*
inputs
):
pass
def
forward
(
self
,
*
inputs
):
raise
NotImplementedError
def
backward
(
self
,
*
inputs
):
raise
NotImplementedError
python/paddle/fluid/imperative/nn.py
浏览文件 @
0d0bc612
...
...
@@ -30,7 +30,7 @@ __all__ = [
]
class
Conv2D
(
layers
.
Py
Layer
):
class
Conv2D
(
layers
.
Layer
):
def
__init__
(
self
,
num_channels
,
num_filters
,
...
...
@@ -143,7 +143,7 @@ class Conv2D(layers.PyLayer):
return
self
.
_helper
.
append_activation
(
pre_act
)
class
Pool2D
(
layers
.
Py
Layer
):
class
Pool2D
(
layers
.
Layer
):
def
__init__
(
self
,
pool_size
=-
1
,
pool_type
=
"max"
,
...
...
@@ -205,7 +205,7 @@ class Pool2D(layers.PyLayer):
return
pool_out
class
FC
(
layers
.
Py
Layer
):
class
FC
(
layers
.
Layer
):
def
__init__
(
self
,
size
,
param_attr
=
None
,
...
...
python/paddle/fluid/tests/unittests/test_imperative.py
浏览文件 @
0d0bc612
...
...
@@ -22,7 +22,7 @@ from paddle.fluid.imperative.nn import FC
from
test_imperative_base
import
new_program_scope
class
MyLayer
(
fluid
.
imperative
.
Py
Layer
):
class
MyLayer
(
fluid
.
imperative
.
Layer
):
def
__init__
(
self
):
super
(
MyLayer
,
self
).
__init__
()
...
...
@@ -34,7 +34,7 @@ class MyLayer(fluid.imperative.PyLayer):
return
[
x
]
class
MLP
(
fluid
.
imperative
.
Py
Layer
):
class
MLP
(
fluid
.
imperative
.
Layer
):
def
__init__
(
self
):
super
(
MLP
,
self
).
__init__
()
self
.
_fc1
=
FC
(
3
,
...
...
@@ -56,7 +56,7 @@ class TestImperative(unittest.TestCase):
with
fluid
.
imperative
.
guard
():
cl
=
core
.
Layer
()
cl
.
forward
([])
l
=
fluid
.
imperative
.
Py
Layer
()
l
=
fluid
.
imperative
.
Layer
()
self
.
assertRaises
(
NotImplementedError
,
l
.
forward
,
[])
def
test_layer_in_out
(
self
):
...
...
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
浏览文件 @
0d0bc612
...
...
@@ -26,7 +26,7 @@ from paddle.fluid.imperative.base import to_variable
from
test_imperative_base
import
new_program_scope
class
SimpleImgConvPool
(
fluid
.
imperative
.
Py
Layer
):
class
SimpleImgConvPool
(
fluid
.
imperative
.
Layer
):
def
__init__
(
self
,
num_channels
,
num_filters
,
...
...
@@ -72,7 +72,7 @@ class SimpleImgConvPool(fluid.imperative.PyLayer):
return
x
class
MNIST
(
fluid
.
imperative
.
Py
Layer
):
class
MNIST
(
fluid
.
imperative
.
Layer
):
def
__init__
(
self
,
param_attr
=
None
,
bias_attr
=
None
):
super
(
MNIST
,
self
).
__init__
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录