fix sam2 models
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import List, Dict, Any, Optional, Tuple
|
||||
import cv2
|
||||
from pathlib import Path
|
||||
import warnings
|
||||
import os
|
||||
|
||||
try:
|
||||
from sam2.build_sam import build_sam2_video_predictor
|
||||
@@ -38,6 +39,19 @@ class SAM2VideoMatting:
|
||||
def _load_model(self, model_cfg: str, checkpoint_path: str):
|
||||
"""Load SAM2 video predictor with optimizations"""
|
||||
try:
|
||||
# Check for checkpoint in models directory if not found
|
||||
if not Path(checkpoint_path).exists():
|
||||
models_path = Path("models") / checkpoint_path
|
||||
if models_path.exists():
|
||||
checkpoint_path = str(models_path)
|
||||
else:
|
||||
# Try relative to package
|
||||
import os
|
||||
package_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
models_path = Path(package_dir) / "models" / checkpoint_path
|
||||
if models_path.exists():
|
||||
checkpoint_path = str(models_path)
|
||||
|
||||
self.predictor = build_sam2_video_predictor(
|
||||
model_cfg,
|
||||
checkpoint_path,
|
||||
|
||||
Reference in New Issue
Block a user