Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
f9e6aa2c
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
f9e6aa2c
编写于
3月 02, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine code
上级
c9bb48b3
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
29 addition
and
23 deletion
+29
-23
python/paddle/v2/config_base.py
python/paddle/v2/config_base.py
+8
-4
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+21
-19
未找到文件。
python/paddle/v2/config_base.py
浏览文件 @
f9e6aa2c
...
@@ -19,7 +19,7 @@ import paddle.trainer_config_helpers as conf_helps
...
@@ -19,7 +19,7 @@ import paddle.trainer_config_helpers as conf_helps
class
Layer
(
object
):
class
Layer
(
object
):
def
__init__
(
self
,
name
=
None
,
size
=
None
,
parent_layers
=
None
):
def
__init__
(
self
,
name
=
None
,
parent_layers
=
None
):
assert
isinstance
(
parent_layers
,
dict
)
assert
isinstance
(
parent_layers
,
dict
)
self
.
name
=
name
self
.
name
=
name
self
.
__contex__
=
{}
self
.
__contex__
=
{}
...
@@ -64,7 +64,12 @@ class Layer(object):
...
@@ -64,7 +64,12 @@ class Layer(object):
def
use_context_name
(
self
):
def
use_context_name
(
self
):
return
False
return
False
def
calcalted_size
(
self
):
def
calculate_size
(
self
):
"""
lazy calculate size of the layer, should be called when to_proto_impl of
this layer is called.
:return:
"""
return
self
.
__contex__
[
self
.
context_name
()].
size
return
self
.
__contex__
[
self
.
context_name
()].
size
...
@@ -87,8 +92,7 @@ def __convert_to_v2__(method_name, parent_names, is_default_name=True):
...
@@ -87,8 +92,7 @@ def __convert_to_v2__(method_name, parent_names, is_default_name=True):
other_kwargs
[
key
]
=
kwargs
[
key
]
other_kwargs
[
key
]
=
kwargs
[
key
]
name
=
kwargs
.
get
(
'name'
,
None
)
name
=
kwargs
.
get
(
'name'
,
None
)
size
=
kwargs
.
get
(
'size'
,
None
)
super
(
V2LayerImpl
,
self
).
__init__
(
name
,
parent_layers
)
super
(
V2LayerImpl
,
self
).
__init__
(
name
,
size
,
parent_layers
)
self
.
__other_kwargs__
=
other_kwargs
self
.
__other_kwargs__
=
other_kwargs
if
wrapper
is
not
None
:
if
wrapper
is
not
None
:
...
...
python/paddle/v2/layer.py
浏览文件 @
f9e6aa2c
...
@@ -139,10 +139,10 @@ class WithExtraParent(Layer):
...
@@ -139,10 +139,10 @@ class WithExtraParent(Layer):
def
extra_parent
(
self
):
def
extra_parent
(
self
):
return
self
.
__extra_parent__
return
self
.
__extra_parent__
def
__init__
(
self
,
name
=
None
,
size
=
None
,
parent_layers
=
None
):
def
__init__
(
self
,
name
=
None
,
parent_layers
=
None
):
self
.
__extra_parent__
=
[]
self
.
__extra_parent__
=
[]
super
(
WithExtraParent
,
self
).
__init__
(
super
(
WithExtraParent
,
self
).
__init__
(
name
=
name
,
size
=
size
,
parent_layers
=
parent_layers
)
name
=
name
,
parent_layers
=
parent_layers
)
def
append_extra_parent
(
self
,
parent
):
def
append_extra_parent
(
self
,
parent
):
self
.
__extra_parent__
.
append
(
parent
)
self
.
__extra_parent__
.
append
(
parent
)
...
@@ -178,11 +178,9 @@ class WithExtraParent(Layer):
...
@@ -178,11 +178,9 @@ class WithExtraParent(Layer):
class
MemoryV2
(
WithExtraParent
):
class
MemoryV2
(
WithExtraParent
):
def
__init__
(
self
,
name
,
size
,
**
kwargs
):
def
__init__
(
self
,
name
,
**
kwargs
):
self
.
name
=
name
self
.
name
=
name
self
.
size
=
size
super
(
MemoryV2
,
self
).
__init__
(
name
=
name
,
parent_layers
=
dict
())
super
(
MemoryV2
,
self
).
__init__
(
name
=
name
,
size
=
size
,
parent_layers
=
dict
())
self
.
__kwargs__
=
kwargs
self
.
__kwargs__
=
kwargs
self
.
__boot_layer_name__
=
None
self
.
__boot_layer_name__
=
None
if
'boot_layer'
in
kwargs
:
if
'boot_layer'
in
kwargs
:
...
@@ -221,10 +219,13 @@ class MemoryV2(WithExtraParent):
...
@@ -221,10 +219,13 @@ class MemoryV2(WithExtraParent):
if
self
.
__boot_layer_name__
is
not
None
:
if
self
.
__boot_layer_name__
is
not
None
:
args
[
'boot_layer'
]
=
context
[
self
.
__boot_layer_name__
]
args
[
'boot_layer'
]
=
context
[
self
.
__boot_layer_name__
]
if
callable
(
self
.
size
):
size
=
args
.
get
(
'size'
,
None
)
real_size
=
self
.
size
()
if
size
is
not
None
:
if
callable
(
size
):
real_size
=
size
()
else
:
else
:
real_size
=
self
.
size
real_size
=
size
print
(
real_size
)
args
[
'size'
]
=
real_size
args
[
'size'
]
=
real_size
return
conf_helps
.
memory
(
name
=
self
.
name
,
**
args
)
return
conf_helps
.
memory
(
name
=
self
.
name
,
**
args
)
...
@@ -298,7 +299,7 @@ class MixedLayerV2(Layer):
...
@@ -298,7 +299,7 @@ class MixedLayerV2(Layer):
other_kwargs
[
'bias_attr'
]
=
bias_attr
other_kwargs
[
'bias_attr'
]
=
bias_attr
other_kwargs
[
'layer_attr'
]
=
layer_attr
other_kwargs
[
'layer_attr'
]
=
layer_attr
parent_layers
=
{
"input"
:
self
.
__inputs__
}
parent_layers
=
{
"input"
:
self
.
__inputs__
}
super
(
MixedLayerV2
,
self
).
__init__
(
name
,
size
,
parent_layers
)
super
(
MixedLayerV2
,
self
).
__init__
(
name
,
parent_layers
)
self
.
__other_kwargs__
=
other_kwargs
self
.
__other_kwargs__
=
other_kwargs
def
__iadd__
(
self
,
other
):
def
__iadd__
(
self
,
other
):
...
@@ -322,6 +323,7 @@ class MixedLayerV2(Layer):
...
@@ -322,6 +323,7 @@ class MixedLayerV2(Layer):
for
each
in
self
.
__other_kwargs__
:
for
each
in
self
.
__other_kwargs__
:
args
[
each
]
=
self
.
__other_kwargs__
[
each
]
args
[
each
]
=
self
.
__other_kwargs__
[
each
]
size
=
args
.
get
(
'size'
,
None
)
size
=
args
.
get
(
'size'
,
None
)
if
size
is
not
None
:
if
callable
(
size
):
if
callable
(
size
):
real_size
=
size
()
real_size
=
size
()
else
:
else
:
...
@@ -473,11 +475,11 @@ def recurrent_group(step, input, name=None):
...
@@ -473,11 +475,11 @@ def recurrent_group(step, input, name=None):
mem
=
memory
(
mem
=
memory
(
name
=
mem_name
,
name
=
mem_name
,
is_seq
=
static_input
.
is_seq
,
is_seq
=
static_input
.
is_seq
,
size
=
static_input
.
input
.
calc
alted
_size
,
size
=
static_input
.
input
.
calc
ulate
_size
,
boot_layer
=
static_input
.
input
)
boot_layer
=
static_input
.
input
)
with
mixed
(
with
mixed
(
name
=
mem_name
,
name
=
mem_name
,
size
=
static_input
.
input
.
calc
alted
_size
,
size
=
static_input
.
input
.
calc
ulate
_size
,
act
=
activation
.
Identity
())
as
mix
:
act
=
activation
.
Identity
())
as
mix
:
mix
+=
identity_projection
(
input
=
mem
)
mix
+=
identity_projection
(
input
=
mem
)
rnn_input
.
insert
(
input
.
index
(
static_input
),
mix
)
rnn_input
.
insert
(
input
.
index
(
static_input
),
mix
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录