Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
9f8e4981
P
Paddle
项目概览
Crayon鑫
/
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看板
提交
9f8e4981
编写于
9月 06, 2017
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix some issues.
上级
6684b55b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
11 deletion
+19
-11
paddle/operators/pad_op.cc
paddle/operators/pad_op.cc
+3
-0
paddle/operators/pad_op.h
paddle/operators/pad_op.h
+5
-5
python/paddle/v2/framework/op.py
python/paddle/v2/framework/op.py
+1
-1
python/paddle/v2/framework/tests/test_pad_op.py
python/paddle/v2/framework/tests/test_pad_op.py
+10
-5
未找到文件。
paddle/operators/pad_op.cc
浏览文件 @
9f8e4981
...
...
@@ -27,6 +27,9 @@ class PadOp : public framework::OperatorWithKernel {
void
InferShape
(
const
framework
::
InferShapeContext
&
ctx
)
const
override
{
auto
dim0
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
();
auto
paddings
=
GetAttr
<
std
::
vector
<
std
::
pair
<
int
,
int
>>>
(
"paddings"
);
PADDLE_ENFORCE_EQ
(
dim0
.
size
(),
paddings
.
size
(),
"Paddings size should be equal to dimension size of input tensor."
);
std
::
vector
<
int
>
dim1
(
dim0
.
size
());
for
(
int
i
=
0
;
i
<
dim0
.
size
();
++
i
)
{
dim1
[
i
]
=
dim0
[
i
]
+
paddings
[
i
].
first
+
paddings
[
i
].
second
;
...
...
paddle/operators/pad_op.h
浏览文件 @
9f8e4981
...
...
@@ -14,8 +14,6 @@
#pragma once
#include "paddle/operators/math/math_function.h"
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
...
...
@@ -30,12 +28,13 @@ 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
.
op_
.
GetAttr
<
std
::
vector
<
std
::
pair
<
int
,
int
>>>
(
"paddings"
);
auto
pads
=
context
.
op
().
GetAttr
<
std
::
vector
<
std
::
pair
<
int
,
int
>>>
(
"paddings"
);
Eigen
::
array
<
std
::
pair
<
int
,
int
>
,
D
>
paddings
;
for
(
int
i
=
0
;
i
<
pads
.
size
();
++
i
)
{
paddings
[
i
]
=
pads
[
i
];
}
T
pad_value
=
context
.
op
_
.
GetAttr
<
T
>
(
"pad_value"
);
T
pad_value
=
context
.
op
()
.
GetAttr
<
T
>
(
"pad_value"
);
auto
*
X
=
context
.
Input
<
Tensor
>
(
"X"
);
auto
*
Out
=
context
.
Output
<
Tensor
>
(
"Out"
);
...
...
@@ -80,7 +79,8 @@ class PadKernel : public framework::OpKernel {
template
<
typename
Place
,
typename
T
,
size_t
D
>
void
PadGradFunction
(
const
framework
::
ExecutionContext
&
context
)
{
auto
pads
=
context
.
op_
.
GetAttr
<
std
::
vector
<
std
::
pair
<
int
,
int
>>>
(
"paddings"
);
auto
pads
=
context
.
op
().
GetAttr
<
std
::
vector
<
std
::
pair
<
int
,
int
>>>
(
"paddings"
);
Eigen
::
array
<
std
::
pair
<
int
,
int
>
,
D
>
paddings
;
for
(
int
i
=
0
;
i
<
pads
.
size
();
++
i
)
{
paddings
[
0
].
first
=
-
paddings
[
0
].
first
;
...
...
python/paddle/v2/framework/op.py
浏览文件 @
9f8e4981
...
...
@@ -96,7 +96,7 @@ class OpDescCreationMethod(object):
new_attr
.
strings
.
extend
(
user_defined_attr
)
elif
attr
.
type
==
framework_pb2
.
INT_PAIRS
:
for
p
in
user_defined_attr
:
pair
=
new_attr
.
pairs
.
add
()
pair
=
new_attr
.
int_
pairs
.
add
()
pair
.
first
=
p
[
0
]
pair
.
second
=
p
[
1
]
else
:
...
...
python/paddle/v2/framework/tests/test_pad_op.py
浏览文件 @
9f8e4981
...
...
@@ -22,17 +22,22 @@ class TestPadOp(unittest.TestCase):
}
class
PadGradOpTest
(
GradientChecker
):
def
test_pad
(
self
):
op
=
Operator
(
class
TestPadGradOp
(
GradientChecker
):
def
setUp
(
self
):
self
.
op
=
Operator
(
type
=
"pad"
,
X
=
"X"
,
Out
=
"Out"
,
paddings
=
[(
0
,
1
),
(
2
,
3
)],
pad_value
=
0
)
inputs
=
{
'X'
:
np
.
random
.
random
((
16
,
16
)).
astype
(
"float32"
),
}
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
16
,
16
)).
astype
(
"float32"
),
}
def
test_normal
(
self
):
self
.
check_grad
(
self
.
op
,
self
.
inputs
,
set
([
"X"
]),
"Out"
,
max_relative_error
=
0.5
)
self
.
check_grad
(
op
,
inputs
,
set
([
"X"
]),
"Out"
,
max_relative_error
=
0.5
)
def
test_cpu_gpu_compare
(
self
):
self
.
compare_grad
(
self
.
op
,
self
.
inputs
)
if
__name__
==
'__main__'
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录