Unverified Commit 34810c0c authored by Francisco Massa's avatar Francisco Massa Committed by GitHub
Browse files

Add more tests to NMS (#2279)

* Add more tests to NMS

* Fix lint
parent b40f49fd
...@@ -393,6 +393,10 @@ class NMSTester(unittest.TestCase): ...@@ -393,6 +393,10 @@ class NMSTester(unittest.TestCase):
keep_ref = self.reference_nms(boxes, scores, iou) keep_ref = self.reference_nms(boxes, scores, iou)
keep = ops.nms(boxes, scores, iou) keep = ops.nms(boxes, scores, iou)
self.assertTrue(torch.allclose(keep, keep_ref), err_msg.format(iou)) self.assertTrue(torch.allclose(keep, keep_ref), err_msg.format(iou))
self.assertRaises(RuntimeError, ops.nms, torch.rand(4), torch.rand(3), 0.5)
self.assertRaises(RuntimeError, ops.nms, torch.rand(3, 5), torch.rand(3), 0.5)
self.assertRaises(RuntimeError, ops.nms, torch.rand(3, 4), torch.rand(3, 2), 0.5)
self.assertRaises(RuntimeError, ops.nms, torch.rand(3, 4), torch.rand(4), 0.5)
@unittest.skipIf(not torch.cuda.is_available(), "CUDA unavailable") @unittest.skipIf(not torch.cuda.is_available(), "CUDA unavailable")
def test_nms_cuda(self): def test_nms_cuda(self):
......
...@@ -12,6 +12,24 @@ at::Tensor nms( ...@@ -12,6 +12,24 @@ at::Tensor nms(
const at::Tensor& dets, const at::Tensor& dets,
const at::Tensor& scores, const at::Tensor& scores,
const double iou_threshold) { const double iou_threshold) {
TORCH_CHECK(
dets.dim() == 2, "boxes should be a 2d tensor, got ", dets.dim(), "D");
TORCH_CHECK(
dets.size(1) == 4,
"boxes should have 4 elements in dimension 1, got ",
dets.size(1));
TORCH_CHECK(
scores.dim() == 1,
"scores should be a 1d tensor, got ",
scores.dim(),
"D");
TORCH_CHECK(
dets.size(0) == scores.size(0),
"boxes and scores should have same number of elements in ",
"dimension 0, got ",
dets.size(0),
" and ",
scores.size(0));
if (dets.is_cuda()) { if (dets.is_cuda()) {
#if defined(WITH_CUDA) #if defined(WITH_CUDA)
if (dets.numel() == 0) { if (dets.numel() == 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment