Skip to content

Commit 216bdb2

Browse files
committed
Make SkipFrames bbox tensors device-safe
Refactor bbox creation in `SkipFrames.__call__` to build tensors from `pose` (`new_zeros/new_tensor/new_ones`) so boxes and scores stay on the same device and dtype. The NaN handling for min/max coordinates is now explicit via `nan=` arguments, and bbox limiting uses `torch.clamp` with typed min/max tensors.
1 parent 5522254 commit 216bdb2

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

‎dlclive/pose_estimation_pytorch/runner.py‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,33 @@ def update(self, pose: torch.Tensor, w: int, h: int) -> None:
7272
num_det, num_kpts = pose.shape[:2]
7373
size = max(w, h)
7474

75-
bboxes = torch.zeros((num_det, 4))
76-
bboxes[:, :2] = torch.min(torch.nan_to_num(pose, size)[..., :2], dim=1)[0] - self.margin
77-
bboxes[:, 2:4] = torch.max(torch.nan_to_num(pose, 0)[..., :2], dim=1)[0] + self.margin
78-
bboxes = torch.clip(bboxes, min=torch.zeros(4), max=torch.tensor([w, h, w, h]))
79-
self._detections = dict(boxes=bboxes, scores=torch.ones(num_det))
75+
bboxes = pose.new_zeros((num_det, 4))
76+
77+
bboxes[:, :2] = (
78+
torch.min(
79+
torch.nan_to_num(pose[..., :2], nan=float(size)),
80+
dim=1,
81+
)[0]
82+
- self.margin
83+
)
84+
85+
bboxes[:, 2:4] = (
86+
torch.max(
87+
torch.nan_to_num(pose[..., :2], nan=0.0),
88+
dim=1,
89+
)[0]
90+
+ self.margin
91+
)
92+
93+
minimum = pose.new_zeros(4)
94+
maximum = pose.new_tensor([w, h, w, h])
95+
96+
bboxes = torch.clamp(bboxes, min=minimum, max=maximum)
97+
98+
self._detections = {
99+
"boxes": bboxes,
100+
"scores": pose.new_ones(num_det),
101+
}
80102
self._age += 1
81103

82104

0 commit comments

Comments
 (0)