Spaces:
Runtime error
Runtime error
Anigor66
commited on
Commit
·
a513848
1
Parent(s):
2b2d916
Optimized
Browse files
app.py
CHANGED
|
@@ -427,6 +427,16 @@ def generate_auto_masks(image, request_json):
|
|
| 427 |
# Convert PIL to numpy
|
| 428 |
image_array = np.array(image)
|
| 429 |
H, W = image_array.shape[:2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 430 |
|
| 431 |
print(f"Generating automatic masks for image of size {W}x{H}...")
|
| 432 |
|
|
|
|
| 427 |
# Convert PIL to numpy
|
| 428 |
image_array = np.array(image)
|
| 429 |
H, W = image_array.shape[:2]
|
| 430 |
+
|
| 431 |
+
# Optional downscaling to keep masks smaller / faster
|
| 432 |
+
resize_longest = int(params.get("resize_longest", 0) or 0)
|
| 433 |
+
if resize_longest > 0 and max(H, W) > resize_longest:
|
| 434 |
+
scale = resize_longest / float(max(H, W))
|
| 435 |
+
new_w = max(1, int(W * scale))
|
| 436 |
+
new_h = max(1, int(H * scale))
|
| 437 |
+
print(f"Resizing image from {W}x{H} to {new_w}x{new_h} for auto masks...")
|
| 438 |
+
image_array = np.array(Image.fromarray(image_array).resize((new_w, new_h)))
|
| 439 |
+
H, W = image_array.shape[:2]
|
| 440 |
|
| 441 |
print(f"Generating automatic masks for image of size {W}x{H}...")
|
| 442 |
|