Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c9bb48b3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c9bb48b3
编写于
3月 02, 2017
作者:
Q
qiaolongfei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support calculate size
上级
b400c8f0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
42 deletion
+75
-42
python/paddle/v2/config_base.py
python/paddle/v2/config_base.py
+5
-2
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+70
-40
未找到文件。
python/paddle/v2/config_base.py
浏览文件 @
c9bb48b3
...
...
@@ -22,7 +22,7 @@ class Layer(object):
def
__init__
(
self
,
name
=
None
,
size
=
None
,
parent_layers
=
None
):
assert
isinstance
(
parent_layers
,
dict
)
self
.
name
=
name
self
.
size
=
size
self
.
__contex__
=
{}
self
.
__parent_layers__
=
parent_layers
def
to_proto
(
self
,
context
):
...
...
@@ -44,7 +44,7 @@ class Layer(object):
return
self
.
to_proto_impl
(
**
kwargs
)
elif
self
.
context_name
()
not
in
context
:
context
[
self
.
context_name
()]
=
self
.
to_proto_impl
(
**
kwargs
)
self
.
__contex__
=
context
if
self
.
use_context_name
():
return
context
[
self
.
context_name
()]
else
:
...
...
@@ -64,6 +64,9 @@ class Layer(object):
def
use_context_name
(
self
):
return
False
def
calcalted_size
(
self
):
return
self
.
__contex__
[
self
.
context_name
()].
size
def
__convert_to_v2__
(
method_name
,
parent_names
,
is_default_name
=
True
):
if
is_default_name
:
...
...
python/paddle/v2/layer.py
浏览文件 @
c9bb48b3
...
...
@@ -197,6 +197,10 @@ class MemoryV2(WithExtraParent):
val
=
locs
[
key
]
if
isinstance
(
val
,
RecurrentLayerInput
):
begin_of_current_rnn
.
append
(
val
)
elif
isinstance
(
val
,
collections
.
Sequence
):
for
v
in
val
:
if
isinstance
(
v
,
RecurrentLayerInput
):
begin_of_current_rnn
.
append
(
v
)
if
begin_of_current_rnn
:
break
...
...
@@ -216,7 +220,13 @@ class MemoryV2(WithExtraParent):
if
self
.
__boot_layer_name__
is
not
None
:
args
[
'boot_layer'
]
=
context
[
self
.
__boot_layer_name__
]
return
conf_helps
.
memory
(
name
=
self
.
name
,
size
=
self
.
size
,
**
args
)
if
callable
(
self
.
size
):
real_size
=
self
.
size
()
else
:
real_size
=
self
.
size
args
[
'size'
]
=
real_size
return
conf_helps
.
memory
(
name
=
self
.
name
,
**
args
)
def
context_name
(
self
):
return
self
.
name
+
"#memory"
...
...
@@ -311,6 +321,12 @@ class MixedLayerV2(Layer):
args
[
each
]
=
kwargs
[
each
]
for
each
in
self
.
__other_kwargs__
:
args
[
each
]
=
self
.
__other_kwargs__
[
each
]
size
=
args
.
get
(
'size'
,
None
)
if
callable
(
size
):
real_size
=
size
()
else
:
real_size
=
size
args
[
'size'
]
=
real_size
return
getattr
(
conf_helps
,
self
.
__method_name__
)(
**
args
)
...
...
@@ -363,53 +379,15 @@ class RecurrentLayerOutput(Layer):
RecurrentLayerGroupEnd
(
name
=
self
.
__recurrent_name__
)
@
wrap_name_default
()
def
recurrent_group
(
step
,
input
,
name
=
None
):
if
not
isinstance
(
input
,
collections
.
Sequence
):
input
=
[
input
]
# TODO(qiaolongfei) convert StaticInput to memory according to v2 recurrent_group
for
i
in
xrange
(
len
(
input
)):
cur_input
=
input
[
i
]
if
isinstance
(
cur_input
,
StaticInputV2
):
input
[
i
]
=
cur_input
.
input
actual_input
=
[
RecurrentLayerInput
(
recurrent_name
=
name
,
index
=
i
,
parent_layers
=
{
'recurrent_inputs'
:
input
})
for
i
in
xrange
(
len
(
input
))
]
actual_output
=
step
(
*
actual_input
)
if
not
isinstance
(
actual_output
,
collections
.
Sequence
):
actual_output
=
[
actual_output
]
retv
=
[
RecurrentLayerOutput
(
recurrent_name
=
name
,
index
=
i
,
parent_layers
=
{
'recurrent_outputs'
:
actual_output
})
for
i
in
xrange
(
len
(
actual_output
))
]
if
len
(
retv
)
==
1
:
return
retv
[
0
]
else
:
return
retv
LayerV2
=
Layer
data
=
DataLayerV2
AggregateLevel
=
conf_helps
.
layers
.
AggregateLevel
ExpandLevel
=
conf_helps
.
layers
.
ExpandLevel
recurrent_group
=
recurrent_group
memory
=
MemoryV2
def
__layer_name_mapping__
(
inname
):
if
inname
in
[
'data_layer'
,
'memory'
,
'mixed_layer'
]:
if
inname
in
[
'data_layer'
,
'memory'
,
'mixed_layer'
,
'recurrent_group'
]:
# Do Not handle these layers
return
elif
inname
==
'maxid_layer'
:
...
...
@@ -469,3 +447,55 @@ operator_list = [
for
op
in
operator_list
:
globals
()[
op
[
0
]]
=
__convert_to_v2__
(
op
[
0
],
parent_names
=
op
[
1
],
is_default_name
=
False
)
@
wrap_name_default
()
def
recurrent_group
(
step
,
input
,
name
=
None
):
if
not
isinstance
(
input
,
collections
.
Sequence
):
input
=
[
input
]
non_static_inputs
=
filter
(
lambda
x
:
not
isinstance
(
x
,
StaticInputV2
),
input
)
actual_input
=
[
RecurrentLayerInput
(
recurrent_name
=
name
,
index
=
i
,
parent_layers
=
{
'recurrent_inputs'
:
non_static_inputs
})
for
i
in
xrange
(
len
(
non_static_inputs
))
]
def
__real_step__
(
*
args
):
rnn_input
=
list
(
args
)
static_inputs
=
filter
(
lambda
x
:
isinstance
(
x
,
StaticInputV2
),
input
)
for
static_input
in
static_inputs
:
mem_name
=
"__%s_memory__"
%
static_input
.
input
.
name
print
memory
mem
=
memory
(
name
=
mem_name
,
is_seq
=
static_input
.
is_seq
,
size
=
static_input
.
input
.
calcalted_size
,
boot_layer
=
static_input
.
input
)
with
mixed
(
name
=
mem_name
,
size
=
static_input
.
input
.
calcalted_size
,
act
=
activation
.
Identity
())
as
mix
:
mix
+=
identity_projection
(
input
=
mem
)
rnn_input
.
insert
(
input
.
index
(
static_input
),
mix
)
return
step
(
*
rnn_input
)
actual_output
=
__real_step__
(
*
actual_input
)
if
not
isinstance
(
actual_output
,
collections
.
Sequence
):
actual_output
=
[
actual_output
]
retv
=
[
RecurrentLayerOutput
(
recurrent_name
=
name
,
index
=
i
,
parent_layers
=
{
'recurrent_outputs'
:
actual_output
})
for
i
in
xrange
(
len
(
actual_output
))
]
if
len
(
retv
)
==
1
:
return
retv
[
0
]
else
:
return
retv
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录