Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
b9f8cc06
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看板
提交
b9f8cc06
编写于
2月 28, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of github.com:baidu/Paddle into feature/tester
上级
75466f4e
b265ccab
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
61 addition
and
98 deletion
+61
-98
python/paddle/trainer_config_helpers/default_decorators.py
python/paddle/trainer_config_helpers/default_decorators.py
+4
-0
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+6
-0
python/paddle/v2/layer.py
python/paddle/v2/layer.py
+50
-93
python/paddle/v2/tests/test_layer.py
python/paddle/v2/tests/test_layer.py
+1
-5
未找到文件。
python/paddle/trainer_config_helpers/default_decorators.py
浏览文件 @
b9f8cc06
...
@@ -52,6 +52,10 @@ def wrap_param_default(param_names=None,
...
@@ -52,6 +52,10 @@ def wrap_param_default(param_names=None,
kwargs
[
name
]
=
default_factory
(
func
)
kwargs
[
name
]
=
default_factory
(
func
)
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
if
hasattr
(
func
,
'argspec'
):
__wrapper__
.
argspec
=
func
.
argspec
else
:
__wrapper__
.
argspec
=
inspect
.
getargspec
(
func
)
return
__wrapper__
return
__wrapper__
return
__impl__
return
__impl__
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
b9f8cc06
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
import
functools
import
functools
import
collections
import
collections
import
inspect
from
paddle.trainer.config_parser
import
*
from
paddle.trainer.config_parser
import
*
from
.activations
import
LinearActivation
,
SigmoidActivation
,
TanhActivation
,
\
from
.activations
import
LinearActivation
,
SigmoidActivation
,
TanhActivation
,
\
...
@@ -316,6 +317,11 @@ def layer_support(*attrs):
...
@@ -316,6 +317,11 @@ def layer_support(*attrs):
val
.
check
(
method
.
__name__
)
val
.
check
(
method
.
__name__
)
return
method
(
*
args
,
**
kwargs
)
return
method
(
*
args
,
**
kwargs
)
if
hasattr
(
method
,
'argspec'
):
wrapper
.
argspec
=
method
.
argspec
else
:
wrapper
.
argspec
=
inspect
.
getargspec
(
method
)
return
wrapper
return
wrapper
return
decorator
return
decorator
...
...
python/paddle/v2/layer.py
浏览文件 @
b9f8cc06
...
@@ -67,6 +67,7 @@ paddle.v2.parameters.create, no longer exposed to users.
...
@@ -67,6 +67,7 @@ paddle.v2.parameters.create, no longer exposed to users.
"""
"""
import
collections
import
collections
import
inspect
import
paddle.trainer_config_helpers
as
conf_helps
import
paddle.trainer_config_helpers
as
conf_helps
from
paddle.trainer_config_helpers.config_parser_utils
import
\
from
paddle.trainer_config_helpers.config_parser_utils
import
\
...
@@ -74,26 +75,14 @@ from paddle.trainer_config_helpers.config_parser_utils import \
...
@@ -74,26 +75,14 @@ from paddle.trainer_config_helpers.config_parser_utils import \
from
paddle.trainer_config_helpers.default_decorators
import
wrap_name_default
from
paddle.trainer_config_helpers.default_decorators
import
wrap_name_default
from
paddle.trainer_config_helpers.default_decorators
import
wrap_act_default
from
paddle.trainer_config_helpers.default_decorators
import
wrap_act_default
from
paddle.trainer_config_helpers.default_decorators
import
wrap_bias_attr_default
from
paddle.trainer_config_helpers.default_decorators
import
\
wrap_bias_attr_default
from
paddle.trainer_config_helpers.layers
import
layer_support
from
paddle.trainer_config_helpers.layers
import
layer_support
import
data_type
import
data_type
import
activation
import
activation
import
attr
__all__
=
[
'parse_network'
,
'data'
]
__all__
=
[
'parse_network'
,
'data'
,
'fc'
,
'conv_shift'
,
'img_conv'
,
'img_pool'
,
'spp'
,
'maxout'
,
'img_cmrnorm'
,
'batch_norm'
,
'sum_to_one_norm'
,
'recurrent'
,
'lstmemory'
,
'grumemory'
,
'pool'
,
'last_seq'
,
'first_seq'
,
'concat'
,
'seq_concat'
,
'block_expand'
,
'expand'
,
'repeat'
,
'seq_reshape'
,
'addto'
,
'linear_comb'
,
'interpolation'
,
'bilinear_interp'
,
'power'
,
'scaling'
,
'slope_intercept'
,
'tensor'
,
'cos_sim'
,
'trans'
,
'max_id'
,
'sampling_id'
,
'pad'
,
'classification_cost'
,
'cross_entropy_cost'
,
'cross_entropy_with_selfnorm_cost'
,
'regression_cost'
,
'multi_binary_label_cross_entropy_cost'
,
'rank_cost'
,
'lambda_cost'
,
'sum_cost'
,
'huber_cost'
,
'crf'
,
'crf_decoding'
,
'ctc'
,
'warp_ctc'
,
'nce'
,
'hsigmoid'
,
'eos'
]
__projection_names__
=
filter
(
lambda
x
:
x
.
endswith
(
'_projection'
),
__projection_names__
=
filter
(
lambda
x
:
x
.
endswith
(
'_projection'
),
dir
(
conf_helps
))
dir
(
conf_helps
))
...
@@ -289,83 +278,51 @@ data = DataLayerV2
...
@@ -289,83 +278,51 @@ data = DataLayerV2
AggregateLevel
=
conf_helps
.
layers
.
AggregateLevel
AggregateLevel
=
conf_helps
.
layers
.
AggregateLevel
ExpandLevel
=
conf_helps
.
layers
.
ExpandLevel
ExpandLevel
=
conf_helps
.
layers
.
ExpandLevel
layer_list
=
[
# [V2LayerImpl, V1_method_name, parent_names]
def
__layer_name_mapping__
(
inname
):
# fully connected layers
if
inname
in
[
'data_layer'
,
'memory'
,
'mixed_layer'
]:
[
'fc'
,
'fc_layer'
,
[
'input'
]],
# Do Not handle these layers
# conv layers
return
[
'conv_shift'
,
'conv_shift_layer'
,
[
'a'
,
'b'
]],
elif
inname
==
'maxid_layer'
:
[
'img_conv'
,
'img_conv_layer'
,
[
'input'
]],
return
'max_id'
# image pooling layers
elif
inname
.
endswith
(
'memory'
)
or
inname
.
endswith
(
[
'img_pool'
,
'img_pool_layer'
,
[
'input'
]],
'_seq'
)
or
inname
.
endswith
(
'_sim'
)
or
inname
==
'hsigmoid'
:
[
'spp'
,
'spp_layer'
,
[
'input'
]],
return
inname
[
'maxout'
,
'maxout_layer'
,
[
'input'
]],
elif
inname
in
[
# norm layers
'cross_entropy'
,
'multi_binary_label_cross_entropy'
,
[
'img_cmrnorm'
,
'img_cmrnorm_layer'
,
[
'input'
]],
'cross_entropy_with_selfnorm'
[
'batch_norm'
,
'batch_norm_layer'
,
[
'input'
]],
]:
[
'sum_to_one_norm'
,
'sum_to_one_norm_layer'
,
[
'input'
]],
return
inname
+
"_cost"
# recurrent layers
elif
inname
.
endswith
(
'_cost'
):
[
'recurrent'
,
'recurrent_layer'
,
[
'input'
]],
return
inname
[
'lstmemory'
,
'lstmemory'
,
[
'input'
]],
elif
inname
.
endswith
(
"_layer"
):
[
'grumemory'
,
'grumemory'
,
[
'input'
]],
return
inname
[:
-
len
(
"_layer"
)]
# aggregate layers
[
'pool'
,
'pooling_layer'
,
[
'input'
]],
[
'last_seq'
,
'last_seq'
,
[
'input'
]],
def
__layer_name_mapping_parent_names__
(
inname
):
[
'first_seq'
,
'first_seq'
,
[
'input'
]],
all_args
=
getattr
(
conf_helps
,
inname
).
argspec
.
args
[
'concat'
,
'concat_layer'
,
[
'input'
]],
return
filter
(
[
'seq_concat'
,
'seq_concat_layer'
,
[
'a'
,
'b'
]],
lambda
x
:
x
in
[
'input1'
,
'input2'
,
'label'
,
'input'
,
'a'
,
'b'
,
'expand_as'
,
# reshaping layers
'weights'
,
'vectors'
,
'weight'
,
'score'
,
'left'
,
'right'
],
[
'block_expand'
,
'block_expand_layer'
,
[
'input'
]],
all_args
)
[
'expand'
,
'expand_layer'
,
[
'input'
,
'expand_as'
]],
[
'repeat'
,
'repeat_layer'
,
[
'input'
]],
[
'rotate'
,
'rotate_layer'
,
[
'input'
]],
def
__convert_layer__
(
_new_name_
,
_old_name_
,
_parent_names_
):
[
'seq_reshape'
,
'seq_reshape_layer'
,
[
'input'
]],
global
__all__
# math layers
__all__
.
append
(
_new_name_
)
[
'addto'
,
'addto_layer'
,
[
'input'
]],
globals
()[
new_name
]
=
__convert_to_v2__
(
_old_name_
,
_parent_names_
)
[
'linear_comb'
,
'linear_comb_layer'
,
[
'weights'
,
'vectors'
]],
[
'interpolation'
,
'interpolation_layer'
,
[
'input'
,
'weight'
]],
[
'bilinear_interp'
,
'bilinear_interp_layer'
,
[
'input'
]],
for
each_layer_name
in
dir
(
conf_helps
):
[
'power'
,
'power_layer'
,
[
'input'
,
'weight'
]],
new_name
=
__layer_name_mapping__
(
each_layer_name
)
[
'scaling'
,
'scaling_layer'
,
[
'input'
,
'weight'
]],
if
new_name
is
not
None
:
[
'slope_intercept'
,
'slope_intercept_layer'
,
[
'input'
]],
parent_names
=
__layer_name_mapping_parent_names__
(
each_layer_name
)
[
'tensor'
,
'tensor_layer'
,
[
'a'
,
'b'
]],
assert
len
(
parent_names
)
!=
0
,
each_layer_name
[
'cos_sim'
,
'cos_sim'
,
[
'a'
,
'b'
]],
__convert_layer__
(
new_name
,
each_layer_name
,
parent_names
)
[
'trans'
,
'trans_layer'
,
[
'input'
]],
# sampling layers
del
parent_names
[
'max_id'
,
'maxid_layer'
,
[
'input'
]],
del
new_name
[
'sampling_id'
,
'sampling_id_layer'
,
[
'input'
]],
del
each_layer_name
# slicing and joining layers
[
'pad'
,
'pad_layer'
,
[
'input'
]],
# cost layers
[
'classification_cost'
,
'classification_cost'
,
[
'input'
,
'label'
,
'weight'
]
],
[
'regression_cost'
,
'regression_cost'
,
[
'input'
,
'label'
,
'weight'
]],
[
'cross_entropy_cost'
,
'cross_entropy'
,
[
'input'
,
'label'
]],
[
'cross_entropy_with_selfnorm_cost'
,
'cross_entropy_with_selfnorm'
,
[
'input'
,
'label'
]
],
[
'multi_binary_label_cross_entropy_cost'
,
'multi_binary_label_cross_entropy'
,
[
'input'
,
'label'
]
],
[
'rank_cost'
,
'rank_cost'
,
[
'left'
,
'right'
,
'label'
,
'weight'
]],
[
'lambda_cost'
,
'lambda_cost'
,
[
'input'
,
'score'
]],
[
'sum_cost'
,
'sum_cost'
,
[
'input'
]],
[
'huber_cost'
,
'huber_cost'
,
[
'input'
,
'label'
]],
[
'crf'
,
'crf_layer'
,
[
'input'
,
'label'
]],
[
'crf_decoding'
,
'crf_decoding_layer'
,
[
'input'
]],
[
'ctc'
,
'ctc_layer'
,
[
'input'
,
'label'
]],
[
'warp_ctc'
,
'warp_ctc_layer'
,
[
'input'
,
'label'
]],
[
'nce'
,
'nce_layer'
,
[
'input'
,
'label'
]],
[
'hsigmoid'
,
'hsigmoid'
,
[
'input'
,
'label'
]],
# check layers
[
'eos'
,
'eos_layer'
,
[
'input'
]]
]
for
l
in
layer_list
:
globals
()[
l
[
0
]]
=
__convert_to_v2__
(
l
[
1
],
l
[
2
])
# convert projection
# convert projection
for
prj
in
__projection_names__
:
for
prj
in
__projection_names__
:
...
...
python/paddle/v2/tests/test_layer.py
浏览文件 @
b9f8cc06
...
@@ -11,17 +11,13 @@
...
@@ -11,17 +11,13 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
difflib
import
unittest
import
unittest
import
paddle.trainer_config_helpers
as
conf_helps
import
paddle.v2.activation
as
activation
import
paddle.v2.activation
as
activation
import
paddle.v2.attr
as
attr
import
paddle.v2.attr
as
attr
import
paddle.v2.data_type
as
data_type
import
paddle.v2.data_type
as
data_type
import
paddle.v2.layer
as
layer
import
paddle.v2.layer
as
layer
import
paddle.v2.pooling
as
pooling
import
paddle.v2.pooling
as
pooling
from
paddle.trainer_config_helpers.config_parser_utils
import
\
parse_network_config
as
parse_network
pixel
=
layer
.
data
(
name
=
'pixel'
,
type
=
data_type
.
dense_vector
(
128
))
pixel
=
layer
.
data
(
name
=
'pixel'
,
type
=
data_type
.
dense_vector
(
128
))
label
=
layer
.
data
(
name
=
'label'
,
type
=
data_type
.
integer_value
(
10
))
label
=
layer
.
data
(
name
=
'label'
,
type
=
data_type
.
integer_value
(
10
))
...
@@ -70,7 +66,7 @@ class ImageLayerTest(unittest.TestCase):
...
@@ -70,7 +66,7 @@ class ImageLayerTest(unittest.TestCase):
class
AggregateLayerTest
(
unittest
.
TestCase
):
class
AggregateLayerTest
(
unittest
.
TestCase
):
def
test_aggregate_layer
(
self
):
def
test_aggregate_layer
(
self
):
pool
=
layer
.
pool
(
pool
=
layer
.
pool
ing
(
input
=
pixel
,
input
=
pixel
,
pooling_type
=
pooling
.
Avg
(),
pooling_type
=
pooling
.
Avg
(),
agg_level
=
layer
.
AggregateLevel
.
EACH_SEQUENCE
)
agg_level
=
layer
.
AggregateLevel
.
EACH_SEQUENCE
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录