Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
2321a37b
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看板
提交
2321a37b
编写于
9月 18, 2017
作者:
W
wanghaoshuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix issues
上级
6e964ad5
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
17 addition
and
12 deletion
+17
-12
paddle/operators/clip_op.cu
paddle/operators/clip_op.cu
+8
-2
paddle/operators/clip_op.h
paddle/operators/clip_op.h
+1
-1
python/paddle/v2/framework/tests/gradient_checker.py
python/paddle/v2/framework/tests/gradient_checker.py
+1
-0
python/paddle/v2/framework/tests/op_test_util.py
python/paddle/v2/framework/tests/op_test_util.py
+0
-5
python/paddle/v2/framework/tests/test_clip_op.py
python/paddle/v2/framework/tests/test_clip_op.py
+7
-4
未找到文件。
paddle/operators/clip_op.cu
浏览文件 @
2321a37b
...
...
@@ -27,7 +27,13 @@ using Tensor = framework::Tensor;
template
<
typename
T
>
__global__
void
ClipGradientKernel
(
const
int
N
,
const
T
min
,
const
T
max
,
const
T
*
Y
,
const
T
*
dY
,
T
*
dX
)
{
CUDA_1D_KERNEL_LOOP
(
i
,
N
)
{
dX
[
i
]
=
dY
[
i
]
*
(
Y
[
i
]
>
min
&&
Y
[
i
]
<
max
);
}
CUDA_1D_KERNEL_LOOP
(
i
,
N
)
{
if
(
Y
[
i
]
>
min
&&
Y
[
i
]
<
max
)
{
dX
[
i
]
=
dY
[
i
];
}
else
{
dX
[
i
]
=
0
;
}
}
}
template
<
typename
T
>
...
...
@@ -38,7 +44,7 @@ class ClipGradientOpCUDAKernel : public framework::OpKernel {
auto
min
=
context
.
op
().
Attr
<
float
>
(
"min"
);
auto
*
d_out
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_x
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
x
=
context
.
Out
put
<
Tensor
>
(
"X"
);
auto
*
x
=
context
.
In
put
<
Tensor
>
(
"X"
);
auto
dims
=
d_x
->
dims
();
size_t
count
=
1
;
for
(
int
i
=
0
;
i
<
dims
.
size
();
++
i
)
{
...
...
paddle/operators/clip_op.h
浏览文件 @
2321a37b
...
...
@@ -50,7 +50,7 @@ class ClipGradKernel : public framework::OpKernel {
auto
min
=
context
.
op
().
Attr
<
float
>
(
"min"
);
auto
*
d_out
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
d_x
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
x
=
context
.
Out
put
<
Tensor
>
(
"X"
);
auto
*
x
=
context
.
In
put
<
Tensor
>
(
"X"
);
auto
dims
=
d_x
->
dims
();
size_t
count
=
1
;
for
(
int
i
=
0
;
i
<
dims
.
size
();
++
i
)
{
...
...
python/paddle/v2/framework/tests/gradient_checker.py
浏览文件 @
2321a37b
...
...
@@ -238,6 +238,7 @@ class GradientChecker(unittest.TestCase):
:type msf_prefix: string
"""
for
a
,
b
,
name
in
itertools
.
izip
(
numeric_grads
,
analytic_grads
,
names
):
print
"a=%s ; b=%s"
%
(
a
,
b
)
abs_a
=
numpy
.
abs
(
a
)
# if abs_a is nearly zero, then use abs error for a, not relative
# error.
...
...
python/paddle/v2/framework/tests/op_test_util.py
浏览文件 @
2321a37b
...
...
@@ -34,10 +34,8 @@ class OpTestMeta(type):
arr
=
self
.
inputs
[
in_name
]
var
.
set_dims
(
arr
.
shape
)
var
.
set
(
arr
,
place
)
print
"var: %s"
%
in_name
else
:
kwargs
[
in_name
]
=
"@EMPTY@"
print
"var: %s=EMPTY"
%
in_name
for
out_name
in
Operator
.
get_op_output_names
(
self
.
type
):
if
not
hasattr
(
self
,
"outputs"
):
...
...
@@ -48,7 +46,6 @@ class OpTestMeta(type):
(
out_name
))
kwargs
[
out_name
]
=
out_name
scope
.
new_var
(
out_name
).
get_tensor
()
print
"var: %s"
%
out_name
for
attr_name
in
Operator
.
get_op_attr_names
(
self
.
type
):
if
hasattr
(
self
,
"attrs"
)
and
attr_name
in
self
.
attrs
:
...
...
@@ -65,9 +62,7 @@ class OpTestMeta(type):
for
out_name
in
Operator
.
get_op_output_names
(
self
.
type
):
actual
=
numpy
.
array
(
scope
.
find_var
(
out_name
).
get_tensor
())
print
"actual: %s"
%
actual
expect
=
self
.
outputs
[
out_name
]
print
"expect: %s"
%
expect
self
.
assertTrue
(
numpy
.
allclose
(
actual
,
expect
,
atol
=
1e-05
),
...
...
python/paddle/v2/framework/tests/test_clip_op.py
浏览文件 @
2321a37b
...
...
@@ -5,12 +5,13 @@ from gradient_checker import GradientChecker
from
op_test_util
import
OpTestMeta
class
Test
ClipOp
(
unittest
.
TestCase
):
class
ClipOp
(
unittest
.
TestCase
):
__metaclass__
=
OpTestMeta
def
setUp
(
self
):
input
=
np
.
random
.
random
((
16
,
16
)).
astype
(
"float32"
)
print
"input: %s"
%
input
input
[
np
.
abs
(
input
-
0.1
)
<
0.05
]
=
0.5
input
[
np
.
abs
(
input
-
0.9
)
<
0.05
]
=
0.5
self
.
type
=
"clip"
self
.
inputs
=
{
'X'
:
input
,
}
self
.
attrs
=
{}
...
...
@@ -24,14 +25,16 @@ class TestClipOp(unittest.TestCase):
class
TestClipGradOp
(
GradientChecker
):
def
setUp
(
self
):
input
=
np
.
random
.
random
((
8
,
8
)).
astype
(
"float32"
)
print
"input: %s"
%
input
self
.
op
=
Operator
(
type
=
"clip"
,
X
=
"X"
,
Out
=
"Out"
,
min
=
0.1
,
max
=
0.9
)
self
.
inputs
=
{
'X'
:
np
.
random
.
random
((
16
,
16
)).
astype
(
"float32"
)
,
}
self
.
inputs
=
{
'X'
:
input
,
}
def
test_normal
(
self
):
self
.
check_grad
(
self
.
op
,
self
.
inputs
,
set
([
"X"
]),
"Out"
,
max_relative_error
=
0.5
)
def
t
est
_cpu_gpu_compare
(
self
):
def
t_cpu_gpu_compare
(
self
):
self
.
compare_grad
(
self
.
op
,
self
.
inputs
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录