Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
bc150edc
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看板
未验证
提交
bc150edc
编写于
11月 23, 2021
作者:
W
Wangzheee
提交者:
GitHub
11月 23, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Paddle Inference] Fix_nearest: align_corners != true (#37368)
* fix_nearest * fix_nearest * fix_nearest * fix_nearest
上级
ccad31f5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
32 deletion
+37
-32
paddle/fluid/inference/tensorrt/convert/nearest_interp_op.cc
paddle/fluid/inference/tensorrt/convert/nearest_interp_op.cc
+4
-2
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+28
-27
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_nearest_interp.py
...unittests/ir/inference/test_trt_convert_nearest_interp.py
+2
-0
python/paddle/fluid/tests/unittests/ir/inference/test_trt_nearest_interp_op.py
...ests/unittests/ir/inference/test_trt_nearest_interp_op.py
+3
-3
未找到文件。
paddle/fluid/inference/tensorrt/convert/nearest_interp_op.cc
浏览文件 @
bc150edc
...
@@ -38,8 +38,10 @@ class NearestInterpolateOpConverter : public OpConverter {
...
@@ -38,8 +38,10 @@ class NearestInterpolateOpConverter : public OpConverter {
auto
input
=
engine_
->
GetITensor
(
input_name
);
auto
input
=
engine_
->
GetITensor
(
input_name
);
auto
data_layout
=
framework
::
StringToDataLayout
(
auto
data_layout
=
!
op_desc
.
HasAttr
(
"data_layout"
)
BOOST_GET_CONST
(
std
::
string
,
op_desc
.
GetAttr
(
"data_layout"
)));
?
framework
::
DataLayout
::
kNCHW
:
framework
::
StringToDataLayout
(
BOOST_GET_CONST
(
std
::
string
,
op_desc
.
GetAttr
(
"data_layout"
)));
auto
interp_method
=
auto
interp_method
=
BOOST_GET_CONST
(
std
::
string
,
op_desc
.
GetAttr
(
"interp_method"
));
BOOST_GET_CONST
(
std
::
string
,
op_desc
.
GetAttr
(
"interp_method"
));
bool
align_corners
=
bool
align_corners
=
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
bc150edc
...
@@ -667,43 +667,44 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
...
@@ -667,43 +667,44 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
}
}
if
(
op_type
==
"nearest_interp"
)
{
if
(
op_type
==
"nearest_interp"
)
{
std
::
vector
<
std
::
string
>
attrs
{
"data_layout"
,
"interp_method"
,
std
::
vector
<
std
::
string
>
attrs
{
"interp_method"
,
"align_corners"
,
"scale"
,
"align_corners"
,
"scale"
,
"out_h"
,
"out_w"
};
"out_h"
,
"out_w"
};
for
(
auto
const
attr
:
attrs
)
{
for
(
auto
const
attr
:
attrs
)
{
if
(
!
desc
.
HasAttr
(
attr
))
return
false
;
if
(
!
desc
.
HasAttr
(
attr
))
return
false
;
}
}
auto
data_layout
=
framework
::
StringToDataLayout
(
if
(
desc
.
HasAttr
(
"data_layout"
))
{
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"data_layout"
)));
auto
data_layout
=
framework
::
StringToDataLayout
(
if
(
data_layout
!=
framework
::
DataLayout
::
kNCHW
&&
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"data_layout"
)));
data_layout
!=
framework
::
DataLayout
::
kNHWC
)
if
(
data_layout
!=
framework
::
DataLayout
::
kNCHW
&&
return
false
;
data_layout
!=
framework
::
DataLayout
::
kNHWC
)
return
false
;
}
auto
interp_method
=
auto
interp_method
=
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"interp_method"
));
BOOST_GET_CONST
(
std
::
string
,
desc
.
GetAttr
(
"interp_method"
));
if
(
interp_method
!=
"nearest"
)
return
false
;
if
(
interp_method
!=
"nearest"
)
return
false
;
auto
scale
=
BOOST_GET_CONST
(
float
,
desc
.
GetAttr
(
"scale"
));
if
(
!
desc
.
HasAttr
(
"scale"
)
||
!
desc
.
HasAttr
(
"out_h"
)
||
auto
out_h
=
BOOST_GET_CONST
(
int
,
desc
.
GetAttr
(
"out_h"
));
!
desc
.
HasAttr
(
"out_w"
))
{
auto
out_w
=
BOOST_GET_CONST
(
int
,
desc
.
GetAttr
(
"out_w"
));
return
false
;
auto
align_corners
=
BOOST_GET_CONST
(
bool
,
desc
.
GetAttr
(
"align_corners"
));
}
else
{
if
(
!
(
scale
>
0.
f
&&
(
out_h
<=
0
&&
out_w
<=
0
)))
{
auto
scale
=
BOOST_GET_CONST
(
float
,
desc
.
GetAttr
(
"scale"
));
if
(
out_h
<=
0
)
{
auto
out_h
=
BOOST_GET_CONST
(
int
,
desc
.
GetAttr
(
"out_h"
));
VLOG
(
3
)
<<
"out_h must be greater than 0 if scale is not set."
;
auto
out_w
=
BOOST_GET_CONST
(
int
,
desc
.
GetAttr
(
"out_w"
));
return
false
;
if
(
!
(
scale
>
0.
f
&&
(
out_h
<=
0
&&
out_w
<=
0
)))
{
if
(
out_h
<=
0
)
{
VLOG
(
3
)
<<
"out_h must be greater than 0 if scale is not set."
;
return
false
;
}
if
(
out_w
<=
0
)
{
VLOG
(
3
)
<<
"out_w must be greater than 0 if scale is not set."
;
return
false
;
}
}
}
if
(
(
scale
<=
0.
f
)
&&
with_dynamic_shape
)
{
if
(
out_w
<=
0
)
{
VLOG
(
3
)
<<
"
dynamic shape not support scale
not set."
;
VLOG
(
3
)
<<
"
out_w must be greater than 0 if scale is
not set."
;
return
false
;
return
false
;
}
}
}
}
if
((
scale
<=
0.
f
)
&&
with_dynamic_shape
)
{
VLOG
(
3
)
<<
"dynamic shape not support scale not set."
;
return
false
;
}
// When align_corners = true, the paddle's and trt_layer's results has
// diff
if
(
align_corners
&&
scale
!=
1
)
{
return
false
;
}
}
}
if
(
op_type
==
"nearest_interp_v2"
)
{
if
(
op_type
==
"nearest_interp_v2"
)
{
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_nearest_interp.py
浏览文件 @
bc150edc
...
@@ -124,6 +124,8 @@ class TrtConvertNearestInterpTest(TrtLayerAutoScanTest):
...
@@ -124,6 +124,8 @@ class TrtConvertNearestInterpTest(TrtLayerAutoScanTest):
if
program_config
.
ops
[
0
].
attrs
[
if
program_config
.
ops
[
0
].
attrs
[
'scale'
]
<=
0
and
self
.
dynamic_shape
.
min_input_shape
:
'scale'
]
<=
0
and
self
.
dynamic_shape
.
min_input_shape
:
return
True
return
True
if
program_config
.
ops
[
0
].
attrs
[
'align_corners'
]
==
True
:
return
True
return
False
return
False
self
.
add_skip_case
(
self
.
add_skip_case
(
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_nearest_interp_op.py
浏览文件 @
bc150edc
...
@@ -61,9 +61,9 @@ class TRTNearestInterpTest(InferencePassTest):
...
@@ -61,9 +61,9 @@ class TRTNearestInterpTest(InferencePassTest):
def
set_params
(
self
):
def
set_params
(
self
):
self
.
bs
=
4
self
.
bs
=
4
self
.
scale
=
1
self
.
scale
=
0
self
.
channels
=
3
self
.
channels
=
3
self
.
origin_shape
=
(
32
,
32
)
# HW
self
.
origin_shape
=
(
4
,
4
)
# HW
self
.
resize_shape
=
(
64
,
64
)
# HW
self
.
resize_shape
=
(
64
,
64
)
# HW
self
.
align_corners
=
True
self
.
align_corners
=
True
self
.
data_layout
=
'NCHW'
self
.
data_layout
=
'NCHW'
...
@@ -114,7 +114,7 @@ class TRTNearestInterpTest2(TRTNearestInterpTest):
...
@@ -114,7 +114,7 @@ class TRTNearestInterpTest2(TRTNearestInterpTest):
class
TRTNearestInterpTest3
(
TRTNearestInterpTest
):
class
TRTNearestInterpTest3
(
TRTNearestInterpTest
):
def
set_params
(
self
):
def
set_params
(
self
):
self
.
bs
=
4
self
.
bs
=
4
self
.
scale
=
-
1
self
.
scale
=
0
self
.
channels
=
3
self
.
channels
=
3
self
.
origin_shape
=
(
32
,
32
)
# HW
self
.
origin_shape
=
(
32
,
32
)
# HW
self
.
resize_shape
=
(
64
,
64
)
# HW
self
.
resize_shape
=
(
64
,
64
)
# HW
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录