Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tensor in window_reverse to avoid precision issue #617

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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