Spaces:
Running
Running
תיקון שגיאה
Browse files- backend.py +20 -3
backend.py
CHANGED
@@ -8,7 +8,7 @@ import cv2
|
|
8 |
from PIL import Image, ImageFilter
|
9 |
from scipy.ndimage import binary_dilation
|
10 |
import hydra
|
11 |
-
from hydra import
|
12 |
from omegaconf import OmegaConf
|
13 |
|
14 |
# -----------------------------
|
@@ -287,10 +287,27 @@ def process_image(
|
|
287 |
women_boxes.append(bbox)
|
288 |
|
289 |
# 3) שלב SAM2 (עבור בוקסים של נשים)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
if sam2_predictor is None:
|
291 |
print("[process_image] SAM2 לא זמין/נטען. מחזירים תמונה ללא טשטוש.")
|
292 |
-
raise ValueError("SAM2 model is not loaded.")
|
293 |
-
return pil_image
|
294 |
|
295 |
progress_callback(0.6, f"מתחיל פילוח SAM2 על {len(women_boxes)} נשים...")
|
296 |
sam2_predictor.set_image(np.array(pil_image))
|
|
|
8 |
from PIL import Image, ImageFilter
|
9 |
from scipy.ndimage import binary_dilation
|
10 |
import hydra
|
11 |
+
from hydra import initialize_config_dir, compose
|
12 |
from omegaconf import OmegaConf
|
13 |
|
14 |
# -----------------------------
|
|
|
287 |
women_boxes.append(bbox)
|
288 |
|
289 |
# 3) שלב SAM2 (עבור בוקסים של נשים)
|
290 |
+
# אתחול Hydra בתוך הפונקציה
|
291 |
+
global sam2_predictor
|
292 |
+
if sam2_predictor is None:
|
293 |
+
try:
|
294 |
+
config_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), SAM2_CONFIG_PATH))
|
295 |
+
with initialize_config_dir(version_base=None, config_dir=config_dir):
|
296 |
+
cfg = compose(config_name="config") # "config" is the name of the config file, replace if necessary
|
297 |
+
sam2_predictor = SAM2ImagePredictor.from_pretrained(SAM2_MODEL_NAME, config=cfg)
|
298 |
+
sam2_predictor.model.to(device)
|
299 |
+
except Exception as e:
|
300 |
+
print(f"[SAM2] שגיאה בטעינת SAM2: {e}")
|
301 |
+
print(f" - סוג השגיאה: {type(e).__name__}")
|
302 |
+
print(f" - הודעת השגיאה: {e}")
|
303 |
+
import traceback
|
304 |
+
print(f" - Traceback:")
|
305 |
+
traceback.print_exc()
|
306 |
+
sam2_predictor = None
|
307 |
+
|
308 |
if sam2_predictor is None:
|
309 |
print("[process_image] SAM2 לא זמין/נטען. מחזירים תמונה ללא טשטוש.")
|
310 |
+
raise ValueError("SAM2 model is not loaded.")
|
|
|
311 |
|
312 |
progress_callback(0.6, f"מתחיל פילוח SAM2 על {len(women_boxes)} נשים...")
|
313 |
sam2_predictor.set_image(np.array(pil_image))
|