Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
6197c09b
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6197c09b
编写于
10月 16, 2017
作者:
G
gongweibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify styles
上级
f1ca3f7e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
48 deletion
+50
-48
paddle/operators/block_expand_op.cc
paddle/operators/block_expand_op.cc
+23
-22
paddle/operators/block_expand_op.h
paddle/operators/block_expand_op.h
+27
-26
未找到文件。
paddle/operators/block_expand_op.cc
浏览文件 @
6197c09b
...
...
@@ -33,32 +33,33 @@ class BlockExpandOp : public framework::OperatorWithKernel {
PADDLE_ENFORCE_EQ
(
in_dim
.
size
(),
4
,
"Input format must be NCHW."
);
PADDLE_ENFORCE_GE
(
in_dim
[
0
],
1
,
"Input batchsize must >= 1."
);
int
block
H
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"blockHeight"
);
int
block
W
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"blockWidth"
);
int
stride
H
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"strideHeight"
);
int
stride
W
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"strideWidth"
);
int
padding
H
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"paddingHeight"
);
int
padding
W
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"paddingWidth"
);
int
block
_h
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"blockHeight"
);
int
block
_w
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"blockWidth"
);
int
stride
_h
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"strideHeight"
);
int
stride
_w
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"strideWidth"
);
int
padding
_h
eight
=
ctx
->
Attrs
().
Get
<
int
>
(
"paddingHeight"
);
int
padding
_w
idth
=
ctx
->
Attrs
().
Get
<
int
>
(
"paddingWidth"
);
int
N
=
in_dim
[
0
];
int
C
=
in_dim
[
1
];
int
img
H
eight
=
in_dim
[
3
];
int
img
W
idth
=
in_dim
[
4
];
int
img
_h
eight
=
in_dim
[
3
];
int
img
_w
idth
=
in_dim
[
4
];
int
output
H
eight
=
0
;
int
output
W
idth
=
0
;
int
output
_h
eight
=
0
;
int
output
_w
idth
=
0
;
get_blockexpand_output_shape
(
imgHeight
,
imgWidth
,
blockHeight
,
blockWidth
,
strideHeight
,
strideWidth
,
paddingHeight
,
paddingWidth
,
outputHeight
,
outputWidth
);
get_blockexpand_output_shape
(
img_height
,
img_width
,
block_height
,
block_width
,
stride_height
,
stride_width
,
padding_height
,
padding_width
,
output_height
,
output_width
);
// The result of im2col is [output
Height, outputW
idth,
// The result of im2col is [output
_height, output_w
idth,
// inputChannels, filterHeight, filterWidth], and it is easy to
// reshape into [seqLength, stepSize], where seqLength is equal
// output
Height * outputW
idth, stepSize is equal
// output
_height * output_w
idth, stepSize is equal
// input_channels * blockHeight * blockWidth
ctx
->
SetOutputDim
(
"Out"
,
{
N
,
output
Height
,
outputWidth
,
C
,
blockHeight
,
blockW
idth
});
"Out"
,
{
N
,
output
_height
,
output_width
,
C
,
block_height
,
block_w
idth
});
// ctx->ShareLoD("X", /*->*/ "Out");
}
...
...
@@ -85,18 +86,18 @@ class BlockExpandOpMaker : public framework::OpProtoAndCheckerMaker {
AddAttr
<
int
>
(
"paddingWidth"
,
"(int)width of padding."
);
AddComment
(
R"DOC(
Expand feature map to minibatch matrix.
- matirx height is: output
Height * outputW
idth
- matirx height is: output
_height * output_w
idth
- matrix width is: blockHeight * blockWidth * channels
output
H
eight =
1 + (2 * paddingHeight + img
H
eight - blockHeight + strideHeight - 1) /
output
_h
eight =
1 + (2 * paddingHeight + img
_h
eight - blockHeight + strideHeight - 1) /
strideHeight;
output
W
idth =
1 + (2 * paddingWidth + img
W
idth - blockWidth + strideWidth - 1) /
output
_w
idth =
1 + (2 * paddingWidth + img
_w
idth - blockWidth + strideWidth - 1) /
strideWidth;
The expand method is the same with ExpandConvLayer, but saved the transposed
value. After expanding, The number of time steps are output
Height * outputW
idth
value. After expanding, The number of time steps are output
_height * output_w
idth
and the dimension of each time step is blockHeight * blockWidth * channels.
This layer can be used after convolution neural network, and before recurrent neural network.
)DOC"
);
...
...
paddle/operators/block_expand_op.h
浏览文件 @
6197c09b
...
...
@@ -18,24 +18,25 @@
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
#include "paddle/operators/math/im
g
2col.h"
#include "paddle/operators/math/im2col.h"
namespace
paddle
{
namespace
operators
{
inline
void
get_blockexpand_output_shape
(
int
img
Height
,
int
imgW
idth
,
int
block
Height
,
int
blockW
idth
,
int
stride
Height
,
int
strideW
idth
,
int
padding
Height
,
int
paddingW
idth
,
inline
void
get_blockexpand_output_shape
(
int
img
_height
,
int
img_w
idth
,
int
block
_height
,
int
block_w
idth
,
int
stride
_height
,
int
stride_w
idth
,
int
padding
_height
,
int
padding_w
idth
,
int
&
outputHeight
,
int
&
outputWidth
)
{
outputHeight
=
1
+
(
img
Height
+
2
*
paddingHeight
-
blockHeight
+
strideH
eight
-
1
)
/
stride
H
eight
;
(
img
_height
+
2
*
padding_height
-
block_height
+
stride_h
eight
-
1
)
/
stride
_h
eight
;
outputWidth
=
1
+
(
imgWidth
+
2
*
paddingWidth
-
blockWidth
+
strideWidth
-
1
)
/
strideWidth
;
outputWidth
=
1
+
(
img_width
+
2
*
padding_width
-
block_width
+
stride_width
-
1
)
/
stride_width
;
}
template
<
typename
Place
,
typename
T
>
...
...
@@ -50,30 +51,30 @@ class BlockExpandKernel : public framework::OpKernel<T> {
auto
in_dim
=
in
->
dims
();
int
N
=
in_dim
[
0
];
int
C
=
in_dim
[
1
];
int
img
H
eight
=
in_dim
[
2
];
int
img
W
idth
=
in_dim
[
3
];
int
img
_h
eight
=
in_dim
[
2
];
int
img
_w
idth
=
in_dim
[
3
];
int
block
H
eight
=
ctx
.
Attr
<
int
>
(
"blockHeight"
);
int
block
W
idth
=
ctx
.
Attr
<
int
>
(
"blockWidth"
);
int
stride
H
eight
=
ctx
.
Attr
<
int
>
(
"strideHeight"
);
int
stride
W
idth
=
ctx
.
Attr
<
int
>
(
"strideWidth"
);
int
padding
H
eight
=
ctx
.
Attr
<
int
>
(
"paddingHeight"
);
int
padding
W
idth
=
ctx
.
Attr
<
int
>
(
"paddingWidth"
);
int
block
_h
eight
=
ctx
.
Attr
<
int
>
(
"blockHeight"
);
int
block
_w
idth
=
ctx
.
Attr
<
int
>
(
"blockWidth"
);
int
stride
_h
eight
=
ctx
.
Attr
<
int
>
(
"strideHeight"
);
int
stride
_w
idth
=
ctx
.
Attr
<
int
>
(
"strideWidth"
);
int
padding
_h
eight
=
ctx
.
Attr
<
int
>
(
"paddingHeight"
);
int
padding
_w
idth
=
ctx
.
Attr
<
int
>
(
"paddingWidth"
);
int
outputHeight
=
0
;
int
outputWidth
=
0
;
get_blockexpand_output_shape
(
imgHeight
,
imgWidth
,
blockHeight
,
blockWidth
,
strideHeight
,
strideWidth
,
paddingH
eight
,
paddingW
idth
,
outputHeight
,
outputWidth
);
get_blockexpand_output_shape
(
img_height
,
img_width
,
block_height
,
block_width
,
stride_h
eight
,
stride_width
,
padding_height
,
padding_w
idth
,
outputHeight
,
outputWidth
);
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
Tensor
src
=
in
->
Slice
<
T
>
(
i
,
i
+
1
).
Resize
(
C
,
img
Height
,
imgW
idth
);
Tensor
src
=
in
->
Slice
<
T
>
(
i
,
i
+
1
).
Resize
(
C
,
img
_height
,
img_w
idth
);
Tensor
dst
=
out
->
Slice
<
T
>
(
i
,
i
+
1
).
Resize
(
outputHeight
,
outputWidth
,
C
,
block
Height
,
blockW
idth
);
math
::
Im2ColFunctor
<
kOCF
,
ctx
->
GetPlace
(),
T
>
(
ctx
,
src
,
dst
,
strideHeight
,
strideWidth
,
paddingH
eight
,
paddingW
idth
);
block
_height
,
block_w
idth
);
math
::
Im2ColFunctor
<
math
::
ColFormat
::
kOCF
,
Place
,
T
>
(
ctx
,
src
,
dst
,
stride_height
,
stride_width
,
padding_h
eight
,
padding_w
idth
);
}
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录