Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
269a64c
Initial refactoring
IasonTheodorou Jul 3, 2025
3f0aa16
create catkin package
IasonTheodorou Jul 4, 2025
fe77196
included CI tests
IasonTheodorou Jul 4, 2025
17bd100
update of CMakeLists to include some initial needed components
IasonTheodorou Jul 4, 2025
2ef2fc4
Return the mask on SegmentAnything function (not working properly)
IasonTheodorou Jul 4, 2025
70fd58a
Updated CMake and removed not needed parts of the code
IasonTheodorou Aug 19, 2025
6c5c097
Updated code format
IasonTheodorou Aug 26, 2025
e10d45d
Small refactoring of the module
IasonTheodorou Aug 29, 2025
5cb4ab4
Refactor post processing for better accuracy and performance. Also co…
IasonTheodorou Sep 2, 2025
0fe00da
Added tests (still not working with catkin)
IasonTheodorou Sep 2, 2025
9f21012
Fixed catkin workspace for both code and tests
IasonTheodorou Sep 4, 2025
a9fce07
fixed functionallity for the tests to pass and added logging definition
IasonTheodorou Sep 5, 2025
dffbcd3
renamed private members of utils and sam_inference
IasonTheodorou Sep 5, 2025
959a3ff
Separrated test files per category (utils or sam related for now)
IasonTheodorou Sep 5, 2025
fa97e64
Updated initializer and SegmentAnything modules to store the data to …
IasonTheodorou Sep 10, 2025
53989b6
Enabled cuda on the decoder as well
IasonTheodorou Sep 10, 2025
7490f03
Fixed small bug of adding an extra (full img) bounding box
IasonTheodorou Sep 10, 2025
01da1fc
Aligned dimensions [high width] between onnx and opencv
IasonTheodorou Sep 12, 2025
7cdf39a
corrected tests for the new segmentation way of inference (initialize…
IasonTheodorou Sep 12, 2025
b587a1c
Removed typo / from model path
IasonTheodorou Sep 12, 2025
b83bf61
Bump min required cmake version to 3.14
MatthijsBurgh Sep 16, 2025
733167f
EOF line added and package.xml structure update
IasonTheodorou Sep 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: CI

on: [push, pull_request]

jobs:
tue-ci:
name: TUe CI - ${{ github.event_name }}
runs-on: ubuntu-latest
steps:
- name: TUe CI
uses: tue-robotics/tue-env/ci/main@master
with:
package: ${{ github.event.repository.name }}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
build/
images/*
onnxruntime*/
onnxruntime/*
docker/*
CMakefile
CMakeCache.txt
CMakeFiles/*
cmake_install.cmake
Makefile
SPEED-SAM-C-TENSORRT/
sam_inference/model/FastSAM-x.onnx
mask*
segmentation_results*
112 changes: 86 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,59 +1,119 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.14)

set(PROJECT_NAME SAMOnnxRuntimeCPPInference)
project(${PROJECT_NAME} VERSION 0.0.1 LANGUAGES CXX)
project(sam_onnx_ros)

# -------------- CMake Policies ------------------#
#add_compile_options(-Wall -Werror=all)
#add_compile_options(-Wextra -Werror=extra)

# -------------- Support C++17 for using filesystem ------------------#
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

#set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# -------------- OpenCV ------------------#
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})


# -------------- ONNXRuntime ------------------#
set(ONNXRUNTIME_VERSION 1.21.0)
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../onnxruntime-linux-x64-gpu-1.21.1")
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../hero_sam.bak/onnxruntime-linux-x64-gpu-1.21.1")
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded relative path to a '.bak' directory is fragile and non-portable. Consider using find_package or environment variables to locate ONNX Runtime.

Suggested change
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../hero_sam.bak/onnxruntime-linux-x64-gpu-1.21.1")
# Allow user to specify ONNXRUNTIME_ROOT via CMake variable or environment variable
if(NOT DEFINED ONNXRUNTIME_ROOT)
if(DEFINED ENV{ONNXRUNTIME_ROOT})
set(ONNXRUNTIME_ROOT $ENV{ONNXRUNTIME_ROOT})
else()
message(FATAL_ERROR "ONNXRUNTIME_ROOT is not set. Please set the ONNXRUNTIME_ROOT environment variable or pass -DONNXRUNTIME_ROOT=... to cmake.")
endif()
endif()

Copilot uses AI. Check for mistakes.

include_directories(${ONNXRUNTIME_ROOT}/include)

# -------------- Cuda ------------------#
add_definitions(-DUSE_CUDA=1)
include_directories(/usr/local/cuda/include)

find_package(catkin REQUIRED
COMPONENTS
# roscpp
# tue_config
# tue_filesystem
# code_profiler

#onnxruntime_ros
)

# ------------------------------------------------------------------------------------------------
# CATKIN EXPORT
# ------------------------------------------------------------------------------------------------

catkin_package(
INCLUDE_DIRS include
#LIBRARIES ${PROJECT_NAME}
LIBRARIES sam_onnx_ros_core
CATKIN_DEPENDS
DEPENDS OpenCV
)

# ------------------------------------------------------------------------------------------------
# BUILD
# ------------------------------------------------------------------------------------------------

include_directories(
include
SYSTEM
${OpenCV_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)

set(PROJECT_SOURCES
src/main.cpp
src/sam_inference.cpp
src/segmentation.cpp
src/utils.cpp
)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)

# Link OpenCV libraries along with ONNX Runtime
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} ${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so)

# For Windows system, copy onnxruntime.dll to the same folder of the executable file
if (WIN32)
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${ONNXRUNTIME_ROOT}/lib/onnxruntime.dll"
$<TARGET_FILE_DIR:${PROJECT_NAME}>)
endif ()
# Build core library (no main.cpp here)
add_library(sam_onnx_ros_core
src/sam_inference.cpp
src/segmentation.cpp
src/utils.cpp
)
target_link_libraries(sam_onnx_ros_core
${OpenCV_LIBS}
${catkin_LIBRARIES}
${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so
)
target_include_directories(sam_onnx_ros_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Download https://raw.githubusercontent.com/ultralytics/ultralytics/main/ultralytics/cfg/datasets/coco.yaml
# and put it in the same folder of the executable file
configure_file(./model/SAM_mask_decoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_mask_decoder.onnx COPYONLY)
# Main executable links the core lib
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} sam_onnx_ros_core)

# Copy yolov8n.onnx file to the same folder of the executable file
configure_file(./model/SAM_encoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_encoder.onnx COPYONLY)
# Copy sam_<model>.onnx file to the same folder of the executable file
configure_file(~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_mask_decoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_mask_decoder.onnx COPYONLY)
configure_file(~/Documents/repos/hero_sam.bak/sam_inference/model/SAM_encoder.onnx ${CMAKE_CURRENT_BINARY_DIR}/SAM_encoder.onnx COPYONLY)
Comment on lines +87 to +88
Copy link
Preview

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded absolute paths with tilde expansion and '.bak' directories are not portable and will fail on other systems. Consider using relative paths or making model paths configurable.

Copilot uses AI. Check for mistakes.


# Create folder name images in the same folder of the executable file
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/images
)

# # Enable testing
if (CATKIN_ENABLE_TESTING)
# find_package(catkin_lint_cmake REQUIRED)
# catkin_add_catkin_lint_test("-W2 --ignore HEADER_OUTSIDE_PACKAGE_INCLUDE_PATH")

# Utils unit tests (no models needed)
catkin_add_gtest(utils_tests test/test_utils.cpp)
if(TARGET utils_tests)
target_link_libraries(utils_tests sam_onnx_ros_core GTest::gtest_main ${catkin_LIBRARIES})
target_include_directories(utils_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()

# SAM integration-ish tests (may need models)
catkin_add_gtest(sam_tests test/sam_test.cpp)
if(TARGET sam_tests)
target_link_libraries(sam_tests sam_onnx_ros_core GTest::gtest_main ${catkin_LIBRARIES})
target_include_directories(sam_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()
endif()



#If you want to debug
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "-g")
# set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_CXX_FLAGS_DEBUG "-g")
37 changes: 20 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
Custom License Agreement
BSD 2-Clause License

1. License Grant You are hereby granted a non-exclusive, non-transferable license to use, reproduce, and distribute the code (hereinafter referred to as "the Software") under the following conditions:
Copyright (c) 2021, Eindhoven University of Technology - CST Robotics Group
All rights reserved.

2. Conditions of Use
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Non-Commercial Use: You may use the Software for personal, educational, or non-commercial purposes without any additional permissions.
Commercial Use: Any commercial use of the Software, including but not limited to selling, licensing, or using it in a commercial product, requires prior written permission from the original developer.
3. Contact Requirement
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

If you wish to use the Software for commercial purposes, you must contact the original developer at [https://www.linkedin.com/in/hamdi-boukamcha/] to obtain a commercial license.
The terms of any commercial license will be mutually agreed upon and may involve a licensing fee.
4. Attribution
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Regardless of whether you are using the Software for commercial or non-commercial purposes, you must provide appropriate credit to the original developer in any distributions or products that use the Software.
5. Disclaimer of Warranty

The Software is provided "as is," without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the original developer be liable for any claim, damages, or other liability, whether in an action of contract, tort, or otherwise, arising from, out of, or in connection with the Software or the use or other dealings in the Software.
6. Governing Law

This License Agreement shall be governed by and construed in accordance with the laws of France.
By using the Software, you agree to abide by the terms outlined in this License Agreement.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ A high-performance C++ implementation for SAM (segment anything model) using Ten
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
## 📢 Performance
### Infernce Time

| Component | SpeedSAM |
|----------------------------|-----------|
Expand Down Expand Up @@ -51,7 +51,7 @@ A high-performance C++ implementation for SAM (segment anything model) using Ten
│ ├── 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
Expand Down Expand Up @@ -94,8 +94,3 @@ If you use this code in your research, please cite the repository as follows:
publisher = {GitHub},
howpublished = {\url{https://github.com/hamdiboukamcha/SPEED-SAM-C-TENSORRT//}},
}





68 changes: 0 additions & 68 deletions inc/dl_types.h

This file was deleted.

61 changes: 0 additions & 61 deletions inc/sam_inference.h

This file was deleted.

Loading
Loading