Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
29b844ad
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看板
未验证
提交
29b844ad
编写于
9月 03, 2020
作者:
Y
Yang Zhang
提交者:
GitHub
9月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix clip op attr (#26924)
上级
26c698e2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
14 addition
and
11 deletion
+14
-11
paddle/fluid/operators/clip_op.h
paddle/fluid/operators/clip_op.h
+7
-4
python/paddle/fluid/tests/unittests/test_clip_op.py
python/paddle/fluid/tests/unittests/test_clip_op.py
+5
-2
python/paddle/tensor/math.py
python/paddle/tensor/math.py
+2
-5
未找到文件。
paddle/fluid/operators/clip_op.h
浏览文件 @
29b844ad
...
...
@@ -66,7 +66,7 @@ template <typename DeviceContext, typename T>
class
ClipKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
max
=
context
.
Attr
<
T
>
(
"max"
);
auto
max
=
static_cast
<
T
>
(
context
.
Attr
<
float
>
(
"max"
)
);
Tensor
max_cpu
;
if
(
context
.
HasInput
(
"Max"
))
{
auto
*
max_t
=
context
.
Input
<
Tensor
>
(
"Max"
);
...
...
@@ -77,8 +77,9 @@ class ClipKernel : public framework::OpKernel<T> {
}
max
=
max_data
[
0
];
}
max
=
static_cast
<
T
>
(
max
);
auto
min
=
context
.
Attr
<
T
>
(
"min"
);
auto
min
=
context
.
Attr
<
float
>
(
"min"
);
Tensor
min_cpu
;
if
(
context
.
HasInput
(
"Min"
))
{
auto
*
min_t
=
context
.
Input
<
Tensor
>
(
"Min"
);
...
...
@@ -141,7 +142,7 @@ template <typename DeviceContext, typename T>
class
ClipGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
max
=
context
.
Attr
<
T
>
(
"max"
);
auto
max
=
static_cast
<
T
>
(
context
.
Attr
<
float
>
(
"max"
)
);
Tensor
max_cpu
;
if
(
context
.
HasInput
(
"Max"
))
{
auto
*
max_t
=
context
.
Input
<
Tensor
>
(
"Max"
);
...
...
@@ -152,8 +153,9 @@ class ClipGradKernel : public framework::OpKernel<T> {
}
max
=
max_data
[
0
];
}
max
=
static_cast
<
T
>
(
max
);
auto
min
=
context
.
Attr
<
T
>
(
"min"
);
auto
min
=
context
.
Attr
<
float
>
(
"min"
);
Tensor
min_cpu
;
if
(
context
.
HasInput
(
"Min"
))
{
auto
*
min_t
=
context
.
Input
<
Tensor
>
(
"Min"
);
...
...
@@ -164,6 +166,7 @@ class ClipGradKernel : public framework::OpKernel<T> {
}
min
=
min_data
[
0
];
}
min
=
static_cast
<
T
>
(
min
);
auto
*
d_out
=
context
.
Input
<
framework
::
LoDTensor
>
(
framework
::
GradVarName
(
"Out"
));
...
...
python/paddle/fluid/tests/unittests/test_clip_op.py
浏览文件 @
29b844ad
...
...
@@ -138,8 +138,9 @@ class TestClipAPI(unittest.TestCase):
out_6
=
paddle
.
clip
(
images
,
max
=
max
)
out_7
=
paddle
.
clip
(
images
,
max
=-
1.
)
out_8
=
paddle
.
clip
(
images
)
out_9
=
paddle
.
clip
(
paddle
.
cast
(
images
,
'float64'
),
min
=
0.2
,
max
=
0.9
)
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
=
exe
.
run
(
res1
,
res2
,
res3
,
res4
,
res5
,
res6
,
res7
,
res8
,
res9
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
{
"image"
:
data
,
...
...
@@ -147,7 +148,7 @@ class TestClipAPI(unittest.TestCase):
"max"
:
np
.
array
([
0.8
]).
astype
(
'float32'
)
},
fetch_list
=
[
out_1
,
out_2
,
out_3
,
out_4
,
out_5
,
out_6
,
out_7
,
out_8
out_1
,
out_2
,
out_3
,
out_4
,
out_5
,
out_6
,
out_7
,
out_8
,
out_9
])
self
.
assertTrue
(
np
.
allclose
(
res1
,
data
.
clip
(
0.2
,
0.8
)))
...
...
@@ -158,6 +159,8 @@ class TestClipAPI(unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
res6
,
data
.
clip
(
max
=
0.8
)))
self
.
assertTrue
(
np
.
allclose
(
res7
,
data
.
clip
(
max
=-
1
)))
self
.
assertTrue
(
np
.
allclose
(
res8
,
data
))
self
.
assertTrue
(
np
.
allclose
(
res9
,
data
.
astype
(
np
.
float64
).
clip
(
0.2
,
0.9
)))
def
test_clip_dygraph
(
self
):
place
=
fluid
.
CUDAPlace
(
0
)
if
fluid
.
core
.
is_compiled_with_cuda
(
...
...
python/paddle/tensor/math.py
浏览文件 @
29b844ad
...
...
@@ -1611,11 +1611,8 @@ def clip(x, min=None, max=None, name=None):
# [[4.5, 6.4]
"""
np_dtype
=
np
.
float32
if
x
.
dtype
==
VarDesc
.
VarType
.
FP64
:
np_dtype
=
np
.
float64
fmin
=
float
(
np
.
finfo
(
np_dtype
).
min
)
fmax
=
float
(
np
.
finfo
(
np_dtype
).
max
)
fmin
=
float
(
np
.
finfo
(
np
.
float32
).
min
)
fmax
=
float
(
np
.
finfo
(
np
.
float32
).
max
)
if
in_dygraph_mode
():
if
isinstance
(
min
,
Variable
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录