Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
f31217fc
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f31217fc
编写于
9月 11, 2017
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issues
上级
ba8a5c15
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
12 deletion
+14
-12
paddle/operators/pad_op.cc
paddle/operators/pad_op.cc
+3
-2
paddle/operators/pad_op.h
paddle/operators/pad_op.h
+11
-10
未找到文件。
paddle/operators/pad_op.cc
浏览文件 @
f31217fc
...
...
@@ -27,10 +27,10 @@ class PadOp : public framework::OperatorWithKernel {
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
x_dim
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
();
auto
paddings
=
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
PADDLE_ENFORCE_EQ
(
x_dim
.
size
()
*
2
,
int
(
paddings
.
size
()),
PADDLE_ENFORCE_EQ
(
x_dim
.
size
()
*
2
,
int
64_t
(
paddings
.
size
()),
"Size of paddings should be equal to 2 * dimension size "
"of input tensor."
);
std
::
vector
<
int
>
out_dims
(
x_dim
.
size
());
std
::
vector
<
int
64_t
>
out_dims
(
x_dim
.
size
());
for
(
int
i
=
0
;
i
<
x_dim
.
size
();
++
i
)
{
out_dims
[
i
]
=
x_dim
[
i
]
+
paddings
[
i
*
2
]
+
paddings
[
i
*
2
+
1
];
}
...
...
@@ -95,6 +95,7 @@ class PadOpGrad : public framework::OperatorWithKernel {
"Input(Out@GRAD) should not be null"
);
auto
x_dims
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
();
auto
*
x_grad
=
ctx
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
PADDLE_ENFORCE_NOT_NULL
(
x_grad
,
"Output(X@GRAD) should not be null"
);
x_grad
->
Resize
(
x_dims
);
}
...
...
paddle/operators/pad_op.h
浏览文件 @
f31217fc
...
...
@@ -28,18 +28,17 @@ using EigenTensor = framework::EigenTensor<T, D, MajorType, IndexType>;
template
<
typename
Place
,
typename
T
,
size_t
D
>
void
PadFunction
(
const
framework
::
ExecutionContext
&
context
)
{
auto
pads
=
context
.
Get
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
pads
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
Eigen
::
array
<
std
::
pair
<
int
,
int
>
,
D
>
paddings
;
for
(
int
i
=
0
;
i
<
paddings
.
size
();
++
i
)
{
paddings
[
i
].
first
=
pads
[
i
*
2
];
paddings
[
i
].
second
=
pads
[
i
*
2
+
1
];
}
T
pad_value
=
context
.
Get
Attr
<
T
>
(
"pad_value"
);
T
pad_value
=
context
.
Attr
<
T
>
(
"pad_value"
);
auto
*
x
=
context
.
Input
<
Tensor
>
(
"X"
);
auto
*
out
=
context
.
Output
<
Tensor
>
(
"Out"
);
out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
dims
=
x
->
dims
();
auto
x_tensor
=
EigenTensor
<
T
,
D
>::
From
(
*
x
);
auto
out_tensor
=
EigenTensor
<
T
,
D
>::
From
(
*
out
);
...
...
@@ -51,8 +50,8 @@ template <typename Place, typename T>
class
PadKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
int
dim
=
context
.
Input
<
Tensor
>
(
"X"
)
->
dims
().
size
();
switch
(
dim
)
{
int
rank
=
context
.
Input
<
Tensor
>
(
"X"
)
->
dims
().
size
();
switch
(
rank
)
{
case
1
:
PadFunction
<
Place
,
T
,
1
>
(
context
);
break
;
...
...
@@ -72,14 +71,15 @@ class PadKernel : public framework::OpKernel {
PadFunction
<
Place
,
T
,
6
>
(
context
);
break
;
default:
PADDLE_THROW
(
"Only ranks up to 6 supported."
);
PADDLE_THROW
(
"PadOp only support tensors with no more than 6 dimensions."
);
}
}
};
template
<
typename
Place
,
typename
T
,
size_t
D
>
void
PadGradFunction
(
const
framework
::
ExecutionContext
&
context
)
{
auto
pads
=
context
.
Get
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
auto
pads
=
context
.
Attr
<
std
::
vector
<
int
>>
(
"paddings"
);
Eigen
::
array
<
std
::
pair
<
int
,
int
>
,
D
>
paddings
;
for
(
int
i
=
0
;
i
<
paddings
.
size
();
++
i
)
{
paddings
[
i
].
first
=
-
pads
[
i
*
2
];
...
...
@@ -99,9 +99,9 @@ template <typename Place, typename T>
class
PadGradKernel
:
public
framework
::
OpKernel
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
size_t
dim
=
size_t
rank
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
))
->
dims
().
size
();
switch
(
dim
)
{
switch
(
rank
)
{
case
1
:
PadGradFunction
<
Place
,
T
,
1
>
(
context
);
break
;
...
...
@@ -121,7 +121,8 @@ class PadGradKernel : public framework::OpKernel {
PadGradFunction
<
Place
,
T
,
6
>
(
context
);
break
;
default:
PADDLE_THROW
(
"Only ranks up to 6 supported."
);
PADDLE_THROW
(
"PadOp only support tensors with no more than 6 dimensions."
);
}
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录