From 9c78437d895e9035ef1f30e247ffd0d9b4231829 Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Tue, 16 Oct 2018 13:23:36 -0700 Subject: [PATCH 1/6] remove num_labels check in multibox_target --- src/operator/contrib/multibox_target.cu | 1 - 1 file changed, 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); From 1dad4af3ace8db87adc2a8bcc2b05c5f81e8f565 Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Thu, 18 Oct 2018 00:37:19 -0700 Subject: [PATCH 2/6] add unit test --- tests/python/unittest/test_contrib_operator.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/python/unittest/test_contrib_operator.py b/tests/python/unittest/test_contrib_operator.py index 76efe305bceb..4fb18b8ca7aa 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]]).reshape((1, -1, 4)) + cls_pred = mx.nd.array(list(range(10))).reshape((1, -1, 2)) + label = mx.nd.array([1, 0.1, 0.1, 0.5, 0.6]).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 From d600279220f87633a927cb7ef3292fdc3a73d9af Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Thu, 18 Oct 2018 11:47:21 -0700 Subject: [PATCH 3/6] test both cpu and gpu --- tests/python/unittest/test_contrib_operator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/python/unittest/test_contrib_operator.py b/tests/python/unittest/test_contrib_operator.py index 4fb18b8ca7aa..58728d8dad68 100644 --- a/tests/python/unittest/test_contrib_operator.py +++ b/tests/python/unittest/test_contrib_operator.py @@ -245,9 +245,9 @@ 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, 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]]).reshape((1, -1, 4)) - cls_pred = mx.nd.array(list(range(10))).reshape((1, -1, 2)) - label = mx.nd.array([1, 0.1, 0.1, 0.5, 0.6]).reshape((1, -1, 5)) + 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, From dee6f0ed8772c08cce8cdda7d3d99250d3ab5137 Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Thu, 18 Oct 2018 14:24:10 -0700 Subject: [PATCH 4/6] add contrib operator to GPU unit test --- tests/python/gpu/test_operator_gpu.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/gpu/test_operator_gpu.py b/tests/python/gpu/test_operator_gpu.py index dd7ec985c7c8..cfa6a32f1b65 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 * set_default_context(mx.gpu(0)) del test_support_vector_machine_l1_svm # noqa From 2191c5341de94e59617f2b04a676d7644a81df9e Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Thu, 18 Oct 2018 16:01:22 -0700 Subject: [PATCH 5/6] do not test all contrib operator in gpu --- tests/python/gpu/test_operator_gpu.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/gpu/test_operator_gpu.py b/tests/python/gpu/test_operator_gpu.py index cfa6a32f1b65..02895cd920e3 100644 --- a/tests/python/gpu/test_operator_gpu.py +++ b/tests/python/gpu/test_operator_gpu.py @@ -42,7 +42,7 @@ from test_sparse_operator import * from test_ndarray import * from test_subgraph_op import * -from test_contrib_operator import * +from test_contrib_operator import test_multibox_target_op set_default_context(mx.gpu(0)) del test_support_vector_machine_l1_svm # noqa From bfbceda434b49ad6db203f6788bbf1038690afc6 Mon Sep 17 00:00:00 2001 From: Lin Yuan Date: Mon, 22 Oct 2018 23:36:22 -0700 Subject: [PATCH 6/6] Fix the large int assign problem --- src/operator/tensor/matrix_op-inl.h | 2 +- tests/python/unittest/test_ndarray.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/operator/tensor/matrix_op-inl.h b/src/operator/tensor/matrix_op-inl.h index bfee083ca1a6..e375d640536a 100644 --- a/src/operator/tensor/matrix_op-inl.h +++ b/src/operator/tensor/matrix_op-inl.h @@ -992,7 +992,7 @@ void SliceAssignOpForward(const nnvm::NodeAttrs& attrs, } struct SliceAssignScalarParam : public dmlc::Parameter { - real_t scalar; + double scalar; nnvm::Tuple> begin, end; nnvm::Tuple> step; DMLC_DECLARE_PARAMETER(SliceAssignScalarParam) { diff --git a/tests/python/unittest/test_ndarray.py b/tests/python/unittest/test_ndarray.py index 0044ae38f5e9..128dfa61793a 100644 --- a/tests/python/unittest/test_ndarray.py +++ b/tests/python/unittest/test_ndarray.py @@ -1355,6 +1355,17 @@ def test_assign_float_value_to_ndarray(): b[0] = a[0] assert same(a, b.asnumpy()) +def test_assign_large_int_to_ndarray(): + """Test case from https://github.com/apache/incubator-mxnet/issues/11639""" + a = mx.nd.zeros((4, 1), dtype=np.int32) + a[1,0] = int(16800001) + a[2,0] = int(16800002) + b = a.asnumpy() + assert same(b[1,0], 16800001) + a = a-1 + b = a.asnumpy() + assert same(b[1,0], 16800000) + @with_seed() def test_assign_a_row_to_ndarray(): """Test case from https://github.com/apache/incubator-mxnet/issues/9976"""