From 266c7d7b87e87e2a39a3688c225d7782ea4b5e41 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Fri, 17 Feb 2023 09:32:47 +0100 Subject: [PATCH 1/5] enforce that functional dispatchers keep the bounding box format in tact --- test/test_prototype_transforms_functional.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/test_prototype_transforms_functional.py b/test/test_prototype_transforms_functional.py index 7dff7a509ad..ffee57eea6f 100644 --- a/test/test_prototype_transforms_functional.py +++ b/test/test_prototype_transforms_functional.py @@ -508,6 +508,22 @@ def test_unkown_type(self, info): with pytest.raises(TypeError, match=re.escape(str(type(unkown_input)))): info.dispatcher(unkown_input, *other_args, **kwargs) + @make_info_args_kwargs_parametrization( + [ + info + for info in DISPATCHER_INFOS + if datapoints.BoundingBox in info.kernels and info.dispatcher is not F.convert_format_bounding_box + ], + args_kwargs_fn=lambda info: info.sample_inputs(datapoints.BoundingBox), + ) + def test_bounding_box_format_consistency(self, info, args_kwargs): + (bounding_box, *other_args), kwargs = args_kwargs.load() + format = bounding_box.format + + output = info.dispatcher(bounding_box, *other_args, **kwargs) + + assert output.format == format + @pytest.mark.parametrize( ("alias", "target"), From 5d51953f658777535d9e5c1575b7c11edb863fb4 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Fri, 17 Feb 2023 09:42:34 +0100 Subject: [PATCH 2/5] add test for degenerate bounding boxes --- test/test_prototype_transforms.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test_prototype_transforms.py b/test/test_prototype_transforms.py index 8b1665a3d31..51721832047 100644 --- a/test/test_prototype_transforms.py +++ b/test/test_prototype_transforms.py @@ -248,6 +248,7 @@ def test_common(self, transform, adapter, container_type, image_or_video, device if adapter is not None: input = adapter(transform, input, device) + keys = list(input.keys()) if container_type in {tuple, list}: input = container_type(input.values()) @@ -269,6 +270,20 @@ def test_common(self, transform, adapter, container_type, image_or_video, device else: assert output_item is input_item + sanitize = transforms.SanitizeBoundingBoxes() + for output_degenerate_bounding_box, input_degenerate_bounding_box in ( + (output_item, input_item) + for key, output_item, input_item in zip(keys, output_flat, input_flat) + if "degenerate" in key + ): + sample = dict( + bounding_box=output_degenerate_bounding_box, + labels=torch.randint( + 10, input_degenerate_bounding_box.shape[:-1], device=input_degenerate_bounding_box.device + ), + ) + assert sanitize(sample)["bounding_box"].shape == (0, 4) + @parametrize( [ ( From 5253ce9318de3ecffda294f16f136ec4f7663860 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Fri, 17 Feb 2023 12:40:46 +0100 Subject: [PATCH 3/5] relax degenerate test --- test/test_prototype_transforms.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/test/test_prototype_transforms.py b/test/test_prototype_transforms.py index 51721832047..1760b824b46 100644 --- a/test/test_prototype_transforms.py +++ b/test/test_prototype_transforms.py @@ -248,7 +248,6 @@ def test_common(self, transform, adapter, container_type, image_or_video, device if adapter is not None: input = adapter(transform, input, device) - keys = list(input.keys()) if container_type in {tuple, list}: input = container_type(input.values()) @@ -270,19 +269,14 @@ def test_common(self, transform, adapter, container_type, image_or_video, device else: assert output_item is input_item - sanitize = transforms.SanitizeBoundingBoxes() - for output_degenerate_bounding_box, input_degenerate_bounding_box in ( - (output_item, input_item) - for key, output_item, input_item in zip(keys, output_flat, input_flat) - if "degenerate" in key - ): + # Enforce that the transform does not turn a degenerate box marked by RandomIoUCrop (or any other future + # transform that does this), back into a valid one. + for format in list(datapoints.BoundingBoxFormat): sample = dict( - bounding_box=output_degenerate_bounding_box, - labels=torch.randint( - 10, input_degenerate_bounding_box.shape[:-1], device=input_degenerate_bounding_box.device - ), + boxes=datapoints.BoundingBox([[0, 0, 0, 0]], format=format, spatial_size=(224, 244)), + labels=torch.tensor([3]), ) - assert sanitize(sample)["bounding_box"].shape == (0, 4) + assert transforms.SanitizeBoundingBoxes()(sample)["boxes"].shape == (0, 4) @parametrize( [ From da21ae4a157dee52d5e4f191b4a32d9c49bb4b47 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Fri, 17 Feb 2023 12:42:05 +0100 Subject: [PATCH 4/5] add format test to transforms as well --- test/test_prototype_transforms.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test_prototype_transforms.py b/test/test_prototype_transforms.py index 1760b824b46..ac7c2e85354 100644 --- a/test/test_prototype_transforms.py +++ b/test/test_prototype_transforms.py @@ -269,6 +269,11 @@ def test_common(self, transform, adapter, container_type, image_or_video, device else: assert output_item is input_item + if isinstance(input_item, datapoints.BoundingBox) and not isinstance( + transform, transforms.ConvertBoundingBoxFormat + ): + assert output_item.format == input_item.format + # Enforce that the transform does not turn a degenerate box marked by RandomIoUCrop (or any other future # transform that does this), back into a valid one. for format in list(datapoints.BoundingBoxFormat): From 8017b7ef84e9f4a8ee7576ae2a079d770229dd64 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Fri, 17 Feb 2023 13:30:25 +0100 Subject: [PATCH 5/5] add todo --- test/test_prototype_transforms.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_prototype_transforms.py b/test/test_prototype_transforms.py index ac7c2e85354..04093309774 100644 --- a/test/test_prototype_transforms.py +++ b/test/test_prototype_transforms.py @@ -276,6 +276,7 @@ def test_common(self, transform, adapter, container_type, image_or_video, device # Enforce that the transform does not turn a degenerate box marked by RandomIoUCrop (or any other future # transform that does this), back into a valid one. + # TODO: we should test that against all degenerate boxes above for format in list(datapoints.BoundingBoxFormat): sample = dict( boxes=datapoints.BoundingBox([[0, 0, 0, 0]], format=format, spatial_size=(224, 244)),