Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sam2 real time inference? #388

Open
Karmik25 opened this issue Oct 15, 2024 · 2 comments
Open

sam2 real time inference? #388

Karmik25 opened this issue Oct 15, 2024 · 2 comments

Comments

@Karmik25
Copy link

can someone explain to me how to use sam2 for real-time inference, such that the model can predict objects while my webcam is open.

@heyoeyo
Copy link

heyoeyo commented Oct 17, 2024

The existing code doesn't support live/streaming video. Instead you'd have to first record a video on webcam and then process that video using the existing video predictor and/or web demo. It is possible to handle streaming video by modifying the code. It's mostly a matter of re-implementing the existing frame loop outside of the sam2_video_predictor.py script, and handling the frame reading (e.g. from a webcam) in that new loop.

If you don't want to implement this manually, there is an existing repo that has done this:
https://github.com/Gy920/segment-anything-2-real-time
I also have a script that works with webcams (though it's worth noting the repo above has code much more similar to the original, in case that's important):
https://github.com/heyoeyo/muggled_sam?tab=readme-ov-file#run-video-or-webcam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants