An interactive visualization tool for Facebook's Segment-Anything 2 (SAM2) model. This tool allows you to easily visualize and experiment with SAM2's segmentation capabilities through an intuitive user interface.
The service is divided into two parts:
- Backend: a Flask server that runs the SAM2 model
- Frontend: a React app that provides an interactive interface for image segmentation
- Interactive image selection and visualization
- Multiple annotation modes (box, positive points, negative points)
- Real-time segmentation preview
- Adjustable mask overlay
- Support for multiple images
Complete the Installation 🔧 first.
To start the backend, run the following command in the backend directory:
python server.py ../dataset/ ../sam2/checkpoints/sam2.1_hiera_large.pt
where ../dataset is the path to your images directory.
This will start the server at http://localhost:5000
To start the frontend, run the following command in the frontend directory:
yarn start
This will start the UI at http://localhost:3000/
In the interface, you can:
- Select an image from the dropdown
- Choose an annotation mode (box, positive points, negative points)
- Click and drag to create a bounding box or add points
- Click "Segment" to generate the mask
- Toggle mask visibility with the "Show Mask" switch
First, create a Python environment (conda recommended). Then follow these steps:
-
Install the Segment-Anything 2 (SAM2) repository as a submodule:
git submodule update --init --recursive -
Download the SAM2 model weights:
./download_sam_weights.sh -
Install the requirements:
pip install -r backend/requirements.txt
Follow these steps in the frontend directory:
