From 6c8d4858657fceba11d7609c6e43f5138afa2190 Mon Sep 17 00:00:00 2001 From: frgfm Date: Tue, 20 Oct 2020 12:04:48 +0200 Subject: [PATCH 1/4] feat: Added __repr__ to MultiScaleRoIAlign --- torchvision/ops/poolers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torchvision/ops/poolers.py b/torchvision/ops/poolers.py index 463ce7e5ddc..83e9c20d313 100644 --- a/torchvision/ops/poolers.py +++ b/torchvision/ops/poolers.py @@ -258,3 +258,6 @@ def forward( result = _onnx_merge_levels(levels, tracing_results) return result + + def __repr__(self) -> str: + return f"{self.__class__.__name__}(output_size={self.output_size}, sampling_ratio={self.sampling_ratio})" From 1801ff3c3d1e2d143a8b59d88485a8554993e67f Mon Sep 17 00:00:00 2001 From: frgfm Date: Tue, 20 Oct 2020 12:05:06 +0200 Subject: [PATCH 2/4] test: Added unittest for __repr__ of MultiScaleRoIAlign --- test/test_ops.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_ops.py b/test/test_ops.py index 9858450f76c..0269a3c42d7 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -357,6 +357,18 @@ def _test_boxes_shape(self): self._helper_boxes_shape(ops.ps_roi_align) +class MultiScaleRoIAlignTester(unittest.TestCase): + def test_msroialign_repr(self): + output_size = (7, 7) + sampling_ratio = 2 + # Pass mock feature map names + t = ops.poolers.MultiScaleRoIAlign(['0'], output_size, sampling_ratio) + + # Check integrity of object __repr__ attribute + expected_string = f"MultiScaleRoIAlign(output_size={output_size}, sampling_ratio={sampling_ratio})" + self.assertEqual(t.__repr__(), expected_string) + + class NMSTester(unittest.TestCase): def reference_nms(self, boxes, scores, iou_threshold): """ From dff8b4ad4a5341cbbfd9f9cce27d7d358240b425 Mon Sep 17 00:00:00 2001 From: frgfm Date: Tue, 20 Oct 2020 14:56:55 +0200 Subject: [PATCH 3/4] feat: Added feature map names in __repr__ --- torchvision/ops/poolers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/torchvision/ops/poolers.py b/torchvision/ops/poolers.py index 83e9c20d313..02dbf3904bb 100644 --- a/torchvision/ops/poolers.py +++ b/torchvision/ops/poolers.py @@ -260,4 +260,5 @@ def forward( return result def __repr__(self) -> str: - return f"{self.__class__.__name__}(output_size={self.output_size}, sampling_ratio={self.sampling_ratio})" + return (f"{self.__class__.__name__}(featmap_names={self.featmap_names}, " + f"output_size={self.output_size}, sampling_ratio={self.sampling_ratio})") From b8d5cb3652f9220809d7c10b0efc21915b379c6a Mon Sep 17 00:00:00 2001 From: frgfm Date: Tue, 20 Oct 2020 14:57:09 +0200 Subject: [PATCH 4/4] test: Updated unittest --- test/test_ops.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test_ops.py b/test/test_ops.py index 0269a3c42d7..a6f161051fc 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -359,13 +359,15 @@ def _test_boxes_shape(self): class MultiScaleRoIAlignTester(unittest.TestCase): def test_msroialign_repr(self): + fmap_names = ['0'] output_size = (7, 7) sampling_ratio = 2 # Pass mock feature map names - t = ops.poolers.MultiScaleRoIAlign(['0'], output_size, sampling_ratio) + t = ops.poolers.MultiScaleRoIAlign(fmap_names, output_size, sampling_ratio) # Check integrity of object __repr__ attribute - expected_string = f"MultiScaleRoIAlign(output_size={output_size}, sampling_ratio={sampling_ratio})" + expected_string = (f"MultiScaleRoIAlign(featmap_names={fmap_names}, output_size={output_size}, " + f"sampling_ratio={sampling_ratio})") self.assertEqual(t.__repr__(), expected_string)