Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wzpei9
Paddle
提交
3a48282e
P
Paddle
项目概览
wzpei9
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3a48282e
编写于
1月 22, 2018
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unitest
上级
500e29a4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
38 addition
and
61 deletion
+38
-61
paddle/operators/im2sequence_op.cc
paddle/operators/im2sequence_op.cc
+5
-5
paddle/operators/im2sequence_op.h
paddle/operators/im2sequence_op.h
+8
-8
python/paddle/v2/fluid/tests/test_im2sequence_op.py
python/paddle/v2/fluid/tests/test_im2sequence_op.py
+25
-48
未找到文件。
paddle/operators/im2sequence_op.cc
浏览文件 @
3a48282e
...
...
@@ -64,11 +64,11 @@ class Im2SequenceOpMaker : public framework::OpProtoAndCheckerMaker {
AddOutput
(
"Out"
,
"(LodTensor)The output data of im2sequence op,"
);
AddAttr
<
std
::
vector
<
int
>>
(
"kernels"
,
"(vector<int>), the "
"kernels(kernel_height, kernel_width)"
)
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector<int> default:{1, 1}), the "
"strides(h_stride, w_stride)"
)
.
SetDefault
({
1
,
1
});
"kernels(kernel_height, kernel_width)"
)
;
AddAttr
<
std
::
vector
<
int
>>
(
"strides"
,
"(vector<int> default:{1, 1}), the "
"strides(h_stride, w_stride)"
)
.
SetDefault
({
1
,
1
});
AddAttr
<
std
::
vector
<
int
>>
(
"paddings"
,
"(vector<int> default:{0, 0, 0, 0}), the "
"paddings(up_pad, left_pad, down_pad, right_pad)"
)
...
...
paddle/operators/im2sequence_op.h
浏览文件 @
3a48282e
...
...
@@ -50,11 +50,11 @@ class Im2SequenceKernel : public framework::OpKernel<T> {
int
img_height
=
in_dim
[
2
];
int
img_width
=
in_dim
[
3
];
auto
kernels
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"kernels"
);
auto
strides
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"strides"
);
auto
paddings
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"paddings"
);
int
output_height
=
OutputSize
(
img_height
,
kernels
[
0
],
paddings
[
0
],
paddings
[
2
]
strides
[
0
]);
auto
kernels
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"kernels"
);
auto
strides
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
auto
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
int
output_height
=
OutputSize
(
img_height
,
kernels
[
0
],
paddings
[
0
],
paddings
[
2
],
strides
[
0
]);
int
output_width
=
OutputSize
(
img_width
,
kernels
[
1
],
paddings
[
1
],
paddings
[
3
],
strides
[
1
]);
...
...
@@ -106,9 +106,9 @@ class Im2SequenceGradKernel : public framework::OpKernel<T> {
int
img_height
=
in_dim
[
2
];
int
img_width
=
in_dim
[
3
];
auto
kernels
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"kernels"
);
auto
strides
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"strides"
);
auto
paddings
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
kernels
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"kernels"
);
auto
strides
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"strides"
);
auto
paddings
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
int
output_height
=
OutputSize
(
img_height
,
kernels
[
0
],
paddings
[
0
],
paddings
[
2
],
strides
[
0
]);
int
output_width
=
...
...
python/paddle/v2/fluid/tests/test_im2sequence_op.py
浏览文件 @
3a48282e
...
...
@@ -20,22 +20,19 @@ def get_output_shape(attrs, in_shape):
img_height
=
in_shape
[
2
]
img_width
=
in_shape
[
3
]
padding_height
=
attrs
[
'padding_height'
]
padding_width
=
attrs
[
'padding_width'
]
block_height
=
attrs
[
'block_height'
]
block_width
=
attrs
[
'block_width'
]
stride_height
=
attrs
[
'stride_height'
]
stride_width
=
attrs
[
'stride_width'
]
paddings
=
attrs
[
'paddings'
]
kernels
=
attrs
[
'kernels'
]
strides
=
attrs
[
'strides'
]
output_height
=
\
1
+
\
(
img_height
+
2
*
padding_height
-
block_height
+
stride_height
-
1
)
/
\
stride
_height
(
img_height
+
paddings
[
0
]
+
paddings
[
2
]
-
kernels
[
0
]
+
strides
[
0
]
-
1
)
/
\
stride
s
[
0
]
output_width
=
\
1
+
\
(
img_width
+
2
*
padding_width
-
block_width
+
stride_width
-
1
)
/
\
stride
_width
(
img_width
+
paddings
[
1
]
+
paddings
[
3
]
-
kernels
[
1
]
+
strides
[
1
]
-
1
)
/
\
stride
s
[
1
]
return
output_height
,
output_width
...
...
@@ -46,19 +43,11 @@ def im2col(attrs, im, col):
col:
{outputHeight, outputWidth, inputChannels, filterHeight, filterWidth}
"""
input_channels
=
im
.
shape
[
0
]
input_height
=
im
.
shape
[
1
]
input_width
=
im
.
shape
[
2
]
input_channels
,
input_height
,
input_width
=
im
.
shape
output_height
,
output_width
,
_
,
filter_height
,
filter_width
=
col
.
shape
output_height
=
col
.
shape
[
0
]
output_width
=
col
.
shape
[
1
]
filter_height
=
col
.
shape
[
3
]
filter_width
=
col
.
shape
[
4
]
stride_height
=
attrs
[
'stride_height'
]
stride_width
=
attrs
[
'stride_width'
]
padding_height
=
attrs
[
'padding_height'
]
padding_width
=
attrs
[
'padding_width'
]
stride_height
,
stride_width
=
attrs
[
'strides'
]
padding_height
,
padding_width
=
attrs
[
'paddings'
][
0
:
2
]
for
col_row_idx
in
range
(
0
,
output_height
):
for
col_col_idx
in
range
(
0
,
output_width
):
...
...
@@ -92,7 +81,7 @@ def Im2Sequence(inputs, attrs):
batch_size
=
inputs
.
shape
[
0
]
out
=
np
.
zeros
([
batch_size
,
output_height
,
output_width
,
img_channels
,
attrs
[
'
block_height'
],
attrs
[
'block_width'
]
attrs
[
'
kernels'
][
0
],
attrs
[
'kernels'
][
1
]
]).
astype
(
"float32"
)
for
i
in
range
(
len
(
inputs
)):
...
...
@@ -100,7 +89,7 @@ def Im2Sequence(inputs, attrs):
out
=
out
.
reshape
([
batch_size
*
output_height
*
output_width
,
img_channels
*
attrs
[
'
block_height'
]
*
attrs
[
'block_width'
]
img_channels
*
attrs
[
'
kernels'
][
0
]
*
attrs
[
'kernels'
][
1
]
])
return
out
...
...
@@ -112,12 +101,9 @@ class TestBlockExpandOp(OpTest):
self
.
img_height
=
4
self
.
img_width
=
4
self
.
attrs
=
{
'block_height'
:
2
,
'block_width'
:
2
,
'stride_height'
:
1
,
'stride_width'
:
1
,
'padding_height'
:
1
,
'padding_width'
:
1
,
'kernels'
:
[
2
,
2
],
'strides'
:
[
1
,
1
],
'paddings'
:
[
1
,
1
,
1
,
1
]
}
def
setUp
(
self
):
...
...
@@ -145,12 +131,9 @@ class TestBlockExpandOpCase2(TestBlockExpandOp):
self
.
img_height
=
4
self
.
img_width
=
5
self
.
attrs
=
{
'block_height'
:
2
,
'block_width'
:
1
,
'stride_height'
:
2
,
'stride_width'
:
1
,
'padding_height'
:
2
,
'padding_width'
:
1
,
'kernels'
:
[
2
,
1
],
'strides'
:
[
2
,
1
],
'paddings'
:
[
2
,
1
,
2
,
1
]
}
...
...
@@ -161,12 +144,9 @@ class TestBlockExpandOpCase3(TestBlockExpandOp):
self
.
img_height
=
4
self
.
img_width
=
5
self
.
attrs
=
{
'block_height'
:
2
,
'block_width'
:
1
,
'stride_height'
:
2
,
'stride_width'
:
1
,
'padding_height'
:
2
,
'padding_width'
:
0
,
'kernels'
:
[
2
,
1
],
'strides'
:
[
2
,
1
],
'paddings'
:
[
2
,
0
,
2
,
0
]
}
...
...
@@ -177,12 +157,9 @@ class TestBlockExpandOpCase4(TestBlockExpandOp):
self
.
img_height
=
3
self
.
img_width
=
3
self
.
attrs
=
{
'block_height'
:
2
,
'block_width'
:
2
,
'stride_height'
:
1
,
'stride_width'
:
1
,
'padding_height'
:
0
,
'padding_width'
:
0
,
'kernels'
:
[
2
,
2
],
'strides'
:
[
1
,
1
],
'paddings'
:
[
0
,
0
,
0
,
0
]
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录