From 2efa71839c7d6a054dcaa486c34728c67e9de480 Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Thu, 18 Oct 2018 23:17:52 -0700 Subject: [PATCH] [MXNET-1033] Fix a bug in MultiboxTarget GPU implementation (#12840) * remove num_labels check in multibox_target * add unit test * test both cpu and gpu * add contrib operator to GPU unit test * do not test all contrib operator in gpu --- src/operator/contrib/multibox_target.cu | 1 - tests/python/gpu/test_operator_gpu.py | 1 + tests/python/unittest/test_contrib_operator.py | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/operator/contrib/multibox_target.cu b/src/operator/contrib/multibox_target.cu index c70dce3c1d7e..ca0428348a6c 100644 --- a/src/operator/contrib/multibox_target.cu +++ b/src/operator/contrib/multibox_target.cu @@ -356,7 +356,6 @@ inline void MultiBoxTargetForward(const Tensor &loc_target, const int num_anchors = anchors.size(0); const int num_classes = cls_preds.size(1); CHECK_GE(num_batches, 1); - CHECK_GT(num_labels, 2); CHECK_GE(num_anchors, 1); CHECK_EQ(variances.ndim(), 4); diff --git a/tests/python/gpu/test_operator_gpu.py b/tests/python/gpu/test_operator_gpu.py index dd7ec985c7c8..02895cd920e3 100644 --- a/tests/python/gpu/test_operator_gpu.py +++ b/tests/python/gpu/test_operator_gpu.py @@ -42,6 +42,7 @@ from test_sparse_operator import * from test_ndarray import * from test_subgraph_op import * +from test_contrib_operator import test_multibox_target_op set_default_context(mx.gpu(0)) del test_support_vector_machine_l1_svm # noqa diff --git a/tests/python/unittest/test_contrib_operator.py b/tests/python/unittest/test_contrib_operator.py index 76efe305bceb..58728d8dad68 100644 --- a/tests/python/unittest/test_contrib_operator.py +++ b/tests/python/unittest/test_contrib_operator.py @@ -244,6 +244,22 @@ def assert_match(inputs, x, y, threshold, is_ascend=False): assert_match([[0.5, 0.6], [0.1, 0.2], [0.3, 0.4]], [1, -1, 0], [2, 0], 1e-12, False) assert_match([[0.5, 0.6], [0.1, 0.2], [0.3, 0.4]], [-1, 0, 1], [1, 2], 100, True) +def test_multibox_target_op(): + anchors = mx.nd.array([[0.1, 0.2, 0.3, 0.4], [0.5, 0.6, 0.7, 0.8]], ctx=default_context()).reshape((1, -1, 4)) + cls_pred = mx.nd.array(list(range(10)), ctx=default_context()).reshape((1, -1, 2)) + label = mx.nd.array([1, 0.1, 0.1, 0.5, 0.6], ctx=default_context()).reshape((1, -1, 5)) + + loc_target, loc_mask, cls_target = \ + mx.nd.contrib.MultiBoxTarget(anchors, label, cls_pred, + overlap_threshold=0.5, + negative_mining_ratio=3, + negative_mining_thresh=0.4) + expected_loc_target = np.array([[5.0, 2.5000005, 3.4657357, 4.581454, 0., 0., 0., 0.]]) + expected_loc_mask = np.array([[1, 1, 1, 1, 0, 0, 0, 0]]) + expected_cls_target = np.array([[2, 0]]) + assert_allclose(loc_target.asnumpy(), expected_loc_target, rtol=1e-5, atol=1e-5) + assert_array_equal(loc_mask.asnumpy(), expected_loc_mask) + assert_array_equal(cls_target.asnumpy(), expected_cls_target) if __name__ == '__main__': import nose