GitHunt
HA

hamdiboukamcha/SPEED-SAM-C-TENSORRT

SPEED SAM C++ TENSORRT: A high-performance C++ implementation using TensorRT and CUDA

SPEED SAM C++ TENSORRT

SAM C++ TENSORRT

GitHub License

๐ŸŒ Overview

A high-performance C++ implementation for SAM (segment anything model) using TensorRT and CUDA, optimized for real-time image segmentation tasks.

๐Ÿ“ข Updates

Model Conversion: Build TensorRT engines from ONNX models for accelerated inference.
Segmentation with Points and BBoxes: Easily segment images using selected points or bounding boxes.
FP16 Precision: Choose between FP16 and FP32 for speed and precision balance.
Dynamic Shape Support: Efficient handling of variable input sizes using optimization profiles.
CUDA Optimization: Leverage CUDA for preprocessing and efficient memory handling.

๐Ÿ“ข Performance

Infernce Time

Component SpeedSAM
Image Encoder
Parameters 5M
Speed 8ms
Mask Decoder
Parameters 3.876M
Speed 4ms
Whole Pipeline (Enc+Dec)
Parameters 9.66M
Speed 12ms

Results

SPEED-SAM-C-TENSORRT RESULT

๐Ÿ“‚ Project Structure

SPEED-SAM-CPP-TENSORRT/
โ”œโ”€โ”€ include
โ”‚   โ”œโ”€โ”€ config.h          # Model configuration and macros
โ”‚   โ”œโ”€โ”€ cuda_utils.h      # CUDA utility macros
โ”‚   โ”œโ”€โ”€ engineTRT.h       # TensorRT engine management
โ”‚   โ”œโ”€โ”€ logging.h         # Logging utilities
โ”‚   โ”œโ”€โ”€ macros.h          # API export/import macros
โ”‚   โ”œโ”€โ”€ speedSam.h        # SpeedSam class definition
โ”‚   โ””โ”€โ”€ utils.h           # Utility functions for image handling
โ”œโ”€โ”€ src
โ”‚   โ”œโ”€โ”€ engineTRT.cpp     # Implementation of the TensorRT engine
โ”‚   โ”œโ”€โ”€ main.cpp          # Main entry point
โ”‚   โ””โ”€โ”€ speedSam.cpp      # Implementation of the SpeedSam class
โ””โ”€โ”€ CMakeLists.txt        # CMake configuration

๐Ÿš€ Installation

Prerequisites

git clone https://github.com/hamdiboukamcha/SPEED-SAM-C-TENSORRT.git
cd SPEED-SAM-CPP-TENSORRT

# Create a build directory and compile
mkdir build && cd build
cmake ..
make -j$(nproc)

Note: Update the CMakeLists.txt with the correct paths for TensorRT and OpenCV.

๐Ÿ“ฆ Dependencies

CUDA: NVIDIA's parallel computing platform
TensorRT: High-performance deep learning inference
OpenCV: Image processing library
C++17: Required standard for compilation

๐Ÿ” Code Overview

Main Components

SpeedSam Class (speedSam.h): Manages image encoding and mask decoding.
EngineTRT Class (engineTRT.h): TensorRT engine creation and inference.
CUDA Utilities (cuda_utils.h): Macros for CUDA error handling.
Config (config.h): Defines model parameters and precision settings.

Key Functions

EngineTRT::build: Builds the TensorRT engine from an ONNX model.
EngineTRT::infer: Runs inference on the provided input data.
SpeedSam::predict: Segments an image using input points or bounding boxes.

๐Ÿ“ž Contact

For advanced inquiries, feel free to contact me on LinkedIn: LinkedIn

๐Ÿ“œ Citation

If you use this code in your research, please cite the repository as follows:

    @misc{boukamcha2024SpeedSam,
        author = {Hamdi Boukamcha},
        title = {SPEED-SAM-C-TENSORRT},
        year = {2024},
        publisher = {GitHub},
        howpublished = {\url{https://github.com/hamdiboukamcha/SPEED-SAM-C-TENSORRT//}},
    }