C/C++ inference for Meta's Segment Anything Model (SAM)
Top 31.8% on sourcepulse
This project provides a pure C/C++ implementation for Meta's Segment Anything Model (SAM), enabling efficient on-device inference without Python dependencies. It targets developers and researchers needing to integrate advanced image segmentation capabilities into C/C++ applications, offering a lightweight and performant solution.
How It Works
The project leverages the ggml
library for tensor computation, allowing SAM to run efficiently on CPUs. It converts the original PyTorch model checkpoints (.pth
) into a custom ggml
format (.bin
). The inference process involves loading the ggml
model, preprocessing the input image to the required 1024x1024 resolution, and then running the SAM model to generate segmentation masks.
Quick Start & Requirements
git clone --recursive https://github.com/YavorGIvanov/sam.cpp && cd sam.cpp
.pth
checkpoint, run python convert-pth-to-ggml.py <path_to_pth> <output_dir>
.mkdir build && cd build && cmake .. && make -j4
./bin/sam -t <threads> -i <image_path> -m <ggml_model_path>
Highlighted Details
ggml
for CPU-optimized inference.Maintenance & Community
The project is actively maintained by YavorGIvanov. Community interaction channels are not explicitly mentioned in the README.
Licensing & Compatibility
The project appears to be licensed under the MIT License, allowing for commercial use and integration into closed-source projects.
Limitations & Caveats
The project is still under active development, with several features listed as "Next steps" including GPU support, mask/box input, and further performance optimizations. Some output differences compared to the PyTorch implementation are noted.
1 year ago
1 day