((exclusive)) - Camshowrecordings/model/sam_samantha/5

# ------------------------------------------------------------------ # 4️⃣ Pre‑process a single frame (example uses OpenCV) # ------------------------------------------------------------------ def preprocess(img: np.ndarray, cfg) -> torch.Tensor: # Resize while keeping aspect ratio (optional) target_sz = cfg["model"]["image_size"] img_resized = cv2.resize(img, (target_sz, target_sz))

python video_segment.py recordings/2024-03-15.mp4 recordings/2024-03-15_segmented.mp4 --stride 3 Adjust stride to balance speed vs. temporal resolution. | Symptom | Likely Cause | Fix | |---------|--------------|-----| | RuntimeError: CUDA out of memory | Batch size > 1 or image size too large for GPU. | Reduce stride , lower image_size in config.yaml , or switch to CPU ( device: cpu ). | | FileNotFoundError on model.ckpt | Wrong relative path or missing checkpoint. | Verify the file exists in camshowrecordings/model/sam_samantha/5/ . If you cloned a shallow repo, run git lfs pull . | | ImportError: cannot import name 'SamSamantha' | Model class location changed. | Look inside the repo’s camshowrecordings/models/ folder for the exact class name; update the import accordingly. | | torch.cuda.is_available() == False even though GPU is present | Missing or mismatched CUDA toolkit / driver. | Install the correct NVIDIA driver + matching CUDA version, then reinstall PyTorch with the appropriate --index-url flag. | | Segmentation masks are all black | Model not switched to evaluation mode or preprocessing mismatch. | Ensure

Open config.yaml to verify things like:

frame_idx += 1

python run_inference.py path/to/your/frame.jpg If you have a GPU, make sure torch.cuda.is_available() returns True . The script will automatically use the device defined in config.yaml . 7️⃣ Using the Model on a Whole Video Below is a compact example that reads a video file, runs the model on every N ‑th frame, and writes an output video with the segmentation overlay. camshowrecordings/model/sam_samantha/5

def process_video(in_path: Path, out_path: Path, stride: int = 5): cap = cv2.VideoCapture(str(in_path)) if not cap.isOpened(): raise RuntimeError(f"Cannot open in_path")

if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("input_video", type=Path) parser.add_argument("output_video", type=Path) parser.add_argument("--stride", type=int, default=5, help="Run inference every N frames (default=5)") args = parser.parse_args() process_video(args.input_video, args.output_video, args.stride) | Reduce stride , lower image_size in config

cd model/sam_samantha/5 ls -l Typical files you’ll see: