-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/refactoring #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
269a64c
3f0aa16
fe77196
17bd100
2ef2fc4
70fd58a
6c5c097
e10d45d
5cb4ab4
0fe00da
9f21012
a9fce07
dffbcd3
959a3ff
fa97e64
53989b6
7490f03
01da1fc
7cdf39a
b587a1c
b83bf61
733167f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 }} |
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* |
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") | ||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Positive FeedbackNegative Feedback |
||
|
||
# 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") |
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. |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
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.
Copilot uses AI. Check for mistakes.