@@ -564,13 +564,6 @@ def reference_affine_rotated_bounding_boxes_helper(
564564
565565 def affine_rotated_bounding_boxes (bounding_boxes ):
566566 dtype = bounding_boxes .dtype
567- int_dtype = dtype in (
568- torch .uint8 ,
569- torch .int8 ,
570- torch .int16 ,
571- torch .int32 ,
572- torch .int64 ,
573- )
574567 device = bounding_boxes .device
575568
576569 # Go to float before converting to prevent precision loss in case of CXCYWHR -> XYXYXYXY and W or H is 1
@@ -605,17 +598,12 @@ def affine_rotated_bounding_boxes(bounding_boxes):
605598 )
606599
607600 output = output [[2 , 3 , 0 , 1 , 6 , 7 , 4 , 5 ]] if flip else output
608- if not int_dtype :
609- output = _parallelogram_to_bounding_boxes (output )
601+ output = _parallelogram_to_bounding_boxes (output )
610602
611603 output = F .convert_bounding_box_format (
612604 output , old_format = tv_tensors .BoundingBoxFormat .XYXYXYXY , new_format = format
613605 )
614606
615- if torch .is_floating_point (output ) and int_dtype :
616- # It is important to round before cast.
617- output = torch .round (output )
618-
619607 # For rotated boxes, it is important to cast before clamping.
620608 return (
621609 F .clamp_bounding_boxes (
@@ -760,6 +748,8 @@ def test_kernel_image(self, size, interpolation, use_max_size, antialias, dtype,
760748 def test_kernel_bounding_boxes (self , format , size , use_max_size , dtype , device ):
761749 if not (max_size_kwarg := self ._make_max_size_kwarg (use_max_size = use_max_size , size = size )):
762750 return
751+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
752+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
763753
764754 bounding_boxes = make_bounding_boxes (
765755 format = format ,
@@ -1212,6 +1202,8 @@ def test_kernel_image(self, dtype, device):
12121202 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
12131203 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
12141204 def test_kernel_bounding_boxes (self , format , dtype , device ):
1205+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
1206+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
12151207 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
12161208 check_kernel (
12171209 F .horizontal_flip_bounding_boxes ,
@@ -1441,6 +1433,8 @@ def test_kernel_image(self, param, value, dtype, device):
14411433 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
14421434 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
14431435 def test_kernel_bounding_boxes (self , param , value , format , dtype , device ):
1436+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
1437+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
14441438 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
14451439 self ._check_kernel (
14461440 F .affine_bounding_boxes ,
@@ -1823,6 +1817,8 @@ def test_kernel_image(self, dtype, device):
18231817 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
18241818 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
18251819 def test_kernel_bounding_boxes (self , format , dtype , device ):
1820+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
1821+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
18261822 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
18271823 check_kernel (
18281824 F .vertical_flip_bounding_boxes ,
@@ -2021,6 +2017,8 @@ def test_kernel_bounding_boxes(self, param, value, format, dtype, device):
20212017 kwargs = {param : value }
20222018 if param != "angle" :
20232019 kwargs ["angle" ] = self ._MINIMAL_AFFINE_KWARGS ["angle" ]
2020+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
2021+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
20242022
20252023 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
20262024
@@ -3236,6 +3234,8 @@ def test_kernel_image(self, param, value, dtype, device):
32363234 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
32373235 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
32383236 def test_kernel_bounding_boxes (self , format , dtype , device ):
3237+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
3238+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
32393239 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
32403240
32413241 check_kernel (
@@ -3399,6 +3399,8 @@ def test_kernel_image(self, kwargs, dtype, device):
33993399 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
34003400 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
34013401 def test_kernel_bounding_boxes (self , kwargs , format , dtype , device ):
3402+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
3403+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
34023404 bounding_boxes = make_bounding_boxes (self .INPUT_SIZE , format = format , dtype = dtype , device = device )
34033405 check_kernel (F .crop_bounding_boxes , bounding_boxes , format = format , ** kwargs )
34043406
@@ -3576,6 +3578,8 @@ def _reference_crop_bounding_boxes(self, bounding_boxes, *, top, left, height, w
35763578 @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
35773579 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
35783580 def test_functional_bounding_box_correctness (self , kwargs , format , dtype , device ):
3581+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
3582+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
35793583 bounding_boxes = make_bounding_boxes (self .INPUT_SIZE , format = format , dtype = dtype , device = device )
35803584
35813585 actual = F .crop (bounding_boxes , ** kwargs )
@@ -3590,6 +3594,8 @@ def test_functional_bounding_box_correctness(self, kwargs, format, dtype, device
35903594 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
35913595 @pytest .mark .parametrize ("seed" , list (range (5 )))
35923596 def test_transform_bounding_boxes_correctness (self , output_size , format , dtype , device , seed ):
3597+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
3598+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
35933599 input_size = [s * 2 for s in output_size ]
35943600 bounding_boxes = make_bounding_boxes (input_size , format = format , dtype = dtype , device = device )
35953601
@@ -4267,6 +4273,10 @@ def _reference_convert_bounding_box_format(self, bounding_boxes, new_format):
42674273 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
42684274 @pytest .mark .parametrize ("fn_type" , ["functional" , "transform" ])
42694275 def test_correctness (self , old_format , new_format , dtype , device , fn_type ):
4276+ if not dtype .is_floating_point and (
4277+ tv_tensors .is_rotated_bounding_format (old_format ) or tv_tensors .is_rotated_bounding_format (new_format )
4278+ ):
4279+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
42704280 bounding_boxes = make_bounding_boxes (format = old_format , dtype = dtype , device = device )
42714281
42724282 if fn_type == "functional" :
@@ -4706,6 +4716,8 @@ def _reference_pad_bounding_boxes(self, bounding_boxes, *, padding):
47064716 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
47074717 @pytest .mark .parametrize ("fn" , [F .pad , transform_cls_to_functional (transforms .Pad )])
47084718 def test_bounding_boxes_correctness (self , padding , format , dtype , device , fn ):
4719+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
4720+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
47094721 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
47104722
47114723 actual = fn (bounding_boxes , padding = padding )
@@ -4876,6 +4888,8 @@ def _reference_center_crop_bounding_boxes(self, bounding_boxes, output_size):
48764888 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
48774889 @pytest .mark .parametrize ("fn" , [F .center_crop , transform_cls_to_functional (transforms .CenterCrop )])
48784890 def test_bounding_boxes_correctness (self , output_size , format , dtype , device , fn ):
4891+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
4892+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
48794893 bounding_boxes = make_bounding_boxes (self .INPUT_SIZE , format = format , dtype = dtype , device = device )
48804894
48814895 actual = fn (bounding_boxes , output_size )
@@ -5242,6 +5256,8 @@ def perspective_bounding_boxes(bounding_boxes):
52425256 @pytest .mark .parametrize ("dtype" , [torch .int64 , torch .float32 ])
52435257 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
52445258 def test_correctness_perspective_bounding_boxes (self , startpoints , endpoints , format , dtype , device ):
5259+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
5260+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
52455261 bounding_boxes = make_bounding_boxes (format = format , dtype = dtype , device = device )
52465262
52475263 actual = F .perspective (bounding_boxes , startpoints = startpoints , endpoints = endpoints )
@@ -5511,6 +5527,8 @@ class TestClampBoundingBoxes:
55115527 @pytest .mark .parametrize ("dtype" , [torch .int64 , torch .float32 ])
55125528 @pytest .mark .parametrize ("device" , cpu_and_cuda ())
55135529 def test_kernel (self , format , clamping_mode , dtype , device ):
5530+ if not dtype .is_floating_point and tv_tensors .is_rotated_bounding_format (format ):
5531+ pytest .xfail ("Rotated bounding boxes should be floating point tensors" )
55145532 bounding_boxes = make_bounding_boxes (format = format , clamping_mode = clamping_mode , dtype = dtype , device = device )
55155533 check_kernel (
55165534 F .clamp_bounding_boxes ,
@@ -6938,14 +6956,11 @@ def test_classification_preset(image_type, label_type, dataset_return_type, to_t
69386956
69396957
69406958@pytest .mark .parametrize ("input_size" , [(17 , 11 ), (11 , 17 ), (11 , 11 )])
6941- @pytest .mark .parametrize ("dtype" , [torch .float32 , torch .int64 ])
69426959@pytest .mark .parametrize ("device" , cpu_and_cuda ())
6943- def test_parallelogram_to_bounding_boxes (input_size , dtype , device ):
6960+ def test_parallelogram_to_bounding_boxes (input_size , device ):
69446961 # Assert that applying `_parallelogram_to_bounding_boxes` to rotated boxes
69456962 # does not modify the input.
6946- bounding_boxes = make_bounding_boxes (
6947- input_size , format = tv_tensors .BoundingBoxFormat .XYXYXYXY , dtype = dtype , device = device
6948- )
6963+ bounding_boxes = make_bounding_boxes (input_size , format = tv_tensors .BoundingBoxFormat .XYXYXYXY , device = device )
69496964 actual = _parallelogram_to_bounding_boxes (bounding_boxes )
69506965 torch .testing .assert_close (actual , bounding_boxes , rtol = 0 , atol = 1 )
69516966
0 commit comments