Skip to content

Add JIT tests for box_area, box_iou, genaralized_box_iou #4472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,14 @@ def area_check(box, expected, tolerance=1e-4):
expected = torch.tensor([605113.875, 600495.1875, 592247.25])
area_check(box_tensor, expected)

def test_box_area_jit(self):
box_tensor = torch.tensor([[0, 0, 100, 100], [0, 0, 0, 0]], dtype=torch.float)
TOLERANCE = 1e-3
expected = ops.box_area(box_tensor)
scripted_fn = torch.jit.script(ops.box_area)
scripted_area = scripted_fn(box_tensor)
torch.testing.assert_close(scripted_area, expected, rtol=0.0, atol=TOLERANCE)


class TestBoxIou:
def test_iou(self):
Expand All @@ -978,6 +986,14 @@ def iou_check(box, expected, tolerance=1e-4):
expected = torch.tensor([[1.0, 0.9933, 0.9673], [0.9933, 1.0, 0.9737], [0.9673, 0.9737, 1.0]])
iou_check(box_tensor, expected, tolerance=0.002 if dtype == torch.float16 else 1e-4)

def test_iou_jit(self):
box_tensor = torch.tensor([[0, 0, 100, 100], [0, 0, 50, 50], [200, 200, 300, 300]], dtype=torch.float)
TOLERANCE = 1e-3
expected = ops.box_iou(box_tensor, box_tensor)
scripted_fn = torch.jit.script(ops.box_iou)
scripted_iou = scripted_fn(box_tensor, box_tensor)
torch.testing.assert_close(scripted_iou, expected, rtol=0.0, atol=TOLERANCE)


class TestGenBoxIou:
def test_gen_iou(self):
Expand All @@ -999,6 +1015,14 @@ def gen_iou_check(box, expected, tolerance=1e-4):
expected = torch.tensor([[1.0, 0.9933, 0.9673], [0.9933, 1.0, 0.9737], [0.9673, 0.9737, 1.0]])
gen_iou_check(box_tensor, expected, tolerance=0.002 if dtype == torch.float16 else 1e-3)

def test_giou_jit(self):
box_tensor = torch.tensor([[0, 0, 100, 100], [0, 0, 50, 50], [200, 200, 300, 300]], dtype=torch.float)
Copy link
Contributor Author

@oke-aditya oke-aditya Sep 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember adding the IoU tests, and calculating by hand an year ago. Great that they are still used! 😄
#2642

TOLERANCE = 1e-3
expected = ops.generalized_box_iou(box_tensor, box_tensor)
scripted_fn = torch.jit.script(ops.generalized_box_iou)
scripted_iou = scripted_fn(box_tensor, box_tensor)
torch.testing.assert_close(scripted_iou, expected, rtol=0.0, atol=TOLERANCE)


class TestStochasticDepth:
@pytest.mark.parametrize('p', [0.2, 0.5, 0.8])
Expand Down