Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c061c082
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
c061c082
编写于
11月 02, 2022
作者:
Z
Zhang Jun
提交者:
GitHub
11月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[inference][trt] bilinear support OutSize input (#47495)
* add bilinear OutSize
上级
05a4be36
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
34 addition
and
9 deletion
+34
-9
paddle/fluid/inference/tensorrt/convert/bilinear_interp_v2_op.cc
...fluid/inference/tensorrt/convert/bilinear_interp_v2_op.cc
+30
-5
paddle/fluid/inference/tensorrt/op_teller.cc
paddle/fluid/inference/tensorrt/op_teller.cc
+2
-2
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_bilinear_interp_v2.py
...tests/ir/inference/test_trt_convert_bilinear_interp_v2.py
+2
-2
未找到文件。
paddle/fluid/inference/tensorrt/convert/bilinear_interp_v2_op.cc
浏览文件 @
c061c082
...
@@ -52,6 +52,7 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
...
@@ -52,6 +52,7 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
auto
resize_inputs
=
op_desc
.
Inputs
();
auto
resize_inputs
=
op_desc
.
Inputs
();
auto
input_names
=
op_desc
.
Input
(
"X"
);
auto
input_names
=
op_desc
.
Input
(
"X"
);
auto
out_h
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"out_h"
));
auto
out_h
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"out_h"
));
auto
out_w
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"out_w"
));
auto
out_w
=
PADDLE_GET_CONST
(
int
,
op_desc
.
GetAttr
(
"out_w"
));
...
@@ -94,6 +95,15 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
...
@@ -94,6 +95,15 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
out_w
=
static_cast
<
int
>
(
in_dim
.
d
[
w_axis
]
*
scale_w
);
out_w
=
static_cast
<
int
>
(
in_dim
.
d
[
w_axis
]
*
scale_w
);
}
}
// Priority: Input(OutSize) > attr(out_h/out_w) > attr(scale)
nvinfer1
::
ITensor
*
outsize_tensor
=
nullptr
;
if
(
engine_
->
with_dynamic_shape
()
&&
resize_inputs
.
find
(
"OutSize"
)
!=
resize_inputs
.
end
())
{
if
(
op_desc
.
Input
(
"OutSize"
).
size
()
>=
1
)
{
outsize_tensor
=
engine_
->
GetITensor
(
op_desc
.
Input
(
"OutSize"
)[
0
]);
}
}
if
(
out_h
>
0
&&
out_w
>
0
)
{
if
(
out_h
>
0
&&
out_w
>
0
)
{
scale_h
=
scale_h
=
static_cast
<
float
>
(
out_h
)
/
static_cast
<
float
>
(
in_dim
.
d
[
h_axis
]);
static_cast
<
float
>
(
out_h
)
/
static_cast
<
float
>
(
in_dim
.
d
[
h_axis
]);
...
@@ -102,11 +112,9 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
...
@@ -102,11 +112,9 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
}
}
std
::
vector
<
float
>
scales
;
std
::
vector
<
float
>
scales
;
if
(
engine_
->
with_dynamic_shape
())
{
if
(
engine_
->
with_dynamic_shape
())
{
scales
.
push_back
(
1.
f
);
scales
.
push_back
(
1.
f
);
}
}
if
(
data_layout
==
phi
::
DataLayout
::
kNCHW
)
{
if
(
data_layout
==
phi
::
DataLayout
::
kNCHW
)
{
scales
.
push_back
(
1.
f
);
scales
.
push_back
(
1.
f
);
scales
.
push_back
(
scale_h
);
scales
.
push_back
(
scale_h
);
...
@@ -115,12 +123,29 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
...
@@ -115,12 +123,29 @@ class BilinearInterpolateV2OpConverter : public OpConverter {
scales
.
push_back
(
scale_h
);
scales
.
push_back
(
scale_h
);
scales
.
push_back
(
scale_w
);
scales
.
push_back
(
scale_w
);
scales
.
push_back
(
1.
f
);
scales
.
push_back
(
1.
f
);
}
else
{
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"Data layout must be NCHW or NHWC."
));
}
}
if
(
engine_
->
with_dynamic_shape
())
{
if
(
outsize_tensor
!=
nullptr
)
{
std
::
vector
<
nvinfer1
::
ITensor
*>
outsize_itensors
;
auto
*
input_shape
=
Shape
(
input
);
outsize_itensors
.
push_back
(
GetEleTensorOfShape
(
input_shape
,
0
));
if
(
data_layout
==
phi
::
DataLayout
::
kNCHW
)
{
outsize_itensors
.
push_back
(
GetEleTensorOfShape
(
input_shape
,
1
));
outsize_itensors
.
push_back
(
outsize_tensor
);
}
else
if
(
data_layout
==
phi
::
DataLayout
::
kNHWC
)
{
outsize_itensors
.
push_back
(
outsize_tensor
);
outsize_itensors
.
push_back
(
GetEleTensorOfShape
(
input_shape
,
3
));
}
layer
->
setInput
(
1
,
*
Concat
(
outsize_itensors
));
}
else
{
layer
->
setScales
(
scales
.
data
(),
scales
.
size
());
layer
->
setScales
(
scales
.
data
(),
scales
.
size
());
}
}
else
{
layer
->
setScales
(
scales
.
data
(),
scales
.
size
());
}
RreplenishLayerAndOutput
(
RreplenishLayerAndOutput
(
layer
,
"bilinear_interp_v2"
,
{
output_name
},
test_mode
);
layer
,
"bilinear_interp_v2"
,
{
output_name
},
test_mode
);
}
}
...
...
paddle/fluid/inference/tensorrt/op_teller.cc
浏览文件 @
c061c082
...
@@ -803,8 +803,8 @@ struct SimpleOpTypeSetTeller : public Teller {
...
@@ -803,8 +803,8 @@ struct SimpleOpTypeSetTeller : public Teller {
}
}
if
(
resize_inputs
.
find
(
"OutSize"
)
!=
resize_inputs
.
end
())
{
if
(
resize_inputs
.
find
(
"OutSize"
)
!=
resize_inputs
.
end
())
{
if
(
desc
.
Input
(
"OutSize"
).
size
()
>=
1
)
{
if
(
!
with_dynamic_shape
)
{
VLOG
(
3
)
<<
"
The Paddle-TRT does
n't support the OutSize for op_type "
VLOG
(
3
)
<<
"
Static shape do
n't support the OutSize for op_type "
<<
op_type
;
<<
op_type
;
return
false
;
return
false
;
}
}
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_convert_bilinear_interp_v2.py
浏览文件 @
c061c082
...
@@ -41,8 +41,8 @@ class TrtConvertBilinearInterpV2Test(TrtLayerAutoScanTest):
...
@@ -41,8 +41,8 @@ class TrtConvertBilinearInterpV2Test(TrtLayerAutoScanTest):
)
)
for
data_layout
in
[
"NCHW"
,
"NHWC"
]:
for
data_layout
in
[
"NCHW"
,
"NHWC"
]:
for
scale_y
in
[
2.0
,
-
1.0
,
0
.0
]:
for
scale_y
in
[
2.0
,
1
.0
]:
for
scale_x
in
[
2.0
,
-
1.0
,
0
.0
]:
for
scale_x
in
[
2.0
,
1
.0
]:
scale
=
[
scale_y
,
scale_x
]
scale
=
[
scale_y
,
scale_x
]
for
out_h
in
[
32
,
64
,
128
,
192
]:
for
out_h
in
[
32
,
64
,
128
,
192
]:
for
out_w
in
[
32
,
64
]:
for
out_w
in
[
32
,
64
]:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录