@@ -38,16 +38,14 @@ def horizontal_flip_bounding_box(
3838
3939 # TODO: Investigate if it makes sense from a performance perspective to have an implementation for every
4040 # BoundingBoxFormat instead of converting back and forth
41- bounding_box = (
42- bounding_box .clone ()
43- if format == features .BoundingBoxFormat .XYXY
44- else convert_format_bounding_box (bounding_box , old_format = format , new_format = features .BoundingBoxFormat .XYXY )
41+ bounding_box = convert_format_bounding_box (
42+ bounding_box .clone (), old_format = format , new_format = features .BoundingBoxFormat .XYXY , inplace = True
4543 ).reshape (- 1 , 4 )
4644
4745 bounding_box [:, [0 , 2 ]] = spatial_size [1 ] - bounding_box [:, [2 , 0 ]]
4846
4947 return convert_format_bounding_box (
50- bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format
48+ bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
5149 ).reshape (shape )
5250
5351
@@ -79,16 +77,14 @@ def vertical_flip_bounding_box(
7977
8078 # TODO: Investigate if it makes sense from a performance perspective to have an implementation for every
8179 # BoundingBoxFormat instead of converting back and forth
82- bounding_box = (
83- bounding_box .clone ()
84- if format == features .BoundingBoxFormat .XYXY
85- else convert_format_bounding_box (bounding_box , old_format = format , new_format = features .BoundingBoxFormat .XYXY )
80+ bounding_box = convert_format_bounding_box (
81+ bounding_box .clone (), old_format = format , new_format = features .BoundingBoxFormat .XYXY , inplace = True
8682 ).reshape (- 1 , 4 )
8783
8884 bounding_box [:, [1 , 3 ]] = spatial_size [0 ] - bounding_box [:, [3 , 1 ]]
8985
9086 return convert_format_bounding_box (
91- bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format
87+ bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
9288 ).reshape (shape )
9389
9490
@@ -412,7 +408,7 @@ def affine_bounding_box(
412408 # out_bboxes should be of shape [N boxes, 4]
413409
414410 return convert_format_bounding_box (
415- out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format
411+ out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
416412 ).reshape (original_shape )
417413
418414
@@ -594,9 +590,9 @@ def rotate_bounding_box(
594590 )
595591
596592 return (
597- convert_format_bounding_box (out_bboxes , old_format = features . BoundingBoxFormat . XYXY , new_format = format ). reshape (
598- original_shape
599- ),
593+ convert_format_bounding_box (
594+ out_bboxes , old_format = features . BoundingBoxFormat . XYXY , new_format = format , inplace = True
595+ ). reshape ( original_shape ) ,
600596 spatial_size ,
601597 )
602598
@@ -815,18 +811,18 @@ def crop_bounding_box(
815811) -> Tuple [torch .Tensor , Tuple [int , int ]]:
816812 # TODO: Investigate if it makes sense from a performance perspective to have an implementation for every
817813 # BoundingBoxFormat instead of converting back and forth
818- bounding_box = (
819- bounding_box .clone ()
820- if format == features .BoundingBoxFormat .XYXY
821- else convert_format_bounding_box (bounding_box , old_format = format , new_format = features .BoundingBoxFormat .XYXY )
814+ bounding_box = convert_format_bounding_box (
815+ bounding_box .clone (), old_format = format , new_format = features .BoundingBoxFormat .XYXY , inplace = True
822816 )
823817
824818 # Crop or implicit pad if left and/or top have negative values:
825819 bounding_box [..., 0 ::2 ] -= left
826820 bounding_box [..., 1 ::2 ] -= top
827821
828822 return (
829- convert_format_bounding_box (bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format ),
823+ convert_format_bounding_box (
824+ bounding_box , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
825+ ),
830826 (height , width ),
831827 )
832828
@@ -964,7 +960,7 @@ def perspective_bounding_box(
964960 # out_bboxes should be of shape [N boxes, 4]
965961
966962 return convert_format_bounding_box (
967- out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format
963+ out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
968964 ).reshape (original_shape )
969965
970966
@@ -1085,7 +1081,7 @@ def elastic_bounding_box(
10851081 out_bboxes = torch .cat ([out_bbox_mins , out_bbox_maxs ], dim = 1 ).to (bounding_box .dtype )
10861082
10871083 return convert_format_bounding_box (
1088- out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format
1084+ out_bboxes , old_format = features .BoundingBoxFormat .XYXY , new_format = format , inplace = True
10891085 ).reshape (original_shape )
10901086
10911087
0 commit comments