Skip to content

Make image predictor thread-safe#643

Open
adamp87 wants to merge 1 commit intofacebookresearch:mainfrom
adamp87:stateless-img
Open

Make image predictor thread-safe#643
adamp87 wants to merge 1 commit intofacebookresearch:mainfrom
adamp87:stateless-img

Conversation

@adamp87
Copy link

@adamp87 adamp87 commented May 6, 2025

  • Problem: SAM2ImagePredictor is not thread-safe as it stores state variables after set_image() or set_image_batch(). This can be cumbersome to handle in a multi-threaded environment e.g. Web App.
  • Solution: return object by set_image(), which holds "state" variables. Pass returned object to predicts(). This makes predictor stateless.
  • Backward compatibility: store last computed object of set_image() in SAM2ImagePredictor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants