Spaces:
Runtime error
Runtime error
Update mplug_docowl/conversation.py
Browse filesremove image resize during pre-process
- mplug_docowl/conversation.py +15 -13
mplug_docowl/conversation.py
CHANGED
|
@@ -144,22 +144,24 @@ class Conversation:
|
|
| 144 |
image = expand2square(image)
|
| 145 |
elif image_process_mode in ["Default", "Crop"]:
|
| 146 |
pass
|
| 147 |
-
elif image_process_mode == "
|
| 148 |
image = image.resize((336, 336))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
else:
|
| 150 |
raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
|
| 151 |
-
|
| 152 |
-
aspect_ratio = max_hw / min_hw
|
| 153 |
-
max_len, min_len = 800, 400
|
| 154 |
-
shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
|
| 155 |
-
longest_edge = int(shortest_edge * aspect_ratio)
|
| 156 |
-
W, H = image.size
|
| 157 |
-
if longest_edge != max(image.size):
|
| 158 |
-
if H > W:
|
| 159 |
-
H, W = longest_edge, shortest_edge
|
| 160 |
-
else:
|
| 161 |
-
H, W = shortest_edge, longest_edge
|
| 162 |
-
image = image.resize((W, H))
|
| 163 |
if return_pil:
|
| 164 |
images.append(image)
|
| 165 |
else:
|
|
|
|
| 144 |
image = expand2square(image)
|
| 145 |
elif image_process_mode in ["Default", "Crop"]:
|
| 146 |
pass
|
| 147 |
+
elif image_process_mode == "Resize336":
|
| 148 |
image = image.resize((336, 336))
|
| 149 |
+
elif image_process_mode == "Resize":
|
| 150 |
+
max_hw, min_hw = max(image.size), min(image.size)
|
| 151 |
+
aspect_ratio = max_hw / min_hw
|
| 152 |
+
max_len, min_len = 800, 400
|
| 153 |
+
shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw))
|
| 154 |
+
longest_edge = int(shortest_edge * aspect_ratio)
|
| 155 |
+
W, H = image.size
|
| 156 |
+
if longest_edge != max(image.size):
|
| 157 |
+
if H > W:
|
| 158 |
+
H, W = longest_edge, shortest_edge
|
| 159 |
+
else:
|
| 160 |
+
H, W = shortest_edge, longest_edge
|
| 161 |
+
image = image.resize((W, H))
|
| 162 |
else:
|
| 163 |
raise ValueError(f"Invalid image_process_mode: {image_process_mode}")
|
| 164 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
if return_pil:
|
| 166 |
images.append(image)
|
| 167 |
else:
|