Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
2947f567
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看板
提交
2947f567
编写于
10月 23, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
dc7d0735
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
68 addition
and
48 deletion
+68
-48
paddle/operators/math/im2col.cc
paddle/operators/math/im2col.cc
+68
-48
未找到文件。
paddle/operators/math/im2col.cc
浏览文件 @
2947f567
...
...
@@ -42,14 +42,20 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
int
output_height
=
col
.
dims
()[
3
];
int
output_width
=
col
.
dims
()[
4
];
PADDLE_ENFORCE
((
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
==
output_height
);
PADDLE_ENFORCE
((
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
==
output_width
);
PADDLE_ENFORCE_EQ
(
(
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
,
output_height
,
"Output_height and padding(padding_up, padding_down) are "
"inconsistent."
);
PADDLE_ENFORCE_EQ
(
(
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
,
output_width
,
"output_width and padding(padding_left, padding_right) are "
"inconsistent."
);
int
channels_col
=
input_channels
*
filter_height
*
filter_width
;
...
...
@@ -62,16 +68,14 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kCFO,
int
c_im
=
c
/
filter_width
/
filter_height
;
for
(
int
h
=
0
;
h
<
output_height
;
++
h
)
{
for
(
int
w
=
0
;
w
<
output_width
;
++
w
)
{
int
im_row_idx
=
h
*
stride_height
+
h_offset
;
int
im_col_idx
=
w
*
stride_width
+
w_offset
;
if
((
im_row_idx
-
padding_up
)
<
0
||
(
im_row_idx
-
padding_up
)
>=
input_height
||
(
im_col_idx
-
padding_left
)
<
0
||
(
im_col_idx
-
padding_left
)
>=
input_width
)
{
int
im_row_idx
=
h
*
stride_height
+
h_offset
-
padding_up
;
int
im_col_idx
=
w
*
stride_width
+
w_offset
-
padding_left
;
if
(
im_row_idx
<
0
||
im_row_idx
>=
input_height
||
im_col_idx
<
0
||
im_col_idx
>=
input_width
)
{
col_data
[(
c
*
output_height
+
h
)
*
output_width
+
w
]
=
T
(
0
);
}
else
{
im_row_idx
+=
c_im
*
input_height
-
padding_up
;
im_col_idx
-=
padding_left
;
im_row_idx
+=
c_im
*
input_height
;
col_data
[(
c
*
output_height
+
h
)
*
output_width
+
w
]
=
im_data
[
im_row_idx
*
input_width
+
im_col_idx
];
}
...
...
@@ -104,14 +108,20 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kCFO,
int
output_height
=
col
.
dims
()[
3
];
int
output_width
=
col
.
dims
()[
4
];
PADDLE_ENFORCE
((
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
==
output_height
);
PADDLE_ENFORCE
((
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
==
output_width
);
PADDLE_ENFORCE_EQ
(
(
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
,
output_height
,
"Output_height and padding(padding_up, padding_down) are "
"inconsistent."
);
PADDLE_ENFORCE_EQ
(
(
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
,
output_width
,
"output_width and padding(padding_left, padding_right) are "
"inconsistent."
);
int
channels_col
=
input_channels
*
filter_height
*
filter_width
;
...
...
@@ -124,14 +134,12 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kCFO,
int
c_im
=
c
/
filter_width
/
filter_height
;
for
(
int
h
=
0
;
h
<
output_height
;
++
h
)
{
for
(
int
w
=
0
;
w
<
output_width
;
++
w
)
{
int
im_row_idx
=
h
*
stride_height
+
h_offset
;
int
im_col_idx
=
w
*
stride_width
+
w_offset
;
if
((
im_row_idx
-
padding_up
)
>=
0
&&
(
im_row_idx
-
padding_up
)
<
input_height
&&
(
im_col_idx
-
padding_left
)
>=
0
&&
(
im_col_idx
-
padding_left
)
<
input_width
)
{
im_row_idx
+=
c_im
*
input_height
-
padding_up
;
im_col_idx
-=
padding_left
;
int
im_row_idx
=
h
*
stride_height
+
h_offset
-
padding_up
;
int
im_col_idx
=
w
*
stride_width
+
w_offset
-
padding_left
;
if
((
im_row_idx
)
>=
0
&&
(
im_row_idx
)
<
input_height
&&
(
im_col_idx
)
>=
0
&&
(
im_col_idx
)
<
input_width
)
{
im_row_idx
+=
c_im
*
input_height
;
im_data
[
im_row_idx
*
input_width
+
im_col_idx
]
+=
col_data
[(
c
*
output_height
+
h
)
*
output_width
+
w
];
}
...
...
@@ -173,14 +181,20 @@ class Im2ColFunctor<paddle::operators::math::ColFormat::kOCF,
int
output_height
=
col
.
dims
()[
0
];
int
output_width
=
col
.
dims
()[
1
];
PADDLE_ENFORCE
((
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
==
output_height
);
PADDLE_ENFORCE
((
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
==
output_width
);
PADDLE_ENFORCE_EQ
(
(
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
,
output_height
,
"Output_height and padding(padding_up, padding_down) are "
"inconsistent."
);
PADDLE_ENFORCE_EQ
(
(
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
,
output_width
,
"output_width and padding(padding_left, padding_right) are "
"inconsistent."
);
const
T
*
im_data
=
im
.
data
<
T
>
();
T
*
col_data
=
col
.
data
<
T
>
();
...
...
@@ -243,14 +257,20 @@ class Col2ImFunctor<paddle::operators::math::ColFormat::kOCF,
int
output_height
=
col
.
dims
()[
0
];
int
output_width
=
col
.
dims
()[
1
];
PADDLE_ENFORCE
((
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
==
output_height
);
PADDLE_ENFORCE
((
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
==
output_width
);
PADDLE_ENFORCE_EQ
(
(
input_height
+
padding_up
+
padding_down
-
filter_height
)
/
stride_height
+
1
,
output_height
,
"Output_height and padding(padding_up, padding_down) are "
"inconsistent."
);
PADDLE_ENFORCE_EQ
(
(
input_width
+
padding_left
+
padding_right
-
filter_width
)
/
stride_width
+
1
,
output_width
,
"output_width and padding(padding_left, padding_right) are "
"inconsistent."
);
T
*
im_data
=
im
.
data
<
T
>
();
const
T
*
col_data
=
col
.
data
<
T
>
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录