Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2398db5e
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看板
提交
2398db5e
编写于
2月 24, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
93e0609f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
78 addition
and
38 deletion
+78
-38
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+24
-38
python/paddle/v2/fluid/layers/utils.py
python/paddle/v2/fluid/layers/utils.py
+54
-0
未找到文件。
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
2398db5e
...
...
@@ -21,6 +21,7 @@ from ..framework import Variable
from
..param_attr
import
ParamAttr
from
layer_function_generator
import
autodoc
from
tensor
import
concat
import
utils
__all__
=
[
'fc'
,
...
...
@@ -1138,8 +1139,8 @@ def sequence_conv(input,
def
conv2d
(
input
,
num_filters
,
filter_size
,
stride
=
None
,
padding
=
None
,
stride
=
1
,
padding
=
0
,
groups
=
None
,
param_attr
=
None
,
bias_attr
=
None
,
...
...
@@ -1252,17 +1253,15 @@ def conv2d(input,
raise
ValueError
(
"num_channels must be divisible by groups."
)
num_filter_channels
=
num_channels
/
groups
if
isinstance
(
filter_size
,
int
):
filter_size
=
[
filter_size
,
filter_size
]
if
isinstance
(
stride
,
int
):
stride
=
[
stride
,
stride
]
if
isinstance
(
padding
,
int
):
padding
=
[
padding
,
padding
]
filter_size
=
utils
.
convert_to_list
(
filter_size
,
2
,
'conv2d.filter_size'
)
stride
=
utils
.
convert_to_list
(
stride
,
2
,
'conv2d.stride'
)
padding
=
utils
.
convert_to_list
(
padding
,
2
,
'conv2d.padding'
)
if
not
isinstance
(
use_cudnn
,
bool
):
raise
ValueError
(
"use_cudnn should be True or False"
)
input_shape
=
input
.
shape
filter_shape
=
[
num_filters
,
num_filter_channels
]
+
list
(
filter_size
)
filter_shape
=
[
num_filters
,
num_filter_channels
]
+
filter_size
def
_get_default_param_initializer
():
std
=
(
2.0
/
(
filter_size
[
0
]
**
2
*
num_channels
))
**
0.5
...
...
@@ -1685,9 +1684,9 @@ def conv2d_transpose(input,
num_filters
,
output_size
=
None
,
filter_size
=
None
,
padding
=
None
,
stride
=
None
,
dilation
=
None
,
padding
=
0
,
stride
=
1
,
dilation
=
1
,
param_attr
=
None
,
use_cudnn
=
True
,
name
=
None
):
...
...
@@ -1783,26 +1782,12 @@ def conv2d_transpose(input,
raise
TypeError
(
"Input of conv2d_transpose must be Variable"
)
input_channel
=
input
.
shape
[
1
]
op_attr
=
dict
()
if
isinstance
(
padding
,
int
):
op_attr
[
'paddings'
]
=
[
padding
,
padding
]
elif
padding
is
not
None
:
op_attr
[
'paddings'
]
=
padding
if
isinstance
(
stride
,
int
):
op_attr
[
'strides'
]
=
[
stride
,
stride
]
elif
stride
is
not
None
:
op_attr
[
'strides'
]
=
stride
if
isinstance
(
dilation
,
int
):
op_attr
[
'dilations'
]
=
[
dilation
,
dilation
]
elif
dilation
is
not
None
:
op_attr
[
'dilations'
]
=
dilation
padding
=
utils
.
convert_to_list
(
padding
,
2
,
'conv2d_transpose.padding'
)
stride
=
utils
.
convert_to_list
(
stride
,
2
,
'conv2d_transpose.stride'
)
dilation
=
utils
.
convert_to_list
(
dilation
,
2
,
'conv2d_transpose.dilation'
)
if
not
isinstance
(
use_cudnn
,
bool
):
raise
ValueError
(
"use_cudnn should be True or False"
)
op_attr
[
'use_cudnn'
]
=
use_cudnn
if
filter_size
is
None
:
if
output_size
is
None
:
...
...
@@ -1810,10 +1795,6 @@ def conv2d_transpose(input,
if
isinstance
(
output_size
,
int
):
output_size
=
[
output_size
,
output_size
]
padding
=
op_attr
.
get
(
'paddings'
,
[
0
,
0
])
stride
=
op_attr
.
get
(
'strides'
,
[
1
,
1
])
dilation
=
op_attr
.
get
(
'dilations'
,
[
1
,
1
])
h_in
=
input
.
shape
[
2
]
w_in
=
input
.
shape
[
3
]
...
...
@@ -1822,11 +1803,11 @@ def conv2d_transpose(input,
filter_size_w
=
(
output_size
[
1
]
-
(
w_in
-
1
)
*
stride
[
1
]
+
2
*
padding
[
1
]
-
1
)
/
dilation
[
1
]
+
1
filter_size
=
[
filter_size_h
,
filter_size_w
]
else
:
filter_size
=
utils
.
convert_to_list
(
filter_size
,
2
,
'conv2d_transpose.filter_size'
)
elif
isinstance
(
filter_size
,
int
):
filter_size
=
[
filter_size
,
filter_size
]
filter_shape
=
[
input_channel
,
num_filters
]
+
list
(
filter_size
)
filter_shape
=
[
input_channel
,
num_filters
]
+
filter_size
img_filter
=
helper
.
create_parameter
(
dtype
=
input
.
dtype
,
shape
=
filter_shape
,
attr
=
helper
.
param_attr
)
...
...
@@ -1836,7 +1817,12 @@ def conv2d_transpose(input,
inputs
=
{
'Input'
:
[
input
],
'Filter'
:
[
img_filter
]},
outputs
=
{
'Output'
:
out
},
attrs
=
op_attr
)
attrs
=
{
'strides'
:
stride
,
'paddings'
:
padding
,
'dilations'
:
dilation
,
'use_cudnn'
:
use_cudnn
})
return
out
...
...
python/paddle/v2/fluid/layers/utils.py
0 → 100644
浏览文件 @
2398db5e
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
def
convert_to_list
(
value
,
n
,
name
):
"""Converts a single integer or iterable of integers into an integer list.
Arguments:
value: The value to validate and convert. Could an int, or any iterable
of ints.
n: The size of the list to be returned.
name: The name of the argument being validated, e.g. "stride" or
"filter_size". This is only used to format error messages.
Returns:
A list of n integers.
Raises:
ValueError: If something else than an int/long or iterable thereof was
passed.
"""
if
isinstance
(
value
,
int
):
return
[
value
,
]
*
n
else
:
try
:
value_list
=
list
(
value
)
except
TypeError
:
raise
ValueError
(
"The "
+
name
+
"'s type must be list or tuple. Received: "
+
str
(
value
))
if
len
(
value_list
)
!=
n
:
raise
ValueError
(
"The "
+
name
+
"'s length must be "
+
str
(
n
)
+
". Received: "
+
str
(
value
))
for
single_value
in
value_list
:
try
:
int
(
single_value
)
except
(
ValueError
,
TypeError
):
raise
ValueError
(
"The "
+
name
+
"'s must be a list or tuple of "
+
str
(
n
)
+
" integers. Received: "
+
str
(
value
)
+
" "
"including element "
+
str
(
single_value
)
+
" of type"
+
" "
+
str
(
type
(
single_value
)))
return
value_list
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录