Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

hamdiboukamcha/SPEED-SAM-C-TENSORRT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

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//}},
 }

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /