This commit is contained in:
2025-07-26 15:29:37 -07:00
parent 884cb8dce2
commit 4d1361df46
2 changed files with 71 additions and 2 deletions

View File

@@ -49,8 +49,8 @@ class SAM2VideoMatting:
def _load_model(self, model_cfg: str, checkpoint_path: str):
"""Load SAM2 video predictor lazily"""
if self._model_loaded:
return # Already loaded
if self._model_loaded and self.predictor is not None:
return # Already loaded and predictor exists
try:
# Import heavy SAM2 modules only when needed
@@ -419,6 +419,9 @@ class SAM2VideoMatting:
finally:
self.predictor = None
# Reset model loaded state for fresh reload
self._model_loaded = False
# Force garbage collection (critical for memory leak prevention)
gc.collect()