Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
05e563b9
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看板
提交
05e563b9
编写于
1月 23, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unitest
上级
91b83d0a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
34 deletion
+55
-34
python/paddle/v2/fluid/layers/nn.py
python/paddle/v2/fluid/layers/nn.py
+45
-34
python/paddle/v2/fluid/tests/test_layers.py
python/paddle/v2/fluid/tests/test_layers.py
+10
-0
未找到文件。
python/paddle/v2/fluid/layers/nn.py
浏览文件 @
05e563b9
...
...
@@ -1974,16 +1974,13 @@ def sequence_reshape(input, new_dim):
def
im2sequence
(
input
,
block_x
=
1
,
block_y
=
1
,
stride_x
=
1
,
stride_y
=
1
,
padding_x
=
0
,
padding_y
=
0
,
filter_size
=
1
,
stride
=
1
,
padding
=
0
,
name
=
None
,
layer_attr
=
None
):
"""
This op use
block
to scan images and convert these images to sequences.
This op use
filter
to scan images and convert these images to sequences.
After expanding, the number of time step are output_height * output_width
for an image, in which output_height and output_width are calculated
by below equation:
...
...
@@ -1995,23 +1992,34 @@ def im2sequence(input,
And the dimension of each time step is block_y * block_x * input.channels.
Args:
input (Variable): The input should be a tensor in NCHW format.
block_x (int): The width of sub block.
block_y (int): The width of sub block.
stride_x (int): The stride size in horizontal direction.
stride_y (int): The stride size in vertical direction.
padding_x (int): The padding size in horizontal direction.
padding_y (int): The padding size in vertical direction.
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.
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. Default: stride = 1.
padding(int|tuple): The padding size. If padding is a tuple, it can
contain two integers like (padding_H, padding_W) which means
padding_up = padding_down = padding_H and
padding_left = padding_right = padding_W. Or it can use
(padding_up, padding_left, padding_down, padding_right) to indicate
paddings of four direction. Otherwise, a scalar padding means
padding_up = padding_down = padding_left = padding_right = padding
Default: padding = 0.
name (int): The name of this layer. It is optional.
Returns:
output: The output is a LoDTensor woth shape
{input.batch_size * output_y * x,
block_y * block_x * input.channels}.
If we regard output as matrix, each row of this matrix is a step of sequence.
output: The output is a LoDTensor with shape
{input.batch_size * output_height * output_width,
filter_size_H * filter_size_W * input.channels}.
If we regard output as a matrix, each row of this matrix is
a step of a sequence.
Examples:
...
...
@@ -2041,12 +2049,9 @@ def im2sequence(input,
And:
block_height = 2
block_width = 2
stride_height = 1
stride_width = 1
padding_height = 0
padding_width = 0
filter = [2, 2]
stride = [1, 1]
padding = [0, 0]
Then:
...
...
@@ -2063,15 +2068,24 @@ def im2sequence(input,
output.lod = [[0, 4, 8]]
The simple usage is:
.. code-block:: python
output = fluid.layers.im2sequence(input=layer, stride
_x=1, stride_y=1, block_x=2, block_y=2
)
output = fluid.layers.im2sequence(input=layer, stride
=[1, 1], filter=[2, 2]
)
"""
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
]
if
len
(
padding
)
==
2
:
padding
.
append
(
padding
[
0
])
padding
.
append
(
padding
[
1
])
helper
=
LayerHelper
(
'im2sequence'
,
**
locals
())
out
=
helper
.
create_tmp_variable
(
dtype
=
helper
.
input_dtype
())
helper
.
append_op
(
...
...
@@ -2079,11 +2093,8 @@ def im2sequence(input,
inputs
=
{
'X'
:
input
},
outputs
=
{
'Out'
:
out
},
attrs
=
{
'block_height'
:
block_y
,
'block_width'
:
block_x
,
'stride_height'
:
stride_y
,
'stride_width'
:
stride_x
,
'padding_height'
:
padding_y
,
'padding_width'
:
padding_x
'kernels'
:
filter_size
,
'strides'
:
stride
,
'paddings'
:
padding
,
})
return
out
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
05e563b9
...
...
@@ -225,6 +225,16 @@ class TestBook(unittest.TestCase):
self
.
assertIsNotNone
(
out
)
print
(
str
(
program
))
def
test_im2sequence
(
self
):
print
(
"test_im2sequence"
)
program
=
Program
()
with
program_guard
(
program
):
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
3
,
128
,
128
],
dtype
=
'float32'
)
output
=
layers
.
im2sequence
(
input
=
x
,
stride
=
[
1
,
1
],
filter_size
=
[
2
,
2
])
self
.
assertIsNotNone
(
output
)
print
(
str
(
program
))
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录