diff --git a/paddle/fluid/inference/goapi/README.md b/paddle/fluid/inference/goapi/README.md index 272a5a6108eee4579889a504f361cbce3905fed3..6664014bf937b84583c47ed10d35331a34493de4 100644 --- a/paddle/fluid/inference/goapi/README.md +++ b/paddle/fluid/inference/goapi/README.md @@ -11,8 +11,8 @@ Paddle Inference golang API 基于 [capi](../capi_exp) 和 cgo 实现,需要 2. 使用`go get`获取golang paddle api ``` -# 此处使用上一步记录的CommitId,假设为76e5724 -COMMITID=76e5724 +# 此处使用上一步记录的CommitId,假设为0722297 +COMMITID=0722297 go get -d -v github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi@${COMMITID} ``` @@ -28,7 +28,7 @@ go1.15新增了`GOMODCACHE`环境变量,`go get`默认会将代码下载到`GO ```bash eval $(go env | grep GOMODCACHE) # 按需修改最后的goapi版本号 -cd ${GOMODCACHE}/github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi\@v0.0.0-20210517084506-76e5724c16a5/ +cd ${GOMODCACHE}/github.com/paddlepaddle/paddle/paddle/fluid/inference/goapi\@v0.0.0-20210623023452-0722297d9b8c/ ln -s ${PADDLE_C_DOWNLOAD_DIR}/paddle_inference_c_install_dir paddle_inference_c ``` diff --git a/paddle/fluid/inference/tensorrt/op_teller.cc b/paddle/fluid/inference/tensorrt/op_teller.cc index c21ef8840de1299adda62dda10ddb2b92f824bfa..cfbe3957ad444f116182fb396b64964da06213a8 100644 --- a/paddle/fluid/inference/tensorrt/op_teller.cc +++ b/paddle/fluid/inference/tensorrt/op_teller.cc @@ -692,15 +692,16 @@ bool OpTeller::Tell(const framework::ir::Node* node, bool use_no_calib_int8, if (op_type == "reshape" || op_type == "reshape2") { if (!desc.HasAttr("shape")) { return false; - // Paddle-TRT does not support the input tensors: Shape and ShapeTensor - } else if (desc.Input("Shape").size() >= 1 || - desc.Input("ShapeTensor").size() >= 1) { + } + // Paddle-TRT does not support the input tensors: Shape and ShapeTensor + if (desc.Input("Shape").size() >= 1 || + desc.Input("ShapeTensor").size() >= 1) { return false; - } else { - std::vector shape = - BOOST_GET_CONST(std::vector, desc.GetAttr("shape")); - if (shape.size() >= nvinfer1::Dims::MAX_DIMS) return false; } + std::vector shape = + BOOST_GET_CONST(std::vector, desc.GetAttr("shape")); + if (shape.size() >= nvinfer1::Dims::MAX_DIMS) return false; + if (!with_dynamic_shape && shape[0] == -1) return false; } if (op_type == "reduce_sum") { diff --git a/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py b/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py index e3c21eaa78d716863c01996e2e5371c2f90f0643..fab287b5eeba440dcb4c4750eb69af640208fac2 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/inference_pass_test.py @@ -72,9 +72,7 @@ class InferencePassTest(unittest.TestCase): feeded_var_names=list(self.feeds.keys()), target_vars=self.fetch_list, executor=executor, - main_program=program, - model_filename="model", - params_filename="params") + main_program=program) return outs @@ -111,8 +109,7 @@ class InferencePassTest(unittest.TestCase): ''' Return a new object of AnalysisConfig. ''' - config = AnalysisConfig( - os.path.join(self.path, "model"), os.path.join(self.path, "params")) + config = AnalysisConfig(self.path) config.disable_gpu() config.switch_specify_input_names(True) config.switch_ir_optim(True) diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_yolo_box_op.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_yolo_box_op.py index cff8091cd93f8ecfb48e066e11eeda00c1e83a8b..2166bbaa98b2fe48aa24a34bd7f41e4a986d194c 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_yolo_box_op.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_yolo_box_op.py @@ -32,8 +32,6 @@ class TRTYoloBoxTest(InferencePassTest): image_size = fluid.data( name='image_size', shape=[self.bs, 2], dtype='int32') boxes, scores = self.append_yolobox(image, image_size) - scores = fluid.layers.reshape(scores, (self.bs, -1)) - out = fluid.layers.batch_norm(scores, is_test=True) self.feeds = { 'image': np.random.random(image_shape).astype('float32'), @@ -43,7 +41,7 @@ class TRTYoloBoxTest(InferencePassTest): self.enable_trt = True self.trt_parameters = TRTYoloBoxTest.TensorRTParam( 1 << 30, self.bs, 1, AnalysisConfig.Precision.Float32, False, False) - self.fetch_list = [out, boxes] + self.fetch_list = [scores, boxes] def set_params(self): self.bs = 4 @@ -72,5 +70,51 @@ class TRTYoloBoxTest(InferencePassTest): PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) +class TRTYoloBoxFP16Test(InferencePassTest): + def setUp(self): + self.set_params() + with fluid.program_guard(self.main_program, self.startup_program): + image_shape = [self.bs, self.channel, self.height, self.width] + image = fluid.data(name='image', shape=image_shape, dtype='float32') + image_size = fluid.data( + name='image_size', shape=[self.bs, 2], dtype='int32') + boxes, scores = self.append_yolobox(image, image_size) + + self.feeds = { + 'image': np.random.random(image_shape).astype('float32'), + 'image_size': np.array([[416, 416]]).astype('int32'), + } + self.enable_trt = True + self.trt_parameters = TRTYoloBoxFP16Test.TensorRTParam( + 1 << 30, self.bs, 1, AnalysisConfig.Precision.Half, False, False) + self.fetch_list = [scores, boxes] + + def set_params(self): + self.bs = 1 + self.height = 13 + self.width = 13 + self.class_num = 1 + self.anchors = [106, 148, 92, 300, 197, 334] + self.channel = 18 + self.conf_thresh = .05 + self.downsample_ratio = 32 + + def append_yolobox(self, image, image_size): + return fluid.layers.yolo_box( + x=image, + img_size=image_size, + class_num=self.class_num, + anchors=self.anchors, + conf_thresh=self.conf_thresh, + downsample_ratio=self.downsample_ratio) + + def test_check_output(self): + if core.is_compiled_with_cuda(): + use_gpu = True + self.check_output_with_option(use_gpu, flatten=True, rtol=1e-1) + self.assertTrue( + PassVersionChecker.IsCompatible('tensorrt_subgraph_pass')) + + if __name__ == "__main__": unittest.main()