Prototype based on Meta's Segment Anything Model implemented in pure C/C++ using GGML tensor library for machine learning.
The prototype currently supports only the ViT-B SAM model checkpoint.
- Complete SAM model conversion pipeline to GGML format
- Optimized C/C++ implementation for inference
- Support for positive and negative point prompts
- Cross-platform compatibility (Linux, Windows, macOS)
- Sample applications demonstrating real-world usage
- CMake >= 3.12
- C++14 compatible compiler
- GGML library
- OpenCV (for demo applications)
- Python 3.7+ (for conversion scripts and python demo app)
- PyTorch (for model conversion)
- Clone the repository:
git clone git@github.com:andriiryzhkov/ai_mask_prototype.git
cd ai_mask_prototype
git submodule update --init --recursive
- Create python virtual environment and install dependencies:
poetry install
- Download PTH model:
curl --create-dirs --output-dir weights -O https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth
- Convert PTH model to ggml format:
poetry run python scripts/convert-pth-to-ggml.py weights/sam_vit_b_01ec64.pth checkpoints/ 1
- Build the project:
./build.sh
or manually:
mkdir build && cd build
cmake -G Ninja ..
cmake --build . --config Release -j 8
- Run command line inference:
./build/bin/sam_cli -t 12 -i ./images/in/example1.jpg -o ./images/out/example1 -p "2070, 1170, 1"
./build/bin/sam_cli -t 12 -i ./images/in/example2.jpg -o ./images/out/example2 -p "650, 700, 1"
or on Windows:
./build/bin/sam_cli.exe -i ./images/in/example1.jpg -o ./images/out/example1 -p "2070, 1170, 1"
./build/bin/sam_cli.exe -i ./images/in/example2.jpg -o ./images/out/example2 -p "650, 700, 1"
- GTK3 application:
./build/bin/sam_gui
or on Windows:
./build/bin/sam_gui.exe
- Python demo application with original SAM implementation:
poetry run python scripts/demo.py
- Photo by Aaron Doucett on Unsplash
- Photo by Anoir Chafik on Unsplash
GPL3