Skip to content

Commit

Permalink
Add more tests to NMS (#2279)
Browse files Browse the repository at this point in the history
* Add more tests to NMS

* Fix lint
  • Loading branch information
fmassa authored Jun 1, 2020
1 parent b40f49f commit 34810c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ def test_nms(self):
keep_ref = self.reference_nms(boxes, scores, iou)
keep = ops.nms(boxes, scores, 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")
def test_nms_cuda(self):
Expand Down
18 changes: 18 additions & 0 deletions torchvision/csrc/nms.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ at::Tensor nms(
const at::Tensor& dets,
const at::Tensor& scores,
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 defined(WITH_CUDA)
if (dets.numel() == 0) {
Expand Down

0 comments on commit 34810c0

Please sign in to comment.