Spaces:
Sleeping
Sleeping
Georg
commited on
Commit
·
53bf9ae
1
Parent(s):
3f8ed1c
Optimized Docker build to fix OOM errors
Browse files
deploy.sh
CHANGED
|
@@ -64,7 +64,7 @@ fi
|
|
| 64 |
# Check if there are changes to commit
|
| 65 |
if [[ -n $(git status -s) ]]; then
|
| 66 |
echo "Committing changes..."
|
| 67 |
-
git add Dockerfile Dockerfile.base requirements.txt deploy.sh app.py client.py estimator.py
|
| 68 |
git commit -m "Optimized Docker build to fix OOM errors"
|
| 69 |
echo "✓ Changes committed"
|
| 70 |
else
|
|
|
|
| 64 |
# Check if there are changes to commit
|
| 65 |
if [[ -n $(git status -s) ]]; then
|
| 66 |
echo "Committing changes..."
|
| 67 |
+
git add Dockerfile Dockerfile.base requirements.txt deploy.sh app.py client.py estimator.py masks.py
|
| 68 |
git commit -m "Optimized Docker build to fix OOM errors"
|
| 69 |
echo "✓ Changes committed"
|
| 70 |
else
|
masks.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Tuple
|
| 2 |
+
|
| 3 |
+
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def generate_naive_mask(
|
| 8 |
+
rgb_image: np.ndarray,
|
| 9 |
+
min_percentage: float = 1.0,
|
| 10 |
+
max_percentage: float = 90.0
|
| 11 |
+
) -> Tuple[np.ndarray, np.ndarray, float, bool]:
|
| 12 |
+
"""Generate a naive foreground mask using brightness + Otsu thresholding.
|
| 13 |
+
|
| 14 |
+
Returns:
|
| 15 |
+
mask_bool: Boolean mask (H, W)
|
| 16 |
+
debug_mask: uint8 mask for visualization (H, W)
|
| 17 |
+
mask_percentage: % of pixels active in mask_bool
|
| 18 |
+
fallback_full_image: True if the mask was replaced by full-image mask
|
| 19 |
+
"""
|
| 20 |
+
gray = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2GRAY)
|
| 21 |
+
_, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
|
| 22 |
+
|
| 23 |
+
kernel = np.ones((5, 5), np.uint8)
|
| 24 |
+
mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) # Fill holes
|
| 25 |
+
mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) # Remove noise
|
| 26 |
+
|
| 27 |
+
debug_mask = mask.copy()
|
| 28 |
+
mask_bool = mask.astype(bool)
|
| 29 |
+
mask_percentage = (mask_bool.sum() / mask_bool.size) * 100
|
| 30 |
+
|
| 31 |
+
fallback_full_image = False
|
| 32 |
+
if mask_percentage < min_percentage or mask_percentage > max_percentage:
|
| 33 |
+
fallback_full_image = True
|
| 34 |
+
mask_bool = np.ones((rgb_image.shape[0], rgb_image.shape[1]), dtype=bool)
|
| 35 |
+
debug_mask = np.ones((rgb_image.shape[0], rgb_image.shape[1]), dtype=np.uint8) * 255
|
| 36 |
+
|
| 37 |
+
return mask_bool, debug_mask, mask_percentage, fallback_full_image
|