Segment Anything 2 UI
February 22, 2025 ยท View on GitHub

Segment Anything 2 UI is a graphical user interface for video annotation, built using PySide6. It is inspired by Meta's demo web page and allows users to annotate videos with various tools such as bounding boxes, masks, and points. This tool currently supports video files and tif images for 3D segmentation.
This UI wraps the Segment Anything 2 model.
Please use this repository for image only annotation. Segment anything UI
Example output
https://github.com/user-attachments/assets/a7ac9558-e604-4c93-bf57-e6270ef0deb7
Features
- Video Playback: Play, pause, and navigate through video frames.
- Annotation Tools: Annotate videos using bounding boxes, masks, and points.
- Visualization Modes: Toggle between different visualization modes, including image and image with mask.
- Thumbnail Previews: Generate and display thumbnail previews for quick navigation.
- Configurable Settings: Customize settings through a dedicated settings widget.
- Save inference data: Save the inference data to a file using safetensors.
- Multi-object tracking: Track multiple objects in the video.
Installation
-
Clone the repository:
git clone https://github.com/yourusername/segment-anything-2-ui.git cd segment-anything-2-ui -
Install dependencies: Make sure you have Python 3.10+ installed. Then, install the required packages:
pip install -r requirements.txt -
Install SAM2: SAM 2 needs to be installed first before use. The code requires
python>=3.10, as well astorch>=2.5.1andtorchvision>=0.20.1. Please follow the instructions here to install both PyTorch and TorchVision dependencies. You can install SAM 2 on a GPU machine using:git clone https://github.com/facebookresearch/sam2.git && cd sam2 pip install -e .If you are installing on Windows, it's strongly recommended to use Windows Subsystem for Linux (WSL) with Ubuntu.
-
Download the SAM2 model checkpoint:
Use curl or wget to download the model checkpoint and place it in the checkpoints directory.
- ** Setup config.py file**:
- Modify accordingly segment_anything_2_ui/configs/config.py file.
Usage
-
Run the application:
export PYTHONPATH=$PYTHONPATH:. python segment_anything_2_ui/ui/sam2_main_window.pyset PYTHONPATH=$PYTHONPATH;. python segment_anything_2_ui/ui/sam2_main_window.py -
Load a video:
- Click on the "Load video" button in the settings widget to select a video file.
-
Annotate the video:
- Use the annotation tools provided in the settings widget to annotate the video frames.
-
Propagate the inference data:
- Use the "Propagate" button to propagate the inference data to the next frames.
- Use the "Propagate reverse" button to propagate the inference data to the previous frames.
-
Save the inference data:
- Use the "Save" button to save the inference data to a file using safetensors.
Contributing
Contributions are welcome!
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Acknowledgments
- Inspired by Meta's demo web page.
- Built with PySide6 for a seamless user interface experience.
- Segment Anything 2 model.
- Used for annotation of videos.