MogensR commited on
Commit
161521f
·
1 Parent(s): 4f3935e

Update processing/video/video_processor.py

Browse files
Files changed (1) hide show
  1. processing/video/video_processor.py +21 -8
processing/video/video_processor.py CHANGED
@@ -53,13 +53,25 @@ def process_frame(self, frame: np.ndarray, background: np.ndarray) -> Dict[str,
53
  predictor = None
54
  try:
55
  sam2_model = self.models.get_sam2()
56
- # FIX: Check that predictor is not None, not just that attribute exists
57
- if sam2_model and sam2_model.loaded and sam2_model.predictor is not None:
58
- predictor = sam2_model.predictor
59
- else:
60
- self.log.warning("SAM2 predictor is None or not loaded")
 
 
 
 
 
 
 
 
 
 
 
 
61
  except Exception as e:
62
- self.log.warning(f"SAM2 predictor unavailable, using fallback: {e}")
63
 
64
  # 1) segment
65
  mask = segment_person_hq(frame, predictor, fallback_enabled=True)
@@ -68,10 +80,11 @@ def process_frame(self, frame: np.ndarray, background: np.ndarray) -> Dict[str,
68
  matanyone = None
69
  try:
70
  matanyone_model = self.models.get_matanyone()
71
- if matanyone_model and matanyone_model.loaded:
 
72
  matanyone = matanyone_model
73
  except Exception as e:
74
- self.log.warning(f"MatAnyone unavailable, using OpenCV refinement: {e}")
75
 
76
  mask_refined = refine_mask_hq(frame, mask, matanyone, fallback_enabled=True)
77
 
 
53
  predictor = None
54
  try:
55
  sam2_model = self.models.get_sam2()
56
+ # Check if we have a working SAM2 predictor
57
+ # SAM2ImagePredictor has set_image and predict methods
58
+ if sam2_model is not None:
59
+ # Check if it's wrapped (has .predictor attribute)
60
+ if hasattr(sam2_model, 'predictor'):
61
+ predictor = sam2_model.predictor
62
+ # Or if it IS the predictor (has set_image method)
63
+ elif hasattr(sam2_model, 'set_image'):
64
+ predictor = sam2_model
65
+ # Or if it's a dict with model and processor (from transformers)
66
+ elif isinstance(sam2_model, dict) and 'model' in sam2_model:
67
+ # For now, we can't use this format easily
68
+ self.log.warning("SAM2 loaded as dict format, not directly usable")
69
+ predictor = None
70
+
71
+ if predictor is None:
72
+ self.log.debug("SAM2 predictor not available, will use fallback")
73
  except Exception as e:
74
+ self.log.warning(f"SAM2 predictor unavailable: {e}")
75
 
76
  # 1) segment
77
  mask = segment_person_hq(frame, predictor, fallback_enabled=True)
 
80
  matanyone = None
81
  try:
82
  matanyone_model = self.models.get_matanyone()
83
+ # Just check if we have a MatAnyone model at all
84
+ if matanyone_model is not None:
85
  matanyone = matanyone_model
86
  except Exception as e:
87
+ self.log.warning(f"MatAnyone unavailable: {e}")
88
 
89
  mask_refined = refine_mask_hq(frame, mask, matanyone, fallback_enabled=True)
90