Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
9107bf20
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9107bf20
编写于
11月 29, 2019
作者:
A
Adam
提交者:
Tao Luo
11月 29, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add template version of UpdatePadding (#21426)
test=develop
上级
ca879e5a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
21 deletion
+26
-21
paddle/fluid/operators/conv_op.h
paddle/fluid/operators/conv_op.h
+12
-10
paddle/fluid/operators/pool_op.h
paddle/fluid/operators/pool_op.h
+14
-11
未找到文件。
paddle/fluid/operators/conv_op.h
浏览文件 @
9107bf20
...
...
@@ -64,17 +64,19 @@ inline int ConvOutputSize(int input_size, int filter_size, int dilation,
return
output_size
;
}
inline
void
UpdatePaddingAndDilation
(
std
::
vector
<
int
>*
paddings
,
std
::
vector
<
int
>*
dilation
,
template
<
typename
T
=
int
>
inline
void
UpdatePaddingAndDilation
(
std
::
vector
<
T
>*
paddings
,
std
::
vector
<
T
>*
dilation
,
const
std
::
string
padding_algorithm
,
const
framework
::
DDim
data_dims
,
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
ksize
)
{
const
std
::
vector
<
T
>&
strides
,
const
std
::
vector
<
T
>&
ksize
)
{
// set padding size == data_dims.size() * 2
auto
data_shape
=
framework
::
vectorize
<
int
>
(
data_dims
);
auto
data_shape
=
framework
::
vectorize
<
T
>
(
data_dims
);
if
(
static_cast
<
int
>
(
paddings
->
size
())
==
data_dims
.
size
())
{
for
(
int
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
copy_pad
=
*
(
paddings
->
begin
()
+
2
*
i
);
T
copy_pad
=
*
(
paddings
->
begin
()
+
2
*
i
);
paddings
->
insert
(
paddings
->
begin
()
+
2
*
i
+
1
,
copy_pad
);
}
}
else
{
...
...
@@ -86,11 +88,11 @@ inline void UpdatePaddingAndDilation(std::vector<int>* paddings,
// when padding_algorithm is "VALID" or "SAME"
if
(
padding_algorithm
==
"SAME"
)
{
for
(
int
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
out_size
=
(
data_dims
[
i
]
+
strides
[
i
]
-
1
)
/
strides
[
i
];
int
pad_sum
=
T
out_size
=
(
data_dims
[
i
]
+
strides
[
i
]
-
1
)
/
strides
[
i
];
T
pad_sum
=
std
::
max
((
out_size
-
1
)
*
strides
[
i
]
+
ksize
[
i
]
-
data_shape
[
i
],
0
);
int
pad_0
=
pad_sum
/
2
;
int
pad_1
=
pad_sum
-
pad_0
;
T
pad_0
=
pad_sum
/
2
;
T
pad_1
=
pad_sum
-
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
)
=
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
+
1
)
=
pad_1
;
...
...
paddle/fluid/operators/pool_op.h
浏览文件 @
9107bf20
...
...
@@ -57,17 +57,19 @@ class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker {
public:
void
Make
()
override
;
};
inline
void
UpdatePadding
(
std
::
vector
<
int
>*
paddings
,
const
bool
global_pooling
,
template
<
typename
T
=
int
>
inline
void
UpdatePadding
(
std
::
vector
<
T
>*
paddings
,
const
bool
global_pooling
,
const
bool
adaptive
,
const
std
::
string
padding_algorithm
,
const
framework
::
DDim
data_dims
,
const
std
::
vector
<
int
>&
strides
,
const
std
::
vector
<
int
>&
ksize
)
{
const
std
::
vector
<
T
>&
strides
,
const
std
::
vector
<
T
>&
ksize
)
{
// set padding size == data_dims.size() * 2
auto
data_shape
=
framework
::
vectorize
<
int
>
(
data_dims
);
auto
data_shape
=
framework
::
vectorize
<
T
>
(
data_dims
);
if
(
static_cast
<
int
>
(
paddings
->
size
())
==
data_dims
.
size
())
{
for
(
int
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
copy_pad
=
*
(
paddings
->
begin
()
+
2
*
i
);
T
copy_pad
=
*
(
paddings
->
begin
()
+
2
*
i
);
paddings
->
insert
(
paddings
->
begin
()
+
2
*
i
+
1
,
copy_pad
);
}
}
else
{
...
...
@@ -79,11 +81,11 @@ inline void UpdatePadding(std::vector<int>* paddings, const bool global_pooling,
// when padding_algorithm is "VALID" or "SAME"
if
(
padding_algorithm
==
"SAME"
)
{
for
(
int
i
=
0
;
i
<
data_dims
.
size
();
++
i
)
{
int
out_size
=
(
data_dims
[
i
]
+
strides
[
i
]
-
1
)
/
strides
[
i
];
int
pad_sum
=
T
out_size
=
(
data_dims
[
i
]
+
strides
[
i
]
-
1
)
/
strides
[
i
];
T
pad_sum
=
std
::
max
((
out_size
-
1
)
*
strides
[
i
]
+
ksize
[
i
]
-
data_shape
[
i
],
0
);
int
pad_0
=
pad_sum
/
2
;
int
pad_1
=
pad_sum
-
pad_0
;
T
pad_0
=
pad_sum
/
2
;
T
pad_1
=
pad_sum
-
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
)
=
pad_0
;
*
(
paddings
->
begin
()
+
i
*
2
+
1
)
=
pad_1
;
}
...
...
@@ -101,11 +103,12 @@ inline void UpdatePadding(std::vector<int>* paddings, const bool global_pooling,
}
}
inline
void
UpdateKsize
(
std
::
vector
<
int
>*
ksize
,
template
<
typename
T
=
int
>
inline
void
UpdateKsize
(
std
::
vector
<
T
>*
ksize
,
const
framework
::
DDim
data_dims
)
{
ksize
->
resize
(
static_cast
<
size_t
>
(
data_dims
.
size
()));
for
(
size_t
i
=
0
;
i
<
ksize
->
size
();
++
i
)
{
*
(
ksize
->
begin
()
+
i
)
=
static_cast
<
int
>
(
data_dims
[
i
]);
*
(
ksize
->
begin
()
+
i
)
=
static_cast
<
T
>
(
data_dims
[
i
]);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录