CodeJackR
commited on
Commit
·
5407eec
1
Parent(s):
40b9d26
Manage image resizing
Browse files- handler.py +12 -0
handler.py
CHANGED
|
@@ -85,11 +85,23 @@ class EndpointHandler():
|
|
| 85 |
# Ensure the index is within bounds
|
| 86 |
best_mask_idx = min(best_mask_idx.item(), masks.shape[0] - 1)
|
| 87 |
best_mask = masks[best_mask_idx] # Shape: (H, W)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
else:
|
| 89 |
raise ValueError("No masks were generated")
|
| 90 |
|
| 91 |
# Convert to numpy and create binary mask
|
| 92 |
mask_binary = (best_mask > 0.0).cpu().numpy().astype(np.uint8) * 255
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
print("Error processing masks: {}".format(e))
|
|
|
|
| 85 |
# Ensure the index is within bounds
|
| 86 |
best_mask_idx = min(best_mask_idx.item(), masks.shape[0] - 1)
|
| 87 |
best_mask = masks[best_mask_idx] # Shape: (H, W)
|
| 88 |
+
|
| 89 |
+
# Ensure the mask is 2D by squeezing any extra dimensions
|
| 90 |
+
while best_mask.ndim > 2:
|
| 91 |
+
best_mask = best_mask.squeeze()
|
| 92 |
+
|
| 93 |
+
print("Final mask shape: {}".format(best_mask.shape))
|
| 94 |
else:
|
| 95 |
raise ValueError("No masks were generated")
|
| 96 |
|
| 97 |
# Convert to numpy and create binary mask
|
| 98 |
mask_binary = (best_mask > 0.0).cpu().numpy().astype(np.uint8) * 255
|
| 99 |
+
|
| 100 |
+
# Ensure mask_binary is 2D
|
| 101 |
+
if mask_binary.ndim > 2:
|
| 102 |
+
mask_binary = mask_binary.squeeze()
|
| 103 |
+
|
| 104 |
+
print("Final mask_binary shape: {}".format(mask_binary.shape))
|
| 105 |
|
| 106 |
except Exception as e:
|
| 107 |
print("Error processing masks: {}".format(e))
|