Skip to content

Commit

Permalink
Use tensor in window_reverse to avoid precision issue (#617)
Browse files Browse the repository at this point in the history
暂时避免触发 scale OP,将 `window_size` 转为 Tensor 以触发
  • Loading branch information
SigureMo authored Jul 23, 2024
1 parent 4377aa3 commit 106cbba
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion deploy/groundingdino/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def plot_boxes_to_image(image_pil, tgt):
# draw boxes and masks
for box, label in zip(boxes, labels):
# from 0..1 to 0..W, 0..H
box = box * paddle.to_tensor([W, H, W, H])
box = box * paddle.to_tensor([W, H, W, H]).astype(paddle.float32)
# from xywh to xyxy
box[:2] -= box[2:] / 2
box[2:] += box[:2]
Expand Down
2 changes: 1 addition & 1 deletion paddlemix/examples/groundingdino/run_predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def plot_boxes_to_image(image_pil, tgt):
# draw boxes and masks
for box, label in zip(boxes, labels):
# from 0..1 to 0..W, 0..H
box = box * paddle.to_tensor([W, H, W, H])
box = box * paddle.to_tensor([W, H, W, H]).astype(paddle.float32)
# from xywh to xyxy
box[:2] -= box[2:] / 2
box[2:] += box[:2]
Expand Down
2 changes: 1 addition & 1 deletion paddlemix/models/audioldm2/clap_module/htsat_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def window_reverse(windows, window_size, H, W):
Returns:
x: (B, H, W, C)
"""
B = int(windows.shape[0] / (H * W / window_size / window_size))
B = int(windows.shape[0] / (H * W / paddle.to_tensor(window_size * window_size)))
x = windows.reshape([B, H // window_size, W // window_size, window_size, window_size, -1])
x = x.transpose([0, 1, 3, 2, 4, 5]).reshape([B, H, W, -1])
return x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def window_reverse(windows, window_size, H, W):
Returns:
x: (B, H, W, C)
"""
B = int(windows.shape[0] / (H * W / window_size / window_size))
B = int(windows.shape[0] / (H * W / paddle.to_tensor(window_size * window_size)))
x = windows.reshape([B, H // window_size, W // window_size, window_size, window_size, -1])
x = x.transpose([0, 1, 3, 2, 4, 5]).reshape([B, H, W, -1])
return x
Expand Down

0 comments on commit 106cbba

Please sign in to comment.