Georg commited on
Commit
dea278b
·
1 Parent(s): 96b4daf

Optimized Docker build to fix OOM errors

Browse files
Files changed (2) hide show
  1. app.py +5 -1
  2. estimator.py +1 -31
app.py CHANGED
@@ -11,12 +11,16 @@ import os
11
  from pathlib import Path
12
  from typing import Dict, List
13
 
 
 
 
 
14
  import cv2
15
  import gradio as gr
16
  import numpy as np
17
  import torch
18
 
19
- from estimator import generate_naive_mask
20
 
21
  _slimsam_model = None
22
  _slimsam_processor = None
 
11
  from pathlib import Path
12
  from typing import Dict, List
13
 
14
+ # Ensure OMP_NUM_THREADS is a valid integer to avoid libgomp warnings
15
+ if not os.environ.get("OMP_NUM_THREADS", "").isdigit():
16
+ os.environ["OMP_NUM_THREADS"] = "1"
17
+
18
  import cv2
19
  import gradio as gr
20
  import numpy as np
21
  import torch
22
 
23
+ from masks import generate_naive_mask
24
 
25
  _slimsam_model = None
26
  _slimsam_processor = None
estimator.py CHANGED
@@ -13,6 +13,7 @@ import numpy as np
13
  import torch
14
  import cv2
15
 
 
16
  logger = logging.getLogger(__name__)
17
 
18
  # Add FoundationPose to Python path
@@ -34,37 +35,6 @@ except ImportError as e:
34
  trimesh = None
35
 
36
 
37
- def generate_naive_mask(
38
- rgb_image: np.ndarray,
39
- min_percentage: float = 1.0,
40
- max_percentage: float = 90.0
41
- ) -> tuple[np.ndarray, np.ndarray, float, bool]:
42
- """Generate a naive foreground mask using brightness + Otsu thresholding.
43
-
44
- Returns:
45
- mask_bool: Boolean mask (H, W)
46
- debug_mask: uint8 mask for visualization (H, W)
47
- mask_percentage: % of pixels active in mask_bool
48
- fallback_full_image: True if the mask was replaced by full-image mask
49
- """
50
- gray = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2GRAY)
51
- _, mask = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
52
-
53
- kernel = np.ones((5, 5), np.uint8)
54
- mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel) # Fill holes
55
- mask = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel) # Remove noise
56
-
57
- debug_mask = mask.copy()
58
- mask_bool = mask.astype(bool)
59
- mask_percentage = (mask_bool.sum() / mask_bool.size) * 100
60
-
61
- fallback_full_image = False
62
- if mask_percentage < min_percentage or mask_percentage > max_percentage:
63
- fallback_full_image = True
64
- mask_bool = np.ones((rgb_image.shape[0], rgb_image.shape[1]), dtype=bool)
65
- debug_mask = np.ones((rgb_image.shape[0], rgb_image.shape[1]), dtype=np.uint8) * 255
66
-
67
- return mask_bool, debug_mask, mask_percentage, fallback_full_image
68
 
69
 
70
  class FoundationPoseEstimator:
 
13
  import torch
14
  import cv2
15
 
16
+ from masks import generate_naive_mask
17
  logger = logging.getLogger(__name__)
18
 
19
  # Add FoundationPose to Python path
 
35
  trimesh = None
36
 
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
 
40
  class FoundationPoseEstimator: