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

[Question] Calculation about shortest_edge #1413

Open
JJJYmmm opened this issue Apr 17, 2024 · 0 comments
Open

[Question] Calculation about shortest_edge #1413

JJJYmmm opened this issue Apr 17, 2024 · 0 comments

Comments

@JJJYmmm
Copy link

JJJYmmm commented Apr 17, 2024

Question

In llava/conversation.py, to limit image's size, shortest_edge is determined by int(min(max_len / aspect_ratio, min_len, min_hw))

LLaVA/llava/conversation.py

Lines 133 to 143 in 4e2277a

if max(image.size) > max_len:
max_hw, min_hw = max(image.size), min(image.size)
aspect_ratio = max_hw / min_hw
shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
longest_edge = int(shortest_edge * aspect_ratio)
W, H = image.size
if H > W:
H, W = longest_edge, shortest_edge
else:
H, W = shortest_edge, longest_edge
image = image.resize((W, H))

① If max(image.size) > max_len, max_len / aspect_ratio is always smaller than min_hw, so shortest_edge can be simplified to int(min(max_len / aspect_ratio, min_len)

max(image.size) > max_len ⇒ max_hw > max_len ⇒ max_hw / min_hw > max_len / min_hw ⇒ min_hw >max_len / aspect_ratio

② I'm also confused about min_len, in int(min(max_len / aspect_ratio, min_len), the constraint about max_len is larger than min_len(the shortest_edge can be smaller than min_len). The only thing min_len does is to resize image smaller when max_len / aspect_ratio > min_len

I think shortest_edge = int(max_len / aspect_ratio) is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant