diff --git a/configs/anchor_free/README.md b/configs/anchor_free/README.md index 184ca2a6e938cc37d3a57e684480e7c0d035beac..81e9d0843904108bfbde0c8be722e8431c26dcf4 100644 --- a/configs/anchor_free/README.md +++ b/configs/anchor_free/README.md @@ -35,6 +35,7 @@ **注意:** - 模型FPS在Tesla V100单卡环境中通过tools/eval.py进行测试 +- CornerNet-Squeeze要求使用PaddlePaddle1.8及以上版本或适当的develop版本 - CornerNet-Squeeze中使用ResNet结构的骨干网络时,加入了FPN结构,骨干网络的输出feature map采用FPN中的P3层输出。 - \*CornerNet-Squeeze-dcn-mixup-cosine是基于原版CornerNet-Squeeze优化效果最好的模型,在ResNet的骨干网络基础上增加mixup预处理和使用cosine_decay - FCOS使用GIoU loss、用location分支预测centerness、左上右下角点偏移量归一化和ground truth中心匹配策略 diff --git a/ppdet/ext_op/cornerpool_lib.py b/ppdet/ext_op/cornerpool_lib.py index c56fc661ad27f89df7540f05bdbd01035e06ec67..4cae5a088c66bd945f4987a9201fe0914d54f83c 100644 --- a/ppdet/ext_op/cornerpool_lib.py +++ b/ppdet/ext_op/cornerpool_lib.py @@ -1,8 +1,16 @@ import os import paddle.fluid as fluid +use_cpp = False + file_dir = os.path.dirname(os.path.abspath(__file__)) -fluid.load_op_library(os.path.join(file_dir, 'src/cornerpool_lib.so')) +try: + fluid.load_op_library(os.path.join(file_dir, 'src/cornerpool_lib.so')) + use_cpp = True +except: + print( + 'Warning: cornerpool_lib.so not found, use python version instead which may drop the inference speed. Compile in ppdet/ext_op at first if you need cpp version.' + ) from paddle.fluid.layer_helper import LayerHelper @@ -14,6 +22,19 @@ __all__ = [ ] +def cornerpool_op(layer_type, input, name): + helper = LayerHelper(layer_type, input=input, name=name) + dtype = helper.input_dtype() + output = helper.create_variable_for_type_inference(dtype) + max_map = helper.create_variable_for_type_inference(dtype) + helper.append_op( + type=layer_type, + inputs={"X": input}, + outputs={"Output": output, + "MaxMap": max_map}) + return output + + def bottom_pool(input, is_test=False, name=None): """ This layer calculates the bottom pooling output based on the input. @@ -34,16 +55,28 @@ def bottom_pool(input, is_test=False, name=None): output = corner_pool.bottom_pool(input) """ if is_test: - helper = LayerHelper('bottom_pool', **locals()) - dtype = helper.input_dtype() - output = helper.create_variable_for_type_inference(dtype) - max_map = helper.create_variable_for_type_inference(dtype) - helper.append_op( - type="bottom_pool", - inputs={"X": input}, - outputs={"Output": output, - "MaxMap": max_map}) - return output + if use_cpp: + output = cornerpool_op("bottom_pool", input, name) + return output + + def cond(i, output): + return i < H + + def body(i, output): + cur = fluid.layers.slice(output, [2], [i], [H]) + next = fluid.layers.slice(output, [2], [0], [H - i]) + max_v = fluid.layers.elementwise_max(cur, next) + orig = fluid.layers.slice(output, [2], [0], [i]) + output = fluid.layers.concat([orig, max_v], axis=2) + i = i * 2 + return [i, output] + + H = fluid.layers.shape(input)[2] + i = fluid.layers.fill_constant(shape=[1], dtype='int32', value=1) + output = input + output = fluid.layers.while_loop(cond, body, [i, output]) + return output[-1] + H = input.shape[2] i = 1 output = input @@ -77,16 +110,27 @@ def top_pool(input, is_test=False, name=None): output = corner_pool.top_pool(input) """ if is_test: - helper = LayerHelper('top_pool', **locals()) - dtype = helper.input_dtype() - output = helper.create_variable_for_type_inference(dtype) - max_map = helper.create_variable_for_type_inference(dtype) - helper.append_op( - type="top_pool", - inputs={"X": input}, - outputs={"Output": output, - "MaxMap": max_map}) - return output + if use_cpp: + output = cornerpool_op("top_pool", input, name) + return output + + def cond(i, output): + return i < H + + def body(i, output): + cur = fluid.layers.slice(output, [2], [0], [H - i]) + next = fluid.layers.slice(output, [2], [i], [H]) + max_v = fluid.layers.elementwise_max(cur, next) + orig = fluid.layers.slice(output, [2], [H - i], [H]) + output = fluid.layers.concat([max_v, orig], axis=2) + i = i * 2 + return [i, output] + + H = fluid.layers.shape(input)[2] + i = fluid.layers.fill_constant(shape=[1], dtype='int32', value=1) + output = input + output = fluid.layers.while_loop(cond, body, [i, output]) + return output[-1] H = input.shape[2] i = 1 @@ -121,16 +165,27 @@ def right_pool(input, is_test=False, name=None): output = corner_pool.right_pool(input) """ if is_test: - helper = LayerHelper('right_pool', **locals()) - dtype = helper.input_dtype() - output = helper.create_variable_for_type_inference(dtype) - max_map = helper.create_variable_for_type_inference(dtype) - helper.append_op( - type="right_pool", - inputs={"X": input}, - outputs={"Output": output, - "MaxMap": max_map}) - return output + if use_cpp: + output = cornerpool_op("right_pool", input, name) + return output + + def cond(i, output): + return i < W + + def body(i, output): + cur = fluid.layers.slice(output, [3], [i], [W]) + next = fluid.layers.slice(output, [3], [0], [W - i]) + max_v = fluid.layers.elementwise_max(cur, next) + orig = fluid.layers.slice(output, [3], [0], [i]) + output = fluid.layers.concat([orig, max_v], axis=-1) + i = i * 2 + return [i, output] + + W = fluid.layers.shape(input)[3] + i = fluid.layers.fill_constant(shape=[1], dtype='int32', value=1) + output = input + output = fluid.layers.while_loop(cond, body, [i, output]) + return output[-1] W = input.shape[3] i = 1 @@ -165,16 +220,27 @@ def left_pool(input, is_test=False, name=None): output = corner_pool.left_pool(input) """ if is_test: - helper = LayerHelper('left_pool', **locals()) - dtype = helper.input_dtype() - output = helper.create_variable_for_type_inference(dtype) - max_map = helper.create_variable_for_type_inference(dtype) - helper.append_op( - type="left_pool", - inputs={"X": input}, - outputs={"Output": output, - "MaxMap": max_map}) - return output + if use_cpp: + output = cornerpool_op("left_pool", input, name) + return output + + def cond(i, output): + return i < W + + def body(i, output): + cur = fluid.layers.slice(output, [3], [0], [W - i]) + next = fluid.layers.slice(output, [3], [i], [W]) + max_v = fluid.layers.elementwise_max(cur, next) + orig = fluid.layers.slice(output, [3], [W - i], [W]) + output = fluid.layers.concat([max_v, orig], axis=-1) + i = i * 2 + return [i, output] + + W = fluid.layers.shape(input)[3] + i = fluid.layers.fill_constant(shape=[1], dtype='int32', value=1) + output = input + output = fluid.layers.while_loop(cond, body, [i, output]) + return output[-1] W = input.shape[3] i = 1 diff --git a/ppdet/modeling/architectures/cornernet_squeeze.py b/ppdet/modeling/architectures/cornernet_squeeze.py index fb2ce42a11e5d30a6e0ffcfd60ea5f6b50047764..6e3a48f7c818a8d8aefdf5b95da6cb530c74a076 100644 --- a/ppdet/modeling/architectures/cornernet_squeeze.py +++ b/ppdet/modeling/architectures/cornernet_squeeze.py @@ -22,6 +22,7 @@ from paddle import fluid from ppdet.core.workspace import register import numpy as np +from ppdet.utils.check import check_version __all__ = ['CornerNetSqueeze'] @@ -48,6 +49,7 @@ class CornerNetSqueeze(object): corner_head='CornerHead', num_classes=80, fpn=None): + check_version('1.8.0') super(CornerNetSqueeze, self).__init__() self.backbone = backbone self.corner_head = corner_head diff --git a/ppdet/utils/check.py b/ppdet/utils/check.py index 2b3283585c490edff5821eb7230e6d3bc756c5eb..10c4478ac6acc034055d4eb720c46693517c4624 100644 --- a/ppdet/utils/check.py +++ b/ppdet/utils/check.py @@ -45,17 +45,17 @@ def check_gpu(use_gpu): pass -def check_version(): +def check_version(version='1.7.0'): """ Log error and exit when the installed version of paddlepaddle is not satisfied. """ - err = "PaddlePaddle version 1.6 or higher is required, " \ + err = "PaddlePaddle version {} or higher is required, " \ "or a suitable develop version is satisfied as well. \n" \ - "Please make sure the version is good with your code." \ + "Please make sure the version is good with your code.".format(version) try: - fluid.require_version('1.7.0') + fluid.require_version(version) except Exception as e: logger.error(err) sys.exit(1)