Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 42e7110

Browse files
apeforestzhreshold
authored andcommitted
[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
1 parent 441fdb7 commit 42e7110

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/operator/contrib/multibox_target.cu

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ inline void MultiBoxTargetForward(const Tensor<gpu, 2, DType> &loc_target,
356356
const int num_anchors = anchors.size(0);
357357
const int num_classes = cls_preds.size(1);
358358
CHECK_GE(num_batches, 1);
359-
CHECK_GT(num_labels, 2);
360359
CHECK_GE(num_anchors, 1);
361360
CHECK_EQ(variances.ndim(), 4);
362361

tests/python/gpu/test_operator_gpu.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from test_sparse_operator import *
4343
from test_ndarray import *
4444
from test_subgraph_op import *
45+
from test_contrib_operator import test_multibox_target_op
4546

4647
set_default_context(mx.gpu(0))
4748
del test_support_vector_machine_l1_svm # noqa

tests/python/unittest/test_contrib_operator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,22 @@ def assert_match(inputs, x, y, threshold, is_ascend=False):
244244
assert_match([[0.5, 0.6], [0.1, 0.2], [0.3, 0.4]], [1, -1, 0], [2, 0], 1e-12, False)
245245
assert_match([[0.5, 0.6], [0.1, 0.2], [0.3, 0.4]], [-1, 0, 1], [1, 2], 100, True)
246246

247+
def test_multibox_target_op():
248+
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))
249+
cls_pred = mx.nd.array(list(range(10)), ctx=default_context()).reshape((1, -1, 2))
250+
label = mx.nd.array([1, 0.1, 0.1, 0.5, 0.6], ctx=default_context()).reshape((1, -1, 5))
251+
252+
loc_target, loc_mask, cls_target = \
253+
mx.nd.contrib.MultiBoxTarget(anchors, label, cls_pred,
254+
overlap_threshold=0.5,
255+
negative_mining_ratio=3,
256+
negative_mining_thresh=0.4)
257+
expected_loc_target = np.array([[5.0, 2.5000005, 3.4657357, 4.581454, 0., 0., 0., 0.]])
258+
expected_loc_mask = np.array([[1, 1, 1, 1, 0, 0, 0, 0]])
259+
expected_cls_target = np.array([[2, 0]])
260+
assert_allclose(loc_target.asnumpy(), expected_loc_target, rtol=1e-5, atol=1e-5)
261+
assert_array_equal(loc_mask.asnumpy(), expected_loc_mask)
262+
assert_array_equal(cls_target.asnumpy(), expected_cls_target)
247263

248264
if __name__ == '__main__':
249265
import nose

0 commit comments

Comments
 (0)