Update preprocessor.py
Browse files- preprocessor.py +8 -7
preprocessor.py
CHANGED
|
@@ -241,20 +241,21 @@ def resize_longside(
|
|
| 241 |
|
| 242 |
|
| 243 |
def select_best_resolution(original_size: tuple, possible_resolutions: list) -> tuple:
|
| 244 |
-
"""
|
| 245 |
Selects the best-fit resolution from a list of possible resolutions based on the original image size.
|
| 246 |
-
|
| 247 |
-
This function, adapted from LLaVA-Next
|
| 248 |
-
(https://github.com/huggingface/transformers/blob/v4.40.2/src/transformers/models/llava_next/image_processing_llava_next.py),
|
| 249 |
-
evaluates each resolution by computing its effective and wasted area compared to the original size.
|
| 250 |
The optimal resolution is the one that maximizes the effective area while minimizing unused (wasted) space.
|
| 251 |
-
|
| 252 |
Args:
|
| 253 |
original_size (tuple): The original image size in the format (height, width).
|
| 254 |
possible_resolutions (list): A list of candidate resolutions in the format [(height1, width1), (height2, width2), ...].
|
| 255 |
-
|
| 256 |
Returns:
|
| 257 |
tuple: The best-fit resolution in the format (height, width).
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
"""
|
| 259 |
original_height, original_width = original_size
|
| 260 |
best_fit = None
|
|
|
|
| 241 |
|
| 242 |
|
| 243 |
def select_best_resolution(original_size: tuple, possible_resolutions: list) -> tuple:
|
| 244 |
+
"""
|
| 245 |
Selects the best-fit resolution from a list of possible resolutions based on the original image size.
|
| 246 |
+
This function evaluates each resolution by computing its effective and wasted area compared to the original size.
|
|
|
|
|
|
|
|
|
|
| 247 |
The optimal resolution is the one that maximizes the effective area while minimizing unused (wasted) space.
|
| 248 |
+
|
| 249 |
Args:
|
| 250 |
original_size (tuple): The original image size in the format (height, width).
|
| 251 |
possible_resolutions (list): A list of candidate resolutions in the format [(height1, width1), (height2, width2), ...].
|
| 252 |
+
|
| 253 |
Returns:
|
| 254 |
tuple: The best-fit resolution in the format (height, width).
|
| 255 |
+
|
| 256 |
+
This function includes code adapted from the file image_processing_llava_next.py in the LLaVA-Next
|
| 257 |
+
project(https://github.com/huggingface/transformers/blob/v4.40.2/src/transformers/models/llava_next/image_processing_llava_next.py),
|
| 258 |
+
which is licensed under apache-2.0.
|
| 259 |
"""
|
| 260 |
original_height, original_width = original_size
|
| 261 |
best_fit = None
|