sam.cpp  by YavorGIvanov

C/C++ inference for Meta's Segment Anything Model (SAM)

created 1 year ago
1,275 stars

Top 31.8% on sourcepulse

GitHubView on GitHub
Project Summary

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

  • Install: git clone --recursive https://github.com/YavorGIvanov/sam.cpp && cd sam.cpp
  • Prerequisites: Python 3, PyTorch, NumPy (for model conversion), CMake, SDL2 (for GUI).
  • Model Conversion: Download .pth checkpoint, run python convert-pth-to-ggml.py <path_to_pth> <output_dir>.
  • Build: mkdir build && cd build && cmake .. && make -j4
  • Inference: ./bin/sam -t <threads> -i <image_path> -m <ggml_model_path>
  • Docs: https://github.com/YavorGIvanov/sam.cpp

Highlighted Details

  • Pure C/C++ implementation of SAM.
  • Utilizes ggml for CPU-optimized inference.
  • Supports conversion of official PyTorch checkpoints.
  • Includes basic GUI via SDL2 for visualization.

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.

Health Check
Last commit

1 year ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
5 stars in the last 90 days

Explore Similar Projects

Starred by Jared Palmer Jared Palmer(Ex-VP of AI at Vercel; Founder of Turborepo; Author of Formik, TSDX), Eugene Yan Eugene Yan(AI Scientist at AWS), and
2 more.

starcoder.cpp by bigcode-project

0.2%
456
C++ example for StarCoder inference
created 2 years ago
updated 1 year ago
Starred by Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), Jared Palmer Jared Palmer(Ex-VP of AI at Vercel; Founder of Turborepo; Author of Formik, TSDX), and
1 more.

mpt-30B-inference by abacaj

0%
575
CPU inference code for MPT-30B
created 2 years ago
updated 2 years ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Tim J. Baek Tim J. Baek(Founder of Open WebUI), and
5 more.

gemma.cpp by google

0.1%
7k
C++ inference engine for Google's Gemma models
created 1 year ago
updated 1 day ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Lianmin Zheng Lianmin Zheng(Author of SGLang), and
13 more.

gpt-fast by pytorch-labs

0.1%
6k
PyTorch text generation for efficient transformer inference
created 1 year ago
updated 3 months ago
Feedback? Help us improve.