中文 | English
An intelligent image segmentation annotation tool powered by Meta SAM2 (Segment Anything Model 2). Click to segment, zero-shot annotation of any object.
- Click Segmentation -- Left-click on a target area, SAM2 automatically generates segmentation boundaries
- Box Segmentation -- Drag a rectangle to trigger segmentation
- Polygon Drawing -- Click continuously to manually annotate complex boundaries, right-click to close
- Real-time annotation list with select, delete, and visibility toggle
- Add custom text descriptions to each annotation
- 12 preset categories with hierarchical classification (animals/vehicles/buildings, etc.)
- Drag vertices to fine-tune boundaries, right-click menu to insert/delete vertices
- Built-in quality scoring system: comprehensive score, boundary smoothness, vertex density
- SAM2 confidence automatically recorded (average >94%)
- Configurable vertex density (low/medium/high)
- COCO JSON -- Universal object detection/segmentation training
- Pascal VOC XML -- Traditional CV task compatibility
- Exports include quality metrics and confidence extension fields
| Component | Minimum | Recommended |
|---|---|---|
| Python | 3.10+ | 3.12+ |
| Memory | 8 GB | 16 GB+ |
| GPU | None (CPU works) | NVIDIA 8 GB+ |
# Clone the repository
git clone https://github.com/YOUR_USERNAME/SAM2-Annotation-Tool.git
cd SAM2-Annotation-Tool
# Create a virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txtEdit config.yaml to set the SAM2 model path:
model:
path: "models/sam2_hiera_tiny.pt"
config_path: "models/sam2_hiera_t.yaml"
device: "cuda" # use "cpu" if no GPUDownload model weights from the SAM2 official repository.
python main.pyOpen image folder -> Select tool -> Click/box target -> SAM2 auto-segment
|
Export COCO/VOC <- Confirm annotation (add text) <- Fine-tune boundary (drag vertices)
Keyboard Shortcuts
Ctrl+OOpen folderCtrl+SSave projectDeleteDelete selected annotation- Mouse wheel Zoom canvas
+---------------------------------------------+
| UI Layer (PyQt6) |
| ImageList | CanvasWidget | LayerList |
+---------------------------------------------+
| Business Logic Layer |
| MainWindow | ImageManager | ProjectManager|
+---------------------------------------------+
| Core Engine Layer |
| SAM2Engine |
| (PyTorch + SAM2 + OpenCV) |
+---------------------------------------------+
| Data Layer |
| Annotation | COCOExporter | VOCExporter |
+---------------------------------------------+
SAM2-Annotation-Tool/
+-- main.py # Application entry point
+-- config.yaml # Configuration
+-- requirements.txt # Dependencies
+-- src/
| +-- core/
| | +-- sam2_engine.py # SAM2 segmentation engine
| | +-- annotation_data.py # Data models
| | +-- image_manager.py # Image management
| | +-- project_manager.py # Project management
| +-- gui/
| | +-- main_window.py # Main window
| | +-- canvas_widget.py # Canvas widget
| | +-- layer_list.py # Annotation panel
| | +-- image_list.py # Image list
| | +-- tool_bar.py # Toolbar
| +-- exporters/
| | +-- coco_exporter.py # COCO export
| | +-- voc_exporter.py # VOC export
| +-- utils/
| +-- config_loader.py # Config loader
| +-- file_utils.py # File utilities
| +-- image_utils.py # Image utilities
+-- tests/
+-- docs/
The tool computes a quality score for each annotation:
quality_score = 0.5 * confidence + 0.3 * density_score + 0.2 * smoothness
| Metric | Range | Description |
|---|---|---|
| quality_score | 0--1 | Comprehensive quality score |
| boundary_smoothness | 0--1 | Boundary smoothness |
| vertex_count | int | Number of polygon vertices |
| vertex_density | 0--20 | Vertex density (per 100px perimeter) |
| confidence | 0--1 | SAM2 model confidence |
| Feature | SAM2 Annotation Tool | LabelImg | LabelMe | CVAT |
|---|---|---|---|---|
| Smart segmentation | SAM2-driven | Manual | Manual | Requires config |
| Zero-shot | Yes | No | No | No |
| Quality metrics | Built-in | None | None | Basic |
| Vertex density | Configurable | No | No | No |
| Local execution | Yes | Yes | Yes | Requires deploy |
| Learning curve | Low | Low | Medium | High |
- PyQt6 >= 6.0.0
- PyTorch >= 2.0.0
- SAM2 >= 0.4.0
- OpenCV >= 4.8.0
- Pillow >= 10.0.0
- NumPy >= 1.24.0
- PyYAML >= 6.0
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
MIT License -- see LICENSE for details.