Skip to content

Commit 7883f84

Browse files
committed
fix(clip): 修改尺寸收缩算法以更好地维持宽高比
Signed-off-by: YdrMaster <[email protected]>
1 parent ab671b9 commit 7883f84

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

models/clip/common/src/image.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ fn find_best_resize(
240240
// 如果允许放大或需要缩小
241241
if allow_upscale || w * h > scale_resolution.pow(2) {
242242
// 保持宽高比缩放尺寸,使面积等于 `sr²`
243-
let r = (w as fdim / h as fdim).sqrt();
244-
w = (scale_resolution as fdim * r) as _;
245-
h = (scale_resolution as fdim / r) as _;
243+
let r = w as fdim / h as fdim;
244+
h = (scale_resolution as fdim / r.sqrt()) as _;
245+
w = (h as fdim * r) as _;
246246
}
247247
// 确保宽高整除图块尺寸
248248
[w, h].map(|l| div_round(l, patch_size) * patch_size)

0 commit comments

Comments
 (0)