Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
0652f158
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看板
提交
0652f158
编写于
10月 10, 2019
作者:
Z
Zhang Ting
提交者:
Aurelius84
10月 10, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix Attr(scale)'s bug for image_resize and modified unittest, test=develop (#19983)
上级
7c122189
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
35 addition
and
31 deletion
+35
-31
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+5
-2
python/paddle/fluid/tests/unittests/test_nearest_interp_op.py
...on/paddle/fluid/tests/unittests/test_nearest_interp_op.py
+24
-26
python/paddle/fluid/tests/unittests/test_trilinear_interp_op.py
.../paddle/fluid/tests/unittests/test_trilinear_interp_op.py
+6
-3
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
0652f158
...
@@ -9397,10 +9397,13 @@ def image_resize(input,
...
@@ -9397,10 +9397,13 @@ def image_resize(input,
if isinstance(scale, Variable):
if isinstance(scale, Variable):
scale.stop_gradient = True
scale.stop_gradient = True
inputs["Scale"] = scale
inputs["Scale"] = scale
if isinstance(scale, floa
t):
elif isinstance(scale, float) or isinstance(scale, in
t):
if scale <= 0:
if scale <= 0:
raise ValueError("
scale
should be greater than zero.")
raise ValueError("
Attr(scale)
should be greater than zero.")
attrs['scale'] = float(scale)
attrs['scale'] = float(scale)
else:
raise TypeError(
"Attr(scale)'s type should be float, int or Variable.")
if isinstance(actual_shape, Variable):
if isinstance(actual_shape, Variable):
warnings.warn(
warnings.warn(
...
...
python/paddle/fluid/tests/unittests/test_nearest_interp_op.py
100644 → 100755
浏览文件 @
0652f158
...
@@ -425,26 +425,14 @@ class TestNearestInterp_attr_tensor_Case3(TestNearestInterpOp_attr_tensor):
...
@@ -425,26 +425,14 @@ class TestNearestInterp_attr_tensor_Case3(TestNearestInterpOp_attr_tensor):
class
TestNearestAPI
(
OpTest
):
class
TestNearestAPI
(
OpTest
):
def
test_case
(
self
):
def
test_case
(
self
):
x
=
fluid
.
layers
.
data
(
name
=
"x"
,
shape
=
[
3
,
6
,
6
],
dtype
=
"float32"
)
x
=
fluid
.
data
(
name
=
"x"
,
shape
=
[
1
,
3
,
6
,
6
],
dtype
=
"float32"
)
y
=
fluid
.
layers
.
data
(
name
=
"y"
,
shape
=
[
6
,
6
,
3
],
dtype
=
"float32"
)
y
=
fluid
.
data
(
name
=
"y"
,
shape
=
[
1
,
6
,
6
,
3
],
dtype
=
"float32"
)
dim
=
fluid
.
layers
.
data
(
dim
=
fluid
.
data
(
name
=
"dim"
,
shape
=
[
1
],
dtype
=
"int32"
)
name
=
"dim"
,
shape
=
[
1
],
dtype
=
"int32"
,
append_batch_size
=
False
)
shape_tensor
=
fluid
.
data
(
name
=
"shape_tensor"
,
shape
=
[
2
],
dtype
=
"int32"
)
shape_tensor
=
fluid
.
layers
.
data
(
actual_size
=
fluid
.
data
(
name
=
"actual_size"
,
shape
=
[
2
],
dtype
=
"int32"
)
name
=
"shape_tensor"
,
scale_tensor
=
fluid
.
data
(
shape
=
[
2
],
name
=
"scale_tensor"
,
shape
=
[
1
],
dtype
=
"float32"
)
dtype
=
"int32"
,
append_batch_size
=
False
)
actual_size
=
fluid
.
layers
.
data
(
name
=
"actual_size"
,
shape
=
[
2
],
dtype
=
"int32"
,
append_batch_size
=
False
)
scale_tensor
=
fluid
.
layers
.
data
(
name
=
"scale_tensor"
,
shape
=
[
1
],
dtype
=
"float32"
,
append_batch_size
=
False
)
out1
=
fluid
.
layers
.
resize_nearest
(
out1
=
fluid
.
layers
.
resize_nearest
(
y
,
out_shape
=
[
12
,
12
],
data_format
=
'NHWC'
)
y
,
out_shape
=
[
12
,
12
],
data_format
=
'NHWC'
)
...
@@ -481,15 +469,25 @@ class TestNearestAPI(OpTest):
...
@@ -481,15 +469,25 @@ class TestNearestAPI(OpTest):
for
i
in
range
(
len
(
results
)
-
1
):
for
i
in
range
(
len
(
results
)
-
1
):
self
.
assertTrue
(
np
.
allclose
(
results
[
i
+
1
],
expect_res
))
self
.
assertTrue
(
np
.
allclose
(
results
[
i
+
1
],
expect_res
))
class
TestNearestInterpException
(
OpTest
):
def
test_exception
(
self
):
def
test_exception
(
self
):
input
=
fluid
.
data
(
name
=
"input"
,
shape
=
[
1
,
3
,
6
,
6
],
dtype
=
"float32"
)
def
attr_data_format
():
# for 4-D input, data_format can only be NCHW or NHWC
# for 4-D input, data_format can only be NCHW or NHWC
input
=
fluid
.
layers
.
data
(
name
=
"input"
,
shape
=
[
3
,
6
,
6
],
dtype
=
"float32"
)
try
:
out
=
fluid
.
layers
.
resize_nearest
(
out
=
fluid
.
layers
.
resize_nearest
(
input
,
out_shape
=
[
4
,
8
],
data_format
=
'NDHWC'
)
input
,
out_shape
=
[
4
,
8
],
data_format
=
'NDHWC'
)
except
:
pass
def
attr_scale_type
():
out
=
fluid
.
layers
.
resize_nearest
(
input
,
scale
=
'scale'
)
def
attr_scale_value
():
out
=
fluid
.
layers
.
resize_nearest
(
input
,
scale
=-
0.3
)
self
.
assertRaises
(
ValueError
,
attr_data_format
)
self
.
assertRaises
(
TypeError
,
attr_scale_type
)
self
.
assertRaises
(
ValueError
,
attr_scale_value
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
python/paddle/fluid/tests/unittests/test_trilinear_interp_op.py
100644 → 100755
浏览文件 @
0652f158
...
@@ -625,15 +625,18 @@ class TestTrilinearInterpAPI(OpTest):
...
@@ -625,15 +625,18 @@ class TestTrilinearInterpAPI(OpTest):
for
i
in
range
(
len
(
results
)
-
1
):
for
i
in
range
(
len
(
results
)
-
1
):
self
.
assertTrue
(
np
.
allclose
(
results
[
i
+
1
],
expect_res
))
self
.
assertTrue
(
np
.
allclose
(
results
[
i
+
1
],
expect_res
))
class
TestTrilinearInterpOpException
(
OpTest
):
def
test_exception
(
self
):
def
test_exception
(
self
):
input
=
fluid
.
layers
.
data
(
input
=
fluid
.
layers
.
data
(
name
=
"input"
,
shape
=
[
3
,
6
,
9
,
4
],
dtype
=
"float32"
)
name
=
"input"
,
shape
=
[
3
,
6
,
9
,
4
],
dtype
=
"float32"
)
try
:
def
attr_data_format
():
# for 5-D input, data_format only can be NCDHW or NDHWC
# for 5-D input, data_format only can be NCDHW or NDHWC
out
=
fluid
.
layers
.
resize_trilinear
(
out
=
fluid
.
layers
.
resize_trilinear
(
input
,
out_shape
=
[
4
,
8
,
4
],
data_format
=
'NHWC'
)
input
,
out_shape
=
[
4
,
8
,
4
],
data_format
=
'NHWC'
)
except
:
pass
self
.
assertRaises
(
ValueError
,
attr_data_format
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录