device = torch.device(cfg.get("device", "cpu")) model.to(device)

# ------------------------------------------------------------------ # 1️⃣ Helper: load configuration # ------------------------------------------------------------------ CONFIG_PATH = Path(__file__).parent / "model" / "sam_samantha" / "5" / "config.yaml" with open(CONFIG_PATH, "r") as f: cfg = yaml.safe_load(f)

if frame_idx % stride == 0: mask = infer(frame) # binary mask (0/255) overlay = cv2.addWeighted(frame, 0.7, cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR), 0.3, 0) out.write(overlay) else: out.write(frame) # write raw frame for non‑processed indices