Skip to content

Commit f57fc9d

Browse files
author
Zhitao Yu
committed
A correct solution compatible with the inplace parameter
1 parent 52896aa commit f57fc9d

File tree

1 file changed

+5
-1
lines changed
  • torchvision/transforms/v2/functional

1 file changed

+5
-1
lines changed

torchvision/transforms/v2/functional/_meta.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ def _xyxy_to_xywh(xyxy: torch.Tensor, inplace: bool) -> torch.Tensor:
179179
def _cxcywh_to_xyxy(cxcywh: torch.Tensor, inplace: bool) -> torch.Tensor:
180180
# For integer tensors, use float arithmetic to match the behavior of
181181
# `torchvision.ops._box_convert._box_cxcywh_to_xyxy`.
182+
original = cxcywh
182183
dtype = cxcywh.dtype
183184
need_cast = not cxcywh.is_floating_point()
184-
# Float conversion creates a copy, so we only need to clone for floating point when not inplace
185+
185186
if need_cast:
186187
cxcywh = cxcywh.float()
187188
elif not inplace:
@@ -195,6 +196,9 @@ def _cxcywh_to_xyxy(cxcywh: torch.Tensor, inplace: bool) -> torch.Tensor:
195196

196197
if need_cast:
197198
cxcywh = cxcywh.to(dtype)
199+
if inplace:
200+
original[:] = cxcywh
201+
return original
198202

199203
return cxcywh
200204

0 commit comments

Comments
 (0)