@@ -608,6 +608,16 @@ def affine_rotated_bounding_boxes(bounding_boxes):
608608 output , old_format = tv_tensors .BoundingBoxFormat .XYXYXYXY , new_format = format
609609 )
610610
611+ if torch .is_floating_point (output ) and dtype in (
612+ torch .uint8 ,
613+ torch .int8 ,
614+ torch .int16 ,
615+ torch .int32 ,
616+ torch .int64 ,
617+ ):
618+ # it is better to round before cast
619+ output = torch .round (output )
620+
611621 if clamp :
612622 # It is important to clamp before casting, especially for CXCYWHR format, dtype=int64
613623 output = F .clamp_bounding_boxes (
@@ -3934,7 +3944,7 @@ def test_kernel_image(self, param, value, dtype, device):
39343944 ),
39353945 )
39363946
3937- @pytest .mark .parametrize ("format" , SUPPORTED_BOX_FORMATS )
3947+ @pytest .mark .parametrize ("format" , list ( tv_tensors . BoundingBoxFormat ) )
39383948 def test_kernel_bounding_boxes (self , format ):
39393949 bounding_boxes = make_bounding_boxes (format = format )
39403950 check_kernel (
@@ -4054,12 +4064,15 @@ def _reference_pad_bounding_boxes(self, bounding_boxes, *, padding):
40544064 height = bounding_boxes .canvas_size [0 ] + top + bottom
40554065 width = bounding_boxes .canvas_size [1 ] + left + right
40564066
4057- return reference_affine_bounding_boxes_helper (
4058- bounding_boxes , affine_matrix = affine_matrix , new_canvas_size = (height , width )
4067+ helper = (
4068+ reference_affine_rotated_bounding_boxes_helper
4069+ if tv_tensors .is_rotated_bounding_format (bounding_boxes .format )
4070+ else reference_affine_bounding_boxes_helper
40594071 )
4072+ return helper (bounding_boxes , affine_matrix = affine_matrix , new_canvas_size = (height , width ))
40604073
40614074 @pytest .mark .parametrize ("padding" , CORRECTNESS_PADDINGS )
4062- @pytest .mark .parametrize ("format" , SUPPORTED_BOX_FORMATS )
4075+ @pytest .mark .parametrize ("format" , list ( tv_tensors . BoundingBoxFormat ) )
40634076 @pytest .mark .parametrize ("dtype" , [torch .int64 , torch .float32 ])
40644077 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
40654078 @pytest .mark .parametrize ("fn" , [F .pad , transform_cls_to_functional (transforms .Pad )])
@@ -4069,7 +4082,7 @@ def test_bounding_boxes_correctness(self, padding, format, dtype, device, fn):
40694082 actual = fn (bounding_boxes , padding = padding )
40704083 expected = self ._reference_pad_bounding_boxes (bounding_boxes , padding = padding )
40714084
4072- assert_equal (actual , expected )
4085+ torch . testing . assert_close (actual , expected )
40734086
40744087
40754088class TestCenterCrop :
0 commit comments