Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
7e8e3bab
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
7e8e3bab
编写于
11月 25, 2020
作者:
W
Wilber
提交者:
GitHub
11月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Cherry-pick Release/1.8] Fix bug of trt plugin pooling. (#29033)
上级
21d98351
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
25 addition
and
9 deletion
+25
-9
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
+25
-9
未找到文件。
paddle/fluid/inference/tensorrt/convert/pool2d_op.cc
浏览文件 @
7e8e3bab
...
@@ -79,18 +79,25 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -79,18 +79,25 @@ class Pool2dOpConverter : public OpConverter {
std
::
vector
<
int
>
paddings
=
std
::
vector
<
int
>
paddings
=
boost
::
get
<
std
::
vector
<
int
>>
(
op_desc
.
GetAttr
(
"paddings"
));
boost
::
get
<
std
::
vector
<
int
>>
(
op_desc
.
GetAttr
(
"paddings"
));
bool
ceil_mode
=
boost
::
get
<
bool
>
(
op_desc
.
GetAttr
(
"ceil_mode"
));
bool
ceil_mode
=
boost
::
get
<
bool
>
(
op_desc
.
GetAttr
(
"ceil_mode"
));
bool
exclusive
=
op_desc
.
HasAttr
(
"exclusive"
)
?
boost
::
get
<
bool
>
(
op_desc
.
GetAttr
(
"exclusive"
))
:
true
;
bool
adaptive
=
false
;
bool
adaptive
=
false
;
if
(
op_desc
.
HasAttr
(
"adaptive"
))
if
(
op_desc
.
HasAttr
(
"adaptive"
))
adaptive
=
boost
::
get
<
bool
>
(
op_desc
.
GetAttr
(
"adaptive"
));
adaptive
=
boost
::
get
<
bool
>
(
op_desc
.
GetAttr
(
"adaptive"
));
nvinfer1
::
PoolingType
nv_pool_type
=
nvinfer1
::
PoolingType
::
kMAX
;
nvinfer1
::
PoolingType
nv_pool_type
=
nvinfer1
::
PoolingType
::
kMAX
;
nvinfer1
::
ReduceOperation
reduce_operation
=
nvinfer1
::
ReduceOperation
::
kMAX
;
plugin
::
PoolPlugin
::
PoolType
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
::
max
;
plugin
::
PoolPlugin
::
PoolType
::
max
;
if
(
pool_type
==
"max"
)
{
if
(
pool_type
==
"max"
)
{
nv_pool_type
=
nvinfer1
::
PoolingType
::
kMAX
;
nv_pool_type
=
nvinfer1
::
PoolingType
::
kMAX
;
reduce_operation
=
nvinfer1
::
ReduceOperation
::
kMAX
;
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
::
max
;
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
::
max
;
}
else
if
(
pool_type
==
"avg"
)
{
}
else
if
(
pool_type
==
"avg"
)
{
nv_pool_type
=
nvinfer1
::
PoolingType
::
kAVERAGE
;
nv_pool_type
=
nvinfer1
::
PoolingType
::
kAVERAGE
;
reduce_operation
=
nvinfer1
::
ReduceOperation
::
kAVG
;
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
::
avg
;
plugin_pool_type
=
plugin
::
PoolPlugin
::
PoolType
::
avg
;
}
else
{
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
...
@@ -113,12 +120,17 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -113,12 +120,17 @@ class Pool2dOpConverter : public OpConverter {
}
}
if
(
engine_
->
with_dynamic_shape
())
{
if
(
engine_
->
with_dynamic_shape
())
{
if
(
!
adaptive
&&
pool_type
==
"max"
&&
!
global_pooling
&&
!
ceil_mode
)
{
if
(
!
adaptive
&&
!
global_pooling
&&
!
ceil_mode
)
{
auto
*
pool_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Pooling
,
*
input1
,
auto
*
pool_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Pooling
,
*
input1
,
nv_pool_type
,
nv_ksize
);
nv_pool_type
,
nv_ksize
);
pool_layer
->
setStride
(
nv_strides
);
pool_layer
->
setStride
(
nv_strides
);
pool_layer
->
setPadding
(
nv_paddings
);
pool_layer
->
setPadding
(
nv_paddings
);
pool_layer
->
setAverageCountExcludesPadding
(
exclusive
);
layer
=
pool_layer
;
layer
=
pool_layer
;
}
else
if
(
global_pooling
)
{
auto
*
reduce_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Reduce
,
*
input1
,
reduce_operation
,
12
,
true
);
layer
=
reduce_layer
;
}
else
{
}
else
{
#if IS_TRT_VERSION_GE(6000)
#if IS_TRT_VERSION_GE(6000)
plugin
::
PoolPluginDynamic
*
plugin
=
plugin
::
PoolPluginDynamic
*
plugin
=
...
@@ -140,23 +152,27 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -140,23 +152,27 @@ class Pool2dOpConverter : public OpConverter {
if
(
global_pooling
==
true
)
{
if
(
global_pooling
==
true
)
{
nv_ksize
.
d
[
0
]
=
input_shape
.
d
[
input_dims
-
2
];
nv_ksize
.
d
[
0
]
=
input_shape
.
d
[
input_dims
-
2
];
nv_ksize
.
d
[
1
]
=
input_shape
.
d
[
input_dims
-
1
];
nv_ksize
.
d
[
1
]
=
input_shape
.
d
[
input_dims
-
1
];
auto
*
layer
=
TRT_ENGINE_ADD_LAYER
(
auto
*
pool_
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Pooling
,
*
const_cast
<
nvinfer1
::
ITensor
*>
(
input1
),
engine_
,
Pooling
,
*
const_cast
<
nvinfer1
::
ITensor
*>
(
input1
),
nv_pool_type
,
nv_ksize
);
nv_pool_type
,
nv_ksize
);
PADDLE_ENFORCE_NOT_NULL
(
PADDLE_ENFORCE_NOT_NULL
(
layer
,
platform
::
errors
::
Fatal
(
pool_
layer
,
platform
::
errors
::
Fatal
(
"trt pool layer in converter could not be created."
));
"trt pool layer in converter could not be created."
));
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
layer
->
setName
((
"pool2d (Output: "
+
output_name
+
")"
).
c_str
());
pool_layer
->
setStride
(
nv_strides
);
layer
->
getOutput
(
0
)
->
setName
(
output_name
.
c_str
());
pool_layer
->
setPadding
(
nv_paddings
);
engine_
->
SetITensor
(
output_name
,
layer
->
getOutput
(
0
));
pool_layer
->
setAverageCountExcludesPadding
(
exclusive
);
pool_layer
->
setName
((
"pool2d (Output: "
+
output_name
+
")"
).
c_str
());
pool_layer
->
getOutput
(
0
)
->
setName
(
output_name
.
c_str
());
engine_
->
SetITensor
(
output_name
,
pool_layer
->
getOutput
(
0
));
layer
=
pool_layer
;
if
(
test_mode
)
{
if
(
test_mode
)
{
engine_
->
DeclareOutput
(
output_name
);
engine_
->
DeclareOutput
(
output_name
);
}
}
return
;
return
;
}
}
if
(
!
adaptive
&&
pool_type
==
"max"
)
{
if
(
!
adaptive
)
{
// Under ceil mode, the pre_pad and post_pad are used to
// Under ceil mode, the pre_pad and post_pad are used to
// record the the padding size. In some ceil mode cases,
// record the the padding size. In some ceil mode cases,
// we do not need padding, so we initialize the two vars to 0.
// we do not need padding, so we initialize the two vars to 0.
...
@@ -184,6 +200,7 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -184,6 +200,7 @@ class Pool2dOpConverter : public OpConverter {
"trt pool layer in converter could not be created."
));
"trt pool layer in converter could not be created."
));
pool_layer
->
setStride
(
nv_strides
);
pool_layer
->
setStride
(
nv_strides
);
pool_layer
->
setPadding
(
nv_paddings
);
pool_layer
->
setPadding
(
nv_paddings
);
pool_layer
->
setAverageCountExcludesPadding
(
exclusive
);
layer
=
pool_layer
;
layer
=
pool_layer
;
}
else
{
}
else
{
// Average pooling needs to exclude the padding pixels from the average
// Average pooling needs to exclude the padding pixels from the average
...
@@ -203,7 +220,6 @@ class Pool2dOpConverter : public OpConverter {
...
@@ -203,7 +220,6 @@ class Pool2dOpConverter : public OpConverter {
"trt pool plugin layer in converter could not be created."
));
"trt pool plugin layer in converter could not be created."
));
layer
=
pool_layer
;
layer
=
pool_layer
;
}
}
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
auto
output_name
=
op_desc
.
Output
(
"Out"
)[
0
];
RreplenishLayerAndOutput
(
layer
,
"pool2d"
,
{
output_name
},
test_mode
);
RreplenishLayerAndOutput
(
layer
,
"pool2d"
,
{
output_name
},
test_mode
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录