Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
8084b759
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看板
未验证
提交
8084b759
编写于
3月 30, 2021
作者:
S
Shang Zhizhou
提交者:
GitHub
3月 30, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix batchnorm when inpu dims < 3 (#31933)
* fix batchnorm when inpu dims < 3 * add unittest for batchnorm dims = 2
上级
64ee255f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
5 deletion
+65
-5
paddle/fluid/inference/tensorrt/convert/batch_norm_op.cc
paddle/fluid/inference/tensorrt/convert/batch_norm_op.cc
+37
-5
python/paddle/fluid/tests/unittests/ir/inference/test_trt_scale_op.py
...e/fluid/tests/unittests/ir/inference/test_trt_scale_op.py
+28
-0
未找到文件。
paddle/fluid/inference/tensorrt/convert/batch_norm_op.cc
浏览文件 @
8084b759
...
@@ -158,17 +158,49 @@ class BatchNormOpConverter : public OpConverter {
...
@@ -158,17 +158,49 @@ class BatchNormOpConverter : public OpConverter {
TensorRTEngine
::
Weight
power_weights
{
nvinfer1
::
DataType
::
kFLOAT
,
nullptr
,
TensorRTEngine
::
Weight
power_weights
{
nvinfer1
::
DataType
::
kFLOAT
,
nullptr
,
0
};
0
};
nvinfer1
::
IScaleLayer
*
layer
=
int
dynamic_shape_offset
=
engine_
->
with_dynamic_shape
()
?
1
:
0
;
TRT_ENGINE_ADD_LAYER
(
engine_
,
Scale
,
*
const_cast
<
nvinfer1
::
ITensor
*>
(
X
),
nvinfer1
::
ILayer
*
layer
=
nullptr
;
nvinfer1
::
ScaleMode
::
kCHANNEL
,
shift_weights
.
get
(),
nvinfer1
::
IShuffleLayer
*
expand_layer
=
nullptr
;
scale_weights
.
get
(),
power_weights
.
get
());
nvinfer1
::
IShuffleLayer
*
squeeze_layer
=
nullptr
;
auto
x_dim
=
X
->
getDimensions
();
if
(
x_dim
.
nbDims
<
3
+
dynamic_shape_offset
)
{
nvinfer1
::
Dims
expand_shape
;
expand_shape
.
nbDims
=
3
+
dynamic_shape_offset
;
for
(
int
i
=
0
;
i
<
3
+
dynamic_shape_offset
;
i
++
)
{
if
(
i
<
x_dim
.
nbDims
)
{
expand_shape
.
d
[
i
]
=
x_dim
.
d
[
i
]
<
0
?
0
:
x_dim
.
d
[
i
];
}
else
{
expand_shape
.
d
[
i
]
=
1
;
}
}
expand_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
X
);
expand_layer
->
setReshapeDimensions
(
expand_shape
);
X
=
expand_layer
->
getOutput
(
0
);
}
layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Scale
,
*
X
,
nvinfer1
::
ScaleMode
::
kCHANNEL
,
shift_weights
.
get
(),
scale_weights
.
get
(),
power_weights
.
get
());
auto
output_name
=
op_desc
.
Output
(
"Y"
).
front
();
auto
output_name
=
op_desc
.
Output
(
"Y"
).
front
();
engine_
->
SetWeights
(
op_desc
.
Input
(
"Bias"
).
front
(),
engine_
->
SetWeights
(
op_desc
.
Input
(
"Bias"
).
front
(),
std
::
move
(
combile_bias_tensor
));
std
::
move
(
combile_bias_tensor
));
engine_
->
SetWeights
(
op_desc
.
Input
(
"Scale"
).
front
(),
engine_
->
SetWeights
(
op_desc
.
Input
(
"Scale"
).
front
(),
std
::
move
(
combile_scale_tensor
));
std
::
move
(
combile_scale_tensor
));
RreplenishLayerAndOutput
(
layer
,
"pool2d"
,
{
output_name
},
test_mode
);
if
(
x_dim
.
nbDims
<
3
+
dynamic_shape_offset
)
{
nvinfer1
::
Dims
squeeze_shape
;
squeeze_shape
.
nbDims
=
x_dim
.
nbDims
;
for
(
int
i
=
0
;
i
<
squeeze_shape
.
nbDims
;
i
++
)
{
squeeze_shape
.
d
[
i
]
=
x_dim
.
d
[
i
]
<
0
?
0
:
x_dim
.
d
[
i
];
}
squeeze_layer
=
TRT_ENGINE_ADD_LAYER
(
engine_
,
Shuffle
,
*
(
layer
->
getOutput
(
0
)));
squeeze_layer
->
setReshapeDimensions
(
squeeze_shape
);
layer
=
static_cast
<
nvinfer1
::
ILayer
*>
(
squeeze_layer
);
}
RreplenishLayerAndOutput
(
layer
,
"batchnorm_add_scale"
,
{
output_name
},
test_mode
);
}
}
};
};
...
...
python/paddle/fluid/tests/unittests/ir/inference/test_trt_scale_op.py
浏览文件 @
8084b759
...
@@ -48,5 +48,33 @@ class TRTScaleTest(InferencePassTest):
...
@@ -48,5 +48,33 @@ class TRTScaleTest(InferencePassTest):
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
))
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
))
class
TRTScaleShape2Test
(
InferencePassTest
):
def
setUp
(
self
):
with
fluid
.
program_guard
(
self
.
main_program
,
self
.
startup_program
):
data
=
fluid
.
data
(
name
=
"data"
,
shape
=
[
-
1
,
512
,
512
],
dtype
=
"float32"
)
scale_out
=
self
.
append_scale
(
data
)
out
=
fluid
.
layers
.
batch_norm
(
scale_out
,
is_test
=
True
)
self
.
feeds
=
{
"data"
:
np
.
random
.
random
([
1
,
512
,
512
]).
astype
(
"float32"
),
}
self
.
enable_trt
=
True
self
.
trt_parameters
=
TRTScaleShape2Test
.
TensorRTParam
(
1
<<
30
,
32
,
1
,
AnalysisConfig
.
Precision
.
Float32
,
False
,
False
)
self
.
fetch_list
=
[
out
]
def
append_scale
(
self
,
data
):
return
fluid
.
layers
.
scale
(
x
=
data
,
scale
=
2.0
,
bias
=-
1.0
,
bias_after_scale
=
False
)
def
test_check_output
(
self
):
if
core
.
is_compiled_with_cuda
():
use_gpu
=
True
self
.
check_output_with_option
(
use_gpu
,
flatten
=
True
)
self
.
assertTrue
(
PassVersionChecker
.
IsCompatible
(
'tensorrt_subgraph_pass'
))
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录