A simple labeling tool to help annotate frames in video data for segmentation tasks.
It is based on SAM2 model: the user is prompted to sparsly annotate a set of randomly selected images, and this annotation is propagate through the dataset, using SAM2.

This repository provides a semi-automatic labeling pipeline for video and image datasets using the SAM2 segmentation model. It enables users to:
- Split videos into frames
- Annotate images interactively with foreground/background points
- Generate segmentation masks using SAM2
- Export datasets in LabelMe format for downstream tasks
- Interactive annotation: Collect object/background points via mouse clicks
- Batch processing: Split videos and label images in bulk
- Automatic mask generation: Use SAM2 to create segmentation masks
- LabelMe export: Convert masks and annotations to LabelMe JSON format
-
Clone and install SAM2 dependencies
git clone https://github.com/facebookresearch/sam2.git && cd sam2 pip install -e .
-
Clone the repository:
git clone https://github.com/Oassal/SAM2-Labeling-tool.git
-
Install dependencies (recommended: use Anaconda):
conda create -n SAM2 python=3.10 conda activate SAM2 pip install -r requirements.txt
- Required packages: numpy, matplotlib, opencv-python, Pillow, torch
- You also need the SAM2 model weights and config files (see below)
Run the main pipeline with your video directory:
python main.py --video_dir "path/to/videos" --frames_per_split 100 --objects_names object1 object2 object3 ...--frames_per_splitis the sampling value for each sequence, this value depends on the used GPU- This will split each video into folders of frames.
The script will prompt you to annotate selected images in each split folder. Use mouse clicks:
- Left click: Add object point
- Right click: Add background point
- Press 'n': Set current points as default for the object
- Press 'd': Clear all points
- Press 'enter': Save and close annotation
After annotation, the pipeline will automatically generate segmentation masks using SAM2 for each split folder.
Add the --labelme flag to export the dataset in LabelMe format:
python main.py --video_dir "C:\path\to\videos" --frames_per_split 100 --objects_names object1 object2 object3 ... --labelmemain.py: Main pipeline scriptutils_labeling.py: Annotation and mask generation utilitieslabelme_utils.py/labelme_dataset.py: LabelMe export utilitiesutils_folders.py: Folder management utilitiessam.py: SAM2 mask generation logic
- Place your SAM2 model weights and config files in the project directory:
sam2_hiera_large.ptsam2_hiera_l.yaml
- Place your videos in a folder
- Run the main script with appropriate arguments
- Annotate images as prompted
- Masks and LabelMe datasets will be generated in each split folder
- Possibility of using other models
- Possibility of continuing labeling where you left off ...
MIT License