diff --git a/ppdet/ext_op/README.md b/ppdet/ext_op/README.md index 6bfeb0e8843abeacedc7e062c0eb5636124a4644..0516cc70289d5238d4f3cf9299b7c133529154df 100644 --- a/ppdet/ext_op/README.md +++ b/ppdet/ext_op/README.md @@ -59,12 +59,9 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`python -c 'import paddle; print(paddle. 执行下列单测,确保自定义算子可在网络中正确使用: ``` -# 回到 ext_op 目录,添加 PYTHONPATH +# 回到 ext_op 目录,运行单测 cd .. -export PYTHONPATH=$PYTHONPATH:`pwd` - -# 运行单测 -python test/test_corner_op.py +python test/test_corner_pool.py ``` 单测运行成功会输出提示信息,如下所示: diff --git a/ppdet/ext_op/test/test_corner_pool.py b/ppdet/ext_op/test/test_corner_pool.py index b0d10b8939a24a557533c192de01c80079331356..211aaaded08ba62d47505300e79ef895550621d4 100755 --- a/ppdet/ext_op/test/test_corner_pool.py +++ b/ppdet/ext_op/test/test_corner_pool.py @@ -17,7 +17,14 @@ from __future__ import print_function import unittest import numpy as np import paddle.fluid as fluid -import cornerpool_lib +import os +import sys +# add python path of PadleDetection to sys.path +parent_path = os.path.abspath(os.path.join(__file__, *(['..'] * 4))) +if parent_path not in sys.path: + sys.path.append(parent_path) + +from ppdet.ext_op import cornerpool_lib def bottom_pool_np(x): @@ -83,11 +90,7 @@ class TestRightPoolOp(unittest.TestCase): place = fluid.CUDAPlace(0) with fluid.program_guard(tp, sp): - x = fluid.data( - name=self.name, - shape=x_shape, - dtype=x_type, - append_batch_size=False) + x = fluid.data(name=self.name, shape=x_shape, dtype=x_type) y = self.func_map[self.name][0](x) np.random.seed(0) diff --git a/ppdet/modeling/anchor_heads/corner_head.py b/ppdet/modeling/anchor_heads/corner_head.py index 01e1195b0c68bb66837db29a69ab6e6b9f9f5b6e..33a3a55ecf32b975bdb4ecef2b1b9b6abb0009c8 100644 --- a/ppdet/modeling/anchor_heads/corner_head.py +++ b/ppdet/modeling/anchor_heads/corner_head.py @@ -243,11 +243,6 @@ class CornerHead(object): ae_threshold=1, num_dets=1000, top_k=100): - try: - import cornerpool_lib - except: - logger.error( - "cornerpool_lib not found, compile in ppdet/ext_op at first") self.train_batch_size = train_batch_size self.test_batch_size = test_batch_size self.num_classes = num_classes @@ -279,6 +274,11 @@ class CornerHead(object): return conv1 def get_output(self, input): + try: + from ppdet.ext_op import cornerpool_lib + except: + logger.error( + "cornerpool_lib not found, compile in ppdet/ext_op at first") for ind in range(self.stack): cnv = input[ind] tl_modules = corner_pool( @@ -455,6 +455,11 @@ class CornerHead(object): return {'loss': loss} def get_prediction(self, input): + try: + from ppdet.ext_op import cornerpool_lib + except: + logger.error( + "cornerpool_lib not found, compile in ppdet/ext_op at first") ind = self.stack - 1 tl_modules = corner_pool( input,