sam.cpp  by YavorGIvanov

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

Created 2 years ago
1,278 stars

Top 31.1% 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

Inactive

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

Explore Similar Projects

Starred by Jared Palmer Jared Palmer(Ex-VP 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%
456
C++ example for StarCoder inference
Created 2 years ago
Updated 2 years ago
Starred by Yaowei Zheng Yaowei Zheng(Author of LLaMA-Factory), Yineng Zhang Yineng Zhang(Inference Lead at SGLang; Research Scientist at Together AI), and
1 more.

VeOmni by ByteDance-Seed

3.4%
1k
Framework for scaling multimodal model training across accelerators
Created 5 months ago
Updated 3 weeks ago
Starred by Luca Soldaini Luca Soldaini(Research Scientist at Ai2), Edward Sun Edward Sun(Research Scientist at Meta Superintelligence Lab), and
4 more.

parallelformers by tunib-ai

0%
790
Toolkit for easy model parallelization
Created 4 years ago
Updated 2 years ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Jeff Hammerbacher Jeff Hammerbacher(Cofounder of Cloudera), and
4 more.

gemma_pytorch by google

0.2%
6k
PyTorch implementation for Google's Gemma models
Created 1 year ago
Updated 3 months ago
Feedback? Help us improve.