Skip to content

Commit 0914ff9

Browse files
authored
fix reshape trt condition (#34007)
1 parent cb73fee commit 0914ff9

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
lines changed

paddle/fluid/inference/goapi/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Paddle Inference golang API 基于 [capi](../capi_exp) 和 cgo 实现,需要
1111
2. 使用`go get`获取golang paddle api
1212

1313
```
14-
# 此处使用上一步记录的CommitId,假设为76e5724
15-
COMMITID=76e5724
14+
# 此处使用上一步记录的CommitId,假设为0722297
15+
COMMITID=0722297
1616
go get -d -v github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi@${COMMITID}
1717
```
1818

@@ -28,7 +28,7 @@ go1.15新增了`GOMODCACHE`环境变量,`go get`默认会将代码下载到`GO
2828
```bash
2929
eval $(go env | grep GOMODCACHE)
3030
# 按需修改最后的goapi版本号
31-
cd ${GOMODCACHE}/github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi\@v0.0.0-20210517084506-76e5724c16a5/
31+
cd ${GOMODCACHE}/github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi\@v0.0.0-20210623023452-0722297d9b8c/
3232
ln -s ${PADDLE_C_DOWNLOAD_DIR}/paddle_inference_c_install_dir paddle_inference_c
3333
```
3434

paddle/fluid/inference/tensorrt/op_teller.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -692,15 +692,16 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8,
692692
if (op_type == "reshape" || op_type == "reshape2") {
693693
if (!desc.HasAttr("shape")) {
694694
return false;
695-
// Paddle-TRT does not support the input tensors: Shape and ShapeTensor
696-
} else if (desc.Input("Shape").size() >= 1 ||
697-
desc.Input("ShapeTensor").size() >= 1) {
695+
}
696+
// Paddle-TRT does not support the input tensors: Shape and ShapeTensor
697+
if (desc.Input("Shape").size() >= 1 ||
698+
desc.Input("ShapeTensor").size() >= 1) {
698699
return false;
699-
} else {
700-
std::vector<int> shape =
701-
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("shape"));
702-
if (shape.size() >= nvinfer1::Dims::MAX_DIMS) return false;
703700
}
701+
std::vector<int> shape =
702+
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("shape"));
703+
if (shape.size() >= nvinfer1::Dims::MAX_DIMS) return false;
704+
if (!with_dynamic_shape && shape[0] == -1) return false;
704705
}
705706

706707
if (op_type == "reduce_sum") {

python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ def _save_models(self, executor, program, scope):
7272
feeded_var_names=list(self.feeds.keys()),
7373
target_vars=self.fetch_list,
7474
executor=executor,
75-
main_program=program,
76-
model_filename="model",
77-
params_filename="params")
75+
main_program=program)
7876

7977
return outs
8078

@@ -111,8 +109,7 @@ def _get_analysis_config(self,
111109
'''
112110
Return a new object of AnalysisConfig.
113111
'''
114-
config = AnalysisConfig(
115-
os.path.join(self.path, "model"), os.path.join(self.path, "params"))
112+
config = AnalysisConfig(self.path)
116113
config.disable_gpu()
117114
config.switch_specify_input_names(True)
118115
config.switch_ir_optim(True)

python/paddle/fluid/tests/unittests/ir/inference/test_trt_yolo_box_op.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ def setUp(self):
3232
image_size = fluid.data(
3333
name='image_size', shape=[self.bs, 2], dtype='int32')
3434
boxes, scores = self.append_yolobox(image, image_size)
35-
scores = fluid.layers.reshape(scores, (self.bs, -1))
36-
out = fluid.layers.batch_norm(scores, is_test=True)
3735

3836
self.feeds = {
3937
'image': np.random.random(image_shape).astype('float32'),
@@ -43,7 +41,7 @@ def setUp(self):
4341
self.enable_trt = True
4442
self.trt_parameters = TRTYoloBoxTest.TensorRTParam(
4543
1 << 30, self.bs, 1, AnalysisConfig.Precision.Float32, False, False)
46-
self.fetch_list = [out, boxes]
44+
self.fetch_list = [scores, boxes]
4745

4846
def set_params(self):
4947
self.bs = 4
@@ -72,5 +70,51 @@ def test_check_output(self):
7270
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
7371

7472

73+
class TRTYoloBoxFP16Test(InferencePassTest):
74+
def setUp(self):
75+
self.set_params()
76+
with fluid.program_guard(self.main_program, self.startup_program):
77+
image_shape = [self.bs, self.channel, self.height, self.width]
78+
image = fluid.data(name='image', shape=image_shape, dtype='float32')
79+
image_size = fluid.data(
80+
name='image_size', shape=[self.bs, 2], dtype='int32')
81+
boxes, scores = self.append_yolobox(image, image_size)
82+
83+
self.feeds = {
84+
'image': np.random.random(image_shape).astype('float32'),
85+
'image_size': np.array([[416, 416]]).astype('int32'),
86+
}
87+
self.enable_trt = True
88+
self.trt_parameters = TRTYoloBoxFP16Test.TensorRTParam(
89+
1 << 30, self.bs, 1, AnalysisConfig.Precision.Half, False, False)
90+
self.fetch_list = [scores, boxes]
91+
92+
def set_params(self):
93+
self.bs = 1
94+
self.height = 13
95+
self.width = 13
96+
self.class_num = 1
97+
self.anchors = [106, 148, 92, 300, 197, 334]
98+
self.channel = 18
99+
self.conf_thresh = .05
100+
self.downsample_ratio = 32
101+
102+
def append_yolobox(self, image, image_size):
103+
return fluid.layers.yolo_box(
104+
x=image,
105+
img_size=image_size,
106+
class_num=self.class_num,
107+
anchors=self.anchors,
108+
conf_thresh=self.conf_thresh,
109+
downsample_ratio=self.downsample_ratio)
110+
111+
def test_check_output(self):
112+
if core.is_compiled_with_cuda():
113+
use_gpu = True
114+
self.check_output_with_option(use_gpu, flatten=True, rtol=1e-1)
115+
self.assertTrue(
116+
PassVersionChecker.IsCompatible('tensorrt_subgraph_pass'))
117+
118+
75119
if __name__ == "__main__":
76120
unittest.main()

0 commit comments

Comments
 (0)