Skip to content

Commit 89b851e

Browse files
shapovalovfacebook-github-bot
authored andcommitted
Refactor a utility function for bbox conversion
Summary: This function makes it easier to extend FrameData class with new channels; brushing it up a bit. Reviewed By: bottler Differential Revision: D67816470 fbshipit-source-id: 6575415c864d0f539e283889760cd2331bf226a7
1 parent 5247f6a commit 89b851e

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pytorch3d/implicitron/dataset/utils.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,15 @@ def clamp_box_to_image_bounds_and_round(
134134
def bbox_xyxy_to_xywh(xyxy: T) -> T:
135135
wh = xyxy[2:] - xyxy[:2]
136136
xywh = torch.cat([xyxy[:2], wh])
137-
return xywh # pyre-ignore
137+
return xywh # pyre-ignore[7]
138+
139+
140+
def bbox_xywh_to_xyxy(xywh: T, clamp_size: float | int | None = None) -> T:
141+
wh = xywh[2:]
142+
if clamp_size is not None:
143+
wh = wh.clamp(min=clamp_size)
144+
xyxy = torch.cat([xywh[:2], xywh[:2] + wh])
145+
return xyxy # pyre-ignore[7]
138146

139147

140148
def get_clamp_bbox(
@@ -180,16 +188,6 @@ def rescale_bbox(
180188
return bbox * rel_size
181189

182190

183-
def bbox_xywh_to_xyxy(
184-
xywh: torch.Tensor, clamp_size: Optional[int] = None
185-
) -> torch.Tensor:
186-
xyxy = xywh.clone()
187-
if clamp_size is not None:
188-
xyxy[2:] = torch.clamp(xyxy[2:], clamp_size)
189-
xyxy[2:] += xyxy[:2]
190-
return xyxy
191-
192-
193191
def get_1d_bounds(arr: np.ndarray) -> Tuple[int, int]:
194192
nz = np.flatnonzero(arr)
195193
return nz[0], nz[-1] + 1

0 commit comments

Comments
 (0)