Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
6c19deec
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
提交
6c19deec
编写于
11月 28, 2017
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of github.com:baidu/Paddle into feature/fix_macos_compile_grpc
上级
75248e8f
985e4ab6
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
112 addition
and
14 deletion
+112
-14
paddle/operators/conv_transpose_op.cc
paddle/operators/conv_transpose_op.cc
+9
-9
paddle/operators/detail/send_recv.proto
paddle/operators/detail/send_recv.proto
+2
-4
python/paddle/v2/fluid/layers.py
python/paddle/v2/fluid/layers.py
+92
-1
python/paddle/v2/fluid/tests/test_layers.py
python/paddle/v2/fluid/tests/test_layers.py
+9
-0
未找到文件。
paddle/operators/conv_transpose_op.cc
浏览文件 @
6c19deec
...
@@ -74,12 +74,12 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
...
@@ -74,12 +74,12 @@ Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(
"The format of output tensor is also NCHW."
);
"The format of output tensor is also NCHW."
);
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"strides"
,
"(vector<int> defa
lu
t:{1, 1}), the strides(h_stride, w_stride) of "
"(vector<int> defa
ul
t:{1, 1}), the strides(h_stride, w_stride) of "
"convolution transpose operator."
)
"convolution transpose operator."
)
.
SetDefault
({
1
,
1
});
.
SetDefault
({
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"paddings"
,
"(vector<int> defa
lu
t:{0, 0}), the paddings(h_pad, w_pad) of convolution "
"(vector<int> defa
ul
t:{0, 0}), the paddings(h_pad, w_pad) of convolution "
"transpose operator."
)
"transpose operator."
)
.
SetDefault
({
0
,
0
});
.
SetDefault
({
0
,
0
});
AddComment
(
R"DOC(
AddComment
(
R"DOC(
...
@@ -101,8 +101,8 @@ Example:
...
@@ -101,8 +101,8 @@ Example:
Output:
Output:
Output shape: (N, C_out, H_out, W_out)
Output shape: (N, C_out, H_out, W_out)
where
where
H_out = (H_in - 1) * strides[0] - 2 * paddings[0] +
filter_size[0]
;
H_out = (H_in - 1) * strides[0] - 2 * paddings[0] +
H_f
;
W_out = (W_in - 1) * strides[1] - 2 * paddings[1] +
filter_size[1]
;
W_out = (W_in - 1) * strides[1] - 2 * paddings[1] +
W_f
;
)DOC"
);
)DOC"
);
}
}
...
@@ -130,12 +130,12 @@ Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(
...
@@ -130,12 +130,12 @@ Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(
"the number of channels, D is the depth of the feature, H is the "
"the number of channels, D is the depth of the feature, H is the "
"height of the feature, and W is the width of the feature."
);
"height of the feature, and W is the width of the feature."
);
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector<int> defa
lu
t:{1, 1, 1}), the "
"(vector<int> defa
ul
t:{1, 1, 1}), the "
"strides{d_stride, h_stride, w_stride} of "
"strides{d_stride, h_stride, w_stride} of "
"convolution transpose operator."
)
"convolution transpose operator."
)
.
SetDefault
({
1
,
1
,
1
});
.
SetDefault
({
1
,
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"(vector<int> defa
lu
t:{0, 0, 0}), paddings(d_pad, "
"(vector<int> defa
ul
t:{0, 0, 0}), paddings(d_pad, "
"h_pad, w_pad) of convolution transpose operator."
)
"h_pad, w_pad) of convolution transpose operator."
)
.
SetDefault
({
0
,
0
,
0
});
.
SetDefault
({
0
,
0
,
0
});
AddComment
(
R"DOC(
AddComment
(
R"DOC(
...
@@ -158,9 +158,9 @@ Example:
...
@@ -158,9 +158,9 @@ Example:
Output:
Output:
Output shape: (N, C_out, D_out, H_out, W_out)
Output shape: (N, C_out, D_out, H_out, W_out)
where
where
D_out = (D_in - 1) * strides[0] - 2 * paddings[0] +
filter_size[0]
;
D_out = (D_in - 1) * strides[0] - 2 * paddings[0] +
D_f
;
H_out = (H_in - 1) * strides[1] - 2 * paddings[1] +
filter_size[1]
;
H_out = (H_in - 1) * strides[1] - 2 * paddings[1] +
H_f
;
W_out = (W_in - 1) * strides[2] - 2 * paddings[2] +
filter_size[2]
;
W_out = (W_in - 1) * strides[2] - 2 * paddings[2] +
W_f
;
)DOC"
);
)DOC"
);
}
}
...
...
paddle/operators/detail/send_recv.proto
浏览文件 @
6c19deec
...
@@ -32,6 +32,4 @@ message VariableMessage {
...
@@ -32,6 +32,4 @@ message VariableMessage {
bytes
serialized
=
2
;
bytes
serialized
=
2
;
}
}
message
VoidMessage
{
message
VoidMessage
{}
\ No newline at end of file
}
\ No newline at end of file
python/paddle/v2/fluid/layers.py
浏览文件 @
6c19deec
import
core
import
core
import
proto.framework_pb2
as
framework_pb2
import
proto.framework_pb2
as
framework_pb2
from
framework
import
OpProtoHolder
,
Variable
,
Program
,
Operator
from
framework
import
OpProtoHolder
,
Variable
,
Program
,
Operator
from
initializer
import
Constant
,
Normal
,
Xavier
from
initializer
import
Constant
,
Normal
,
Xavier
,
Initializer
from
paddle.v2.fluid.layer_helper
import
LayerHelper
,
unique_name
from
paddle.v2.fluid.layer_helper
import
LayerHelper
,
unique_name
import
re
import
re
import
cStringIO
import
cStringIO
...
@@ -1587,6 +1587,97 @@ def array_length(array, main_program=None):
...
@@ -1587,6 +1587,97 @@ def array_length(array, main_program=None):
return
tmp
return
tmp
def
conv2d_transpose
(
input
,
num_filters
,
output_size
=
None
,
filter_size
=
None
,
padding
=
None
,
stride
=
None
,
param_attr
=
None
,
param_initializer
=
None
,
main_program
=
None
,
startup_program
=
None
):
"""
The transpose of conv2d layer.
This layer is also known as deconvolution layer.
Args:
input(Variable): The input image with [N, C, H, W] format.
num_filters(int): The number of filter. It is as same as the output
image channel.
output_size(int|tuple|None): The output image size. If output size is a
tuple, it must contain two integers, (image_H, image_W). This
parameter only works when filter_size is None.
filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
it must contain two integers, (filter_size_H, filter_size_W).
Otherwise, the filter will be a square. None if use output size to
calculate filter_size
padding(int|tuple): The padding size. If padding is a tuple, it must
contain two integers, (padding_H, padding_W). Otherwise, the
padding_H = padding_W = padding.
stride(int|tuple): The stride size. If stride is a tuple, it must
contain two integers, (stride_H, stride_W). Otherwise, the
stride_H = stride_W = stride.
param_attr: Parameter Attribute.
param_initializer(Initializer): Parameter Initializer. Default is Xavier
main_program(Program): the main program
startup_program(Program): the startup program
Returns:
Variable: Output image.
"""
helper
=
LayerHelper
(
"conv2d_transpose"
,
**
locals
())
if
not
isinstance
(
input
,
Variable
):
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
elif
stride
is
not
None
:
op_attr
[
'strides'
]
=
stride
if
filter_size
is
None
:
if
output_size
is
None
:
raise
ValueError
(
"output_size must be set when filter_size is None"
)
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
])
h_in
=
input
.
shape
[
2
]
w_in
=
input
.
shape
[
3
]
filter_size_h
=
output_size
[
0
]
-
(
h_in
-
1
)
*
stride
[
0
]
+
2
*
padding
[
0
]
filter_size_w
=
output_size
[
1
]
-
(
w_in
-
1
)
*
stride
[
1
]
+
2
*
padding
[
1
]
filter_size
=
[
filter_size_h
,
filter_size_w
]
elif
isinstance
(
filter_size
,
int
):
filter_size
=
[
filter_size
,
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
,
initializer
=
param_initializer
)
out
=
helper
.
create_tmp_variable
(
dtype
=
input
.
dtype
)
helper
.
append_op
(
type
=
'conv2d_transpose'
,
inputs
=
{
'Input'
:
[
input
],
'Filter'
:
[
img_filter
]},
outputs
=
{
'Output'
:
out
},
attrs
=
op_attr
)
return
out
class
ConditionalBlockGuard
(
BlockGuard
):
class
ConditionalBlockGuard
(
BlockGuard
):
def
__init__
(
self
,
block
):
def
__init__
(
self
,
block
):
if
not
isinstance
(
block
,
ConditionalBlock
):
if
not
isinstance
(
block
,
ConditionalBlock
):
...
...
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
6c19deec
...
@@ -65,6 +65,15 @@ class TestBook(unittest.TestCase):
...
@@ -65,6 +65,15 @@ class TestBook(unittest.TestCase):
print
str
(
program
)
print
str
(
program
)
def
test_conv2d_transpose
(
self
):
program
=
Program
()
kwargs
=
{
'main_program'
:
program
}
img
=
layers
.
data
(
name
=
'pixel'
,
shape
=
[
3
,
2
,
2
],
dtype
=
'float32'
,
**
kwargs
)
layers
.
conv2d_transpose
(
input
=
img
,
num_filters
=
10
,
output_size
=
28
,
**
kwargs
)
print
str
(
program
)
def
test_recognize_digits_conv
(
self
):
def
test_recognize_digits_conv
(
self
):
program
=
Program
()
program
=
Program
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录