From 6862da6abef3581a49d421c0b8f8622e2d454e29 Mon Sep 17 00:00:00 2001 From: Kaipeng Deng Date: Wed, 16 Oct 2019 17:24:14 +0800 Subject: [PATCH] Cherry pick remove actual shape (#3620) * remove actual_shape * change version to 1.5 in yolov3 --- .../ppdet/modeling/anchor_heads/yolo_head.py | 12 +----------- .../PaddleDetection/ppdet/modeling/backbones/fpn.py | 7 +------ PaddleCV/yolov3/README.md | 2 +- PaddleCV/yolov3/README_en.md | 2 +- PaddleCV/yolov3/infer.py | 3 ++- PaddleCV/yolov3/models/yolov3.py | 11 +---------- 6 files changed, 7 insertions(+), 30 deletions(-) diff --git a/PaddleCV/PaddleDetection/ppdet/modeling/anchor_heads/yolo_head.py b/PaddleCV/PaddleDetection/ppdet/modeling/anchor_heads/yolo_head.py index 19829233..7e756f26 100644 --- a/PaddleCV/PaddleDetection/ppdet/modeling/anchor_heads/yolo_head.py +++ b/PaddleCV/PaddleDetection/ppdet/modeling/anchor_heads/yolo_head.py @@ -148,18 +148,8 @@ class YOLOv3Head(object): return route, tip def _upsample(self, input, scale=2, name=None): - # get dynamic upsample output shape - shape_nchw = fluid.layers.shape(input) - shape_hw = fluid.layers.slice( - shape_nchw, axes=[0], starts=[2], ends=[4]) - shape_hw.stop_gradient = True - in_shape = fluid.layers.cast(shape_hw, dtype='int32') - out_shape = in_shape * scale - out_shape.stop_gradient = True - - # reisze by actual_shape out = fluid.layers.resize_nearest( - input=input, scale=scale, actual_shape=out_shape, name=name) + input=input, scale=float(scale), name=name) return out def _parse_anchors(self, anchors): diff --git a/PaddleCV/PaddleDetection/ppdet/modeling/backbones/fpn.py b/PaddleCV/PaddleDetection/ppdet/modeling/backbones/fpn.py index 823f7c28..840c8536 100644 --- a/PaddleCV/PaddleDetection/ppdet/modeling/backbones/fpn.py +++ b/PaddleCV/PaddleDetection/ppdet/modeling/backbones/fpn.py @@ -87,13 +87,8 @@ class FPN(object): learning_rate=2., regularizer=L2Decay(0.)), name=lateral_name) - shape = fluid.layers.shape(upper_output) - shape_hw = fluid.layers.slice(shape, axes=[0], starts=[2], ends=[4]) - out_shape_ = shape_hw * 2 - out_shape = fluid.layers.cast(out_shape_, dtype='int32') - out_shape.stop_gradient = True topdown = fluid.layers.resize_nearest( - upper_output, scale=2., actual_shape=out_shape, name=topdown_name) + upper_output, scale=2., name=topdown_name) return lateral + topdown diff --git a/PaddleCV/yolov3/README.md b/PaddleCV/yolov3/README.md index d6ddf71c..7f71ca92 100644 --- a/PaddleCV/yolov3/README.md +++ b/PaddleCV/yolov3/README.md @@ -42,7 +42,7 @@ **安装[PaddlePaddle](https://github.com/PaddlePaddle/Paddle):** -在当前目录下运行样例代码需要PadddlePaddle Fluid的v.1.4或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据[安装文档](http://paddlepaddle.org/documentation/docs/zh/1.4/beginners_guide/install/index_cn.html)中的说明来更新PaddlePaddle。 +在当前目录下运行样例代码需要PadddlePaddle Fluid的v.1.5或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据[安装文档](http://paddlepaddle.org/documentation/docs/zh/1.5/beginners_guide/install/index_cn.html)中的说明来更新PaddlePaddle。 ### 数据准备 diff --git a/PaddleCV/yolov3/README_en.md b/PaddleCV/yolov3/README_en.md index eed38195..c468cd8e 100644 --- a/PaddleCV/yolov3/README_en.md +++ b/PaddleCV/yolov3/README_en.md @@ -28,7 +28,7 @@ We also recommend users to take a look at the  [IPython Notebook demo](https:/ **Install [PaddlePaddle](https://github.com/PaddlePaddle/Paddle):** -Running sample code in this directory requires PaddelPaddle Fluid v.1.4 and later. If the PaddlePaddle on your device is lower than this version, please follow the instructions in [installation document](http://www.paddlepaddle.org/documentation/docs/en/1.4/beginners_guide/install/index_en.html) and make an update. +Running sample code in this directory requires PaddelPaddle Fluid v.1.5 and later. If the PaddlePaddle on your device is lower than this version, please follow the instructions in [installation document](http://www.paddlepaddle.org/documentation/docs/en/1.5/beginners_guide/install/index_en.html) and make an update. **Install the [COCO-API](https://github.com/cocodataset/cocoapi):** diff --git a/PaddleCV/yolov3/infer.py b/PaddleCV/yolov3/infer.py index fa8bb26c..e98e7502 100644 --- a/PaddleCV/yolov3/infer.py +++ b/PaddleCV/yolov3/infer.py @@ -70,7 +70,8 @@ def infer(): im_shape = data[0][2] outputs = exe.run(fetch_list=[v.name for v in fetch_list], feed=feeder.feed(data), - return_numpy=False) + return_numpy=False, + use_program_cache=True) bboxes = np.array(outputs[0]) if bboxes.shape[1] != 6: print("No object found in {}".format(image_name)) diff --git a/PaddleCV/yolov3/models/yolov3.py b/PaddleCV/yolov3/models/yolov3.py index c8460625..0feb2b0e 100644 --- a/PaddleCV/yolov3/models/yolov3.py +++ b/PaddleCV/yolov3/models/yolov3.py @@ -68,17 +68,8 @@ def yolo_detection_block(input, channel, is_test=True, name=None): def upsample(input, scale=2, name=None): - # get dynamic upsample output shape - shape_nchw = fluid.layers.shape(input) - shape_hw = fluid.layers.slice(shape_nchw, axes=[0], starts=[2], ends=[4]) - shape_hw.stop_gradient = True - in_shape = fluid.layers.cast(shape_hw, dtype='int32') - out_shape = in_shape * scale - out_shape.stop_gradient = True - - # reisze by actual_shape out = fluid.layers.resize_nearest( - input=input, scale=scale, actual_shape=out_shape, name=name) + input=input, scale=float(scale), name=name) return out -- GitLab