Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
22956530
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22956530
编写于
12月 29, 2018
作者:
M
minqiyang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish PyLayers
test=develop
上级
0f6ef8ed
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
67 addition
and
124 deletion
+67
-124
python/paddle/fluid/imperative/layers.py
python/paddle/fluid/imperative/layers.py
+1
-13
python/paddle/fluid/imperative/nn.py
python/paddle/fluid/imperative/nn.py
+19
-19
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+44
-88
python/paddle/fluid/tests/unittests/test_imperative.py
python/paddle/fluid/tests/unittests/test_imperative.py
+1
-1
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
...paddle/fluid/tests/unittests/test_imperative_optimizer.py
+2
-3
未找到文件。
python/paddle/fluid/imperative/layers.py
浏览文件 @
22956530
...
...
@@ -24,19 +24,7 @@ __all__ = ['PyLayer']
class
PyLayer
(
core
.
Layer
):
def
__init__
(
self
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
,
param_attr
=
None
,
bias_attr
=
None
,
name
=
None
):
from
..layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
type
(
self
).
__name__
,
param_attr
=
param_attr
,
bias_attr
=
bias_attr
,
dtype
=
dtype
,
name
=
name
)
def
__init__
(
self
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
,
name
=
None
):
self
.
_once_built
=
False
self
.
_dtype
=
dtype
...
...
python/paddle/fluid/imperative/nn.py
浏览文件 @
22956530
...
...
@@ -46,8 +46,15 @@ class Conv2D(layers.PyLayer):
name
=
None
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
):
assert
param_attr
is
not
False
,
"param_attr should not be False here."
super
(
Conv2D
,
self
).
__init__
(
param_attr
=
param_attr
,
bias_attr
=
bias_attr
,
name
=
name
,
dtype
=
dtype
)
super
(
Conv2D
,
self
).
__init__
(
name
=
name
,
dtype
=
dtype
)
from
..layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
type
(
self
).
__name__
,
param_attr
=
param_attr
,
bias_attr
=
bias_attr
,
dtype
=
dtype
,
name
=
name
)
self
.
_groups
=
groups
self
.
_stride
=
utils
.
convert_to_list
(
stride
,
2
,
'stride'
)
...
...
@@ -163,6 +170,9 @@ class Pool2D(layers.PyLayer):
super
(
Pool2D
,
self
).
__init__
(
name
=
name
,
dtype
=
dtype
)
from
..layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
type
(
self
).
__name__
,
dtype
=
dtype
,
name
=
name
)
self
.
_pool_type
=
pool_type
self
.
_pool_size
=
utils
.
convert_to_list
(
pool_size
,
2
,
'pool_size'
)
self
.
_pool_padding
=
utils
.
convert_to_list
(
pool_padding
,
2
,
...
...
@@ -197,32 +207,22 @@ class Pool2D(layers.PyLayer):
class
FC
(
layers
.
PyLayer
):
def
__init__
(
self
,
size_in
,
size_out
,
num_flatten_dims
=
1
,
size
,
param_attr
=
None
,
num_flatten_dims
=
1
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
):
super
(
FC
,
self
).
__init__
(
param_attr
=
param_attr
,
dtype
=
dtype
)
self
.
_size_in
=
size_in
self
.
_size_out
=
size_out
super
(
FC
,
self
).
__init__
()
self
.
_size
=
size
self
.
_num_flatten_dims
=
num_flatten_dims
self
.
_dtype
=
dtype
if
self
.
_size_in
!=
-
1
:
self
.
_w
=
self
.
_helper
.
create_parameter
(
attr
=
self
.
_helper
.
param_attr
,
shape
=
[
size_in
,
size_out
],
dtype
=
self
.
_dtype
,
is_bias
=
False
)
from
..layer_helper
import
LayerHelper
self
.
_helper
=
LayerHelper
(
'FC'
,
param_attr
=
param_attr
)
def
_build_once
(
self
,
input
):
if
self
.
_size_in
!=
-
1
:
return
input_shape
=
input
.
shape
param_shape
=
[
reduce
(
lambda
a
,
b
:
a
*
b
,
input_shape
[
self
.
_num_flatten_dims
:],
1
)
]
+
[
self
.
_size
_out
]
]
+
[
self
.
_size
]
self
.
_w
=
self
.
_helper
.
create_parameter
(
attr
=
self
.
_helper
.
param_attr
,
shape
=
param_shape
,
...
...
python/paddle/fluid/layers/nn.py
浏览文件 @
22956530
...
...
@@ -9713,47 +9713,3 @@ def huber_loss(input, label, delta):
'Residual'
:
residual
},
attrs
=
{
'delta'
:
delta
})
return
out
class
FC
(
layers
.
PyLayer
):
def
__init__
(
self
,
size
,
param_attr
=
None
,
num_flatten_dims
=
1
,
dtype
=
core
.
VarDesc
.
VarType
.
FP32
):
super
(
FC
,
self
).
__init__
(
param_attr
=
param_attr
)
self
.
_size
=
size
self
.
_num_flatten_dims
=
num_flatten_dims
self
.
_dtype
=
dtype
self
.
_tmp
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
self
.
_out
=
self
.
_helper
.
create_variable_for_type_inference
(
self
.
_dtype
)
def
_build_once
(
self
,
inputs
):
input_shape
=
inputs
.
shape
param_shape
=
[
reduce
(
lambda
a
,
b
:
a
*
b
,
input_shape
[
self
.
_num_flatten_dims
:],
1
)
]
+
[
self
.
_size
]
self
.
_w
=
self
.
_helper
.
create_parameter
(
attr
=
self
.
_helper
.
param_attr
,
shape
=
param_shape
,
dtype
=
self
.
_dtype
,
is_bias
=
False
)
def
forward
(
self
,
inputs
):
self
.
_helper
.
append_op
(
type
=
"mul"
,
inputs
=
{
"X"
:
inputs
,
"Y"
:
self
.
_w
},
outputs
=
{
"Out"
:
self
.
_tmp
},
attrs
=
{
"x_num_col_dims"
:
self
.
_num_flatten_dims
,
"y_num_col_dims"
:
1
})
self
.
_helper
.
append_op
(
type
=
"sum"
,
inputs
=
{
"X"
:
[
self
.
_tmp
]},
outputs
=
{
"Out"
:
self
.
_out
},
attrs
=
{
"use_mkldnn"
:
False
})
return
self
.
_out
python/paddle/fluid/tests/unittests/test_imperative.py
浏览文件 @
22956530
...
...
@@ -18,7 +18,7 @@ import numpy as np
import
paddle.fluid
as
fluid
from
paddle.fluid
import
core
from
paddle.fluid.
layers
.nn
import
FC
from
paddle.fluid.
imperative
.nn
import
FC
from
test_imperative_base
import
new_program_scope
...
...
python/paddle/fluid/tests/unittests/test_imperative_optimizer.py
浏览文件 @
22956530
...
...
@@ -74,7 +74,7 @@ class SimpleImgConvPool(fluid.imperative.PyLayer):
class
MNIST
(
fluid
.
imperative
.
PyLayer
):
def
__init__
(
self
,
param_attr
=
None
,
bias_attr
=
None
):
super
(
MNIST
,
self
).
__init__
(
param_attr
=
param_attr
,
bias_attr
=
bias_attr
)
super
(
MNIST
,
self
).
__init__
()
self
.
_simple_img_conv_pool_1
=
SimpleImgConvPool
(
1
,
20
,
5
,
2
,
2
,
act
=
"relu"
)
...
...
@@ -85,8 +85,7 @@ class MNIST(fluid.imperative.PyLayer):
pool_2_shape
=
50
*
8
*
8
SIZE
=
10
scale
=
(
2.0
/
(
pool_2_shape
**
2
*
SIZE
))
**
0.5
self
.
_fc
=
FC
(
-
1
,
10
,
self
.
_fc
=
FC
(
10
,
param_attr
=
fluid
.
param_attr
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
NormalInitializer
(
loc
=
0.0
,
scale
=
scale
)))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录