未验证 提交 0914ff97 编写于 作者: W Wilber 提交者: GitHub

fix reshape trt condition (#34007)

上级 cb73feea
......@@ -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
```
......
......@@ -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<int> shape =
BOOST_GET_CONST(std::vector<int>, desc.GetAttr("shape"));
if (shape.size() >= nvinfer1::Dims::MAX_DIMS) return false;
}
std::vector<int> shape =
BOOST_GET_CONST(std::vector<int>, 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") {
......
......@@ -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)
......
......@@ -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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册