@@ -163,15 +163,20 @@ def vertical_flip_bounding_boxes(
163163 bounding_boxes [:, 1 ].sub_ (canvas_size [0 ]).neg_ ()
164164 elif format == tv_tensors .BoundingBoxFormat .XYXYXYXY :
165165 bounding_boxes [:, 1 ::2 ].sub_ (canvas_size [0 ]).neg_ ()
166- bounding_boxes = bounding_boxes [:, [0 , 1 , 6 , 7 , 4 , 5 , 2 , 3 ]]
166+ bounding_boxes = bounding_boxes [:, [2 , 3 , 0 , 1 , 6 , 7 , 4 , 5 ]]
167167 elif format == tv_tensors .BoundingBoxFormat .XYWHR :
168- bounding_boxes [:, 1 ].sub_ (canvas_size [0 ]).neg_ ()
169- bounding_boxes = bounding_boxes [:, [0 , 1 , 3 , 2 , 4 ]]
170- bounding_boxes [:, - 1 ].sub_ (90 ).neg_ ()
168+ dtype = bounding_boxes .dtype
169+ if not torch .is_floating_point (bounding_boxes ):
170+ # Casting to float to support cos and sin computations.
171+ bounding_boxes = bounding_boxes .to (torch .float64 )
172+ angle_rad = bounding_boxes [:, 4 ].mul (torch .pi ).div (180 )
173+ bounding_boxes [:, 1 ].sub_ (bounding_boxes [:, 2 ].mul (angle_rad .sin ())).sub_ (canvas_size [0 ]).neg_ ()
174+ bounding_boxes [:, 0 ].add_ (bounding_boxes [:, 2 ].mul (angle_rad .cos ()))
175+ bounding_boxes [:, 4 ].neg_ ().add_ (180 )
176+ bounding_boxes = bounding_boxes .to (dtype )
171177 else : # format == tv_tensors.BoundingBoxFormat.CXCYWHR:
172178 bounding_boxes [:, 1 ].sub_ (canvas_size [0 ]).neg_ ()
173- bounding_boxes = bounding_boxes [:, [0 , 1 , 3 , 2 , 4 ]]
174- bounding_boxes [:, - 1 ].sub_ (90 ).neg_ ()
179+ bounding_boxes [:, 4 ].neg_ ().add_ (180 )
175180
176181 return bounding_boxes .reshape (shape )
177182
0 commit comments