@@ -6946,6 +6946,7 @@ def test_no_valid_input(self, query):
69466946 with pytest .raises (TypeError , match = "No image" ):
69476947 query (["blah" ])
69486948
6949+ # TODOKP this is tested here in TestUtils but defined in meta
69496950 @pytest .mark .parametrize (
69506951 "boxes" ,
69516952 [
@@ -6955,42 +6956,28 @@ def test_no_valid_input(self, query):
69556956 tv_tensors .BoundingBoxes (torch .tensor ([[1.5 , 1.5 , 1.0 , 1.0 , 45 ]]), format = "CXCYWHR" , canvas_size = (4 , 4 )),
69566957 tv_tensors .BoundingBoxes (torch .tensor ([[1.0 , 1.0 , 1.0 , 1.0 , 45.0 ]]), format = "XYWHR" , canvas_size = (4 , 4 )),
69576958 tv_tensors .BoundingBoxes (
6958- torch .tensor ([[1.0 , 1.0 , 1.0 , 2.0 , 2.0 , 2.0 , 2.0 , 1.0 ]]), format = "XY" * 4 , canvas_size = (4 , 4 )
6959+ torch .tensor ([[1.0 , 1.0 , 1.0 , 2.0 , 2.0 , 2.0 , 2.0 , 1.0 ]]), format = "XYXYXYXY" , canvas_size = (4 , 4 )
69596960 ),
69606961 ],
69616962 )
69626963 def test_convert_bounding_boxes_to_points (self , boxes : tv_tensors .BoundingBoxes ):
69636964 kp = F .convert_bounding_boxes_to_points (boxes )
69646965 assert kp .shape == (boxes .shape [0 ], 4 , 2 )
69656966 assert kp .dtype == boxes .dtype
6966- # kp is a list of A, B, C, D polygons.
69676967
6968+ # We manually convert the kp back into a BoundingBoxes, and convert that
6969+ # bbox back into the original `boxes` format to compare against it.
69686970 if F ._meta .is_rotated_bounding_box_format (boxes .format ):
6969- # In the rotated case
6970- # If we convert to XYXYXYXY format, we should get what we want.
69716971 reconverted = kp .reshape (- 1 , 8 )
6972- reconverted_bbox = F .convert_bounding_box_format (
6973- tv_tensors .BoundingBoxes (
6974- reconverted , format = tv_tensors .BoundingBoxFormat .XYXYXYXY , canvas_size = kp .canvas_size
6975- ),
6976- new_format = boxes .format ,
6977- )
6978- assert (
6979- (reconverted_bbox - boxes ).abs () < 1e-5
6980- ).all (), ( # Rotational computations mean that we can't ensure exactitude.
6981- f"Invalid reconversion :\n \t Got: { reconverted_bbox } \n \t From: { boxes } \n \t "
6982- f"Diff: { reconverted_bbox - boxes } "
6983- )
6972+ intermediate_format = tv_tensors .BoundingBoxFormat .XYXYXYXY
69846973 else :
6985- # In the unrotated case
6986- # If we use A | C, we should get back the XYXY format of bounding box
69876974 reconverted = torch .cat ([kp [..., 0 , :], kp [..., 2 , :]], dim = - 1 )
6988- reconverted_bbox = F . convert_bounding_box_format (
6989- tv_tensors . BoundingBoxes (
6990- reconverted , format = tv_tensors . BoundingBoxFormat . XYXY , canvas_size = kp . canvas_size
6991- ),
6992- new_format = boxes . format ,
6993- )
6994- assert (
6995- reconverted_bbox == boxes
6996- ). all (), f"Invalid reconversion : \n \t Got: { reconverted_bbox } \n \t From: { boxes } "
6975+ intermediate_format = tv_tensors . BoundingBoxFormat . XYXY
6976+
6977+ reconverted_bbox = F . convert_bounding_box_format (
6978+ tv_tensors . BoundingBoxes (
6979+ reconverted , format = intermediate_format , canvas_size = kp . canvas_size
6980+ ),
6981+ new_format = boxes . format ,
6982+ )
6983+ assert_equal ( reconverted_bbox , boxes , atol = 1e-5 , rtol = 0 )
0 commit comments