Skip to content
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

fix: Restored support of tuple of Tensors for region pooling ops #2199

Merged
merged 6 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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 @@ -548,5 +548,29 @@ def test_frozenbatchnorm2d_repr(self):
self.assertEqual(t.__repr__(), expected_string)


class BoxConversionTester(unittest.TestCase):
@staticmethod
def _get_box_sequences():
# Define here the argument type of `boxes` supported by region pooling operations
box_tensor = torch.tensor([[0, 0, 0, 100, 100], [[1, 0, 0, 100, 100]]], dtype=float)
box_list = [torch.tensor([[0, 0, 100, 100]], dtype=float), torch.tensor([[0, 0, 100, 100]], dtype=float)]
box_tuple = tuple(box_list)
return box_tensor, box_list, box_tuple

def test_check_roi_boxes_shape(self):
# Ensure common sequences of tensors are supported
for box_sequence in self._get_box_sequences():
self.assertIsNone(ops._utils.check_roi_boxes_shape(box_sequence))

def test_convert_boxes_to_roi_format(self):
# Ensure common sequences of tensors yield the same result
ref_tensor = None
for box_sequence in self._get_box_sequences():
if ref_tensor is None:
ref_tensor = ops._utils.convert_boxes_to_roi_format(box_sequence)
else:
self.assertTrue(torch.equal(ref_tensor, ops._utils.convert_boxes_to_roi_format(box_sequence)))


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion torchvision/ops/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def convert_boxes_to_roi_format(boxes):


def check_roi_boxes_shape(boxes):
if isinstance(boxes, list):
if isinstance(boxes, (list, tuple)):
for _tensor in boxes:
assert _tensor.size(1) == 4, \
'The shape of the tensor in the boxes list is not correct as List[Tensor[L, 4]]'
Expand Down