This commit is contained in:
2025-07-27 09:57:42 -07:00
parent e38f63f539
commit a479d6a5f0

View File

@@ -28,25 +28,17 @@ class SAM2StreamingProcessor:
self.device = torch.device(config.get('hardware', {}).get('device', 'cuda')) self.device = torch.device(config.get('hardware', {}).get('device', 'cuda'))
# SAM2 model configuration # SAM2 model configuration
model_cfg_name = config.get('matting', {}).get('sam2_model_cfg', 'sam2.1_hiera_l') model_cfg = config.get('matting', {}).get('sam2_model_cfg', 'sam2.1_hiera_l')
checkpoint = config.get('matting', {}).get('sam2_checkpoint', checkpoint = config.get('matting', {}).get('sam2_checkpoint',
'segment-anything-2/checkpoints/sam2.1_hiera_large.pt') 'segment-anything-2/checkpoints/sam2.1_hiera_large.pt')
# Map config name to full path
config_mapping = {
'sam2.1_hiera_t': 'segment-anything-2/sam2/configs/sam2.1/sam2.1_hiera_t.yaml',
'sam2.1_hiera_s': 'segment-anything-2/sam2/configs/sam2.1/sam2.1_hiera_s.yaml',
'sam2.1_hiera_b+': 'segment-anything-2/sam2/configs/sam2.1/sam2.1_hiera_b+.yaml',
'sam2.1_hiera_l': 'segment-anything-2/sam2/configs/sam2.1/sam2.1_hiera_l.yaml',
}
model_cfg = config_mapping.get(model_cfg_name, model_cfg_name)
# Build predictor (simple, clean approach) # Build predictor (simple, clean approach)
# Note: SAM2 uses Hydra to find configs automatically in sam2/configs/
self.predictor = build_sam2_video_predictor( self.predictor = build_sam2_video_predictor(
model_cfg, model_cfg, # Just the config name, Hydra finds it automatically
checkpoint, checkpoint,
device=self.device device=self.device,
vos_optimized=True # Enable VOS optimizations for speed
) )
# Frame buffer for streaming (like det-sam2) # Frame buffer for streaming (like det-sam2)