Skip to content

Commit 0b63cef

Browse files
IasonTheodorouMatthijsBurgh
authored andcommitted
updated CMakeLists, included .hpp suffix and sam_onnx_ros include dir and configuration .hpp.in file
1 parent ebe0539 commit 0b63cef

File tree

12 files changed

+61
-47
lines changed

12 files changed

+61
-47
lines changed

CMakeLists.txt

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,19 @@ cmake_minimum_required(VERSION 3.14)
33
project(sam_onnx_ros)
44

55
# -------------- CMake Policies ------------------#
6-
# add_compile_options(-Wall -Werror=all)
7-
# add_compile_options(-Wextra -Werror=extra)
6+
add_compile_options(-Wall -Werror=all)
7+
add_compile_options(-Wextra -Werror=extra)
88

99
# -------------- Support C++17 for using filesystem ------------------#
1010
set(CMAKE_CXX_STANDARD 17)
1111
set(CMAKE_CXX_STANDARD_REQUIRED ON)
12-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1312

14-
# -------------- OpenCV ------------------#
15-
find_package(OpenCV REQUIRED)
16-
find_package(console_bridge REQUIRED)
1713

1814
# -------------- ONNXRuntime ------------------#
1915
set(ONNXRUNTIME_VERSION 1.21.0)
2016
set(ONNXRUNTIME_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../hero_sam.bak/onnxruntime-linux-x64-gpu-1.21.1")
2117
include_directories(${ONNXRUNTIME_ROOT}/include)
2218

23-
# -------------- Cuda ------------------#
24-
add_definitions(-DUSE_CUDA=1)
25-
include_directories(/usr/local/cuda/include)
2619

2720
# -------------- Models ------------------#
2821
# TODO: Find proper folder Copy sam_<model>.onnx file to the same folder of the executable file
@@ -37,15 +30,28 @@ find_package(catkin REQUIRED
3730
#onnxruntime_ros
3831
)
3932

40-
find_package(console_bridge REQUIRED)
33+
find_package(OpenCV REQUIRED)
34+
35+
# -------------- Cuda ------------------#
36+
add_definitions(-DUSE_CUDA=1)
37+
include_directories(/usr/local/cuda/include)
38+
39+
set(${PROJECT_NAME}_CUDA_ENABLED ${onnxruntime_ros_CUDA_ENABLED})
40+
if(onnxruntime_ros_CUDA_ENABLED)
41+
find_package(CUDAToolkit REQUIRED)
42+
endif()
43+
44+
configure_file(include/${PROJECT_NAME}/config.hpp.in ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME}/config.hpp)
45+
# add_custom_target(generate_config_hpp
46+
# DEPENDS ${CATKIN_DEVEL_PREFIX}/${CATKIN_GLOBAL_INCLUDE_DESTINATION}/${PROJECT_NAME}/config.hpp
4147

4248
# ------------------------------------------------------------------------------------------------
4349
# CATKIN EXPORT
4450
# ------------------------------------------------------------------------------------------------
4551

4652
catkin_package(
4753
INCLUDE_DIRS include
48-
LIBRARIES ${PROJECT_NAME}_lib
54+
LIBRARIES ${PROJECT_NAME}
4955
CATKIN_DEPENDS
5056
DEPENDS OpenCV console_bridge
5157
)
@@ -54,14 +60,14 @@ catkin_package(
5460
# BUILD
5561
# ------------------------------------------------------------------------------------------------
5662

57-
# Build core library
58-
add_library(${PROJECT_NAME}_lib
63+
# Build library
64+
add_library(${PROJECT_NAME}
5965
src/sam_inference.cpp
6066
src/segmentation.cpp
6167
src/utils.cpp
6268
)
6369

64-
target_include_directories(${PROJECT_NAME}_lib
70+
target_include_directories(${PROJECT_NAME}
6571
PUBLIC
6672
include
6773
SYSTEM
@@ -72,19 +78,19 @@ target_include_directories(${PROJECT_NAME}_lib
7278
)
7379

7480

75-
target_link_libraries(${PROJECT_NAME}_lib
81+
target_link_libraries(${PROJECT_NAME}
7682
${OpenCV_LIBS}
7783
${catkin_LIBRARIES}
7884
${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so
7985
)
8086

8187
# Main executable links the core lib
82-
add_executable(${PROJECT_NAME}
88+
add_executable(test_${PROJECT_NAME}
8389
src/main.cpp
8490
)
8591

86-
target_link_libraries(${PROJECT_NAME}
87-
${PROJECT_NAME}_lib
92+
target_link_libraries(test_${PROJECT_NAME}
93+
${PROJECT_NAME}
8894
${catkin_LIBRARIES}
8995
${ONNXRUNTIME_ROOT}/lib/libonnxruntime.so
9096
)
@@ -100,7 +106,7 @@ install(
100106

101107
install(
102108
TARGETS
103-
${PROJECT_NAME}_lib
109+
${PROJECT_NAME}
104110
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
105111
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
106112
RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
@@ -116,8 +122,8 @@ install(
116122
# Testing
117123
# ------------------------------------------------------------------------------------------------
118124
if (CATKIN_ENABLE_TESTING)
119-
find_package(catkin_lint_cmake REQUIRED)
120-
catkin_add_catkin_lint_test("-W2 --ignore HEADER_OUTSIDE_PACKAGE_INCLUDE_PATH")
125+
#find_package(catkin_lint_cmake REQUIRED)
126+
#catkin_add_catkin_lint_test("-W2 --ignore HEADER_OUTSIDE_PACKAGE_INCLUDE_PATH")
121127

122128
# Utils unit tests (no models needed)
123129
catkin_add_gtest(utils_tests test/test_utils.cpp)

include/sam_onnx_ros/config.hpp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef YOLO_ONNX_SAM_CONFIG_HPP_
2+
#define YOLO_ONNX_SAM_CONFIG_HPP_
3+
4+
//Set which version of the Tree Interface to use
5+
#define YOLO_ONNX_SAM_CUDA_ENABLED @onnx_sam_ros_CUDA_ENABLED@
6+
7+
#endif //#define YOLO_ONNX_SAM_CONFIG_HPP_
File renamed without changes.

include/sam_inference.h renamed to include/sam_onnx_ros/sam_inference.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#define RET_OK nullptr
66
#include <memory>
7-
#include <string>
87
#include <vector>
98
#include <cstdio>
10-
#include "utils.h"
119
#ifdef USE_CUDA
1210
#include <cuda_fp16.h>
1311
#endif
1412

13+
#include "sam_onnx_ros/utils.hpp"
14+
1515
class SAM
1616
{
1717
public:

include/segmentation.h renamed to include/sam_onnx_ros/segmentation.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#ifndef SEGMENTATION_H
22
#define SEGMENTATION_H
33

4-
#include <tuple>
4+
#include "sam_onnx_ros/sam_inference.hpp"
55

6-
#include "sam_inference.h"
76
std::tuple<std::vector<std::unique_ptr<SAM>>, SEG::_DL_INIT_PARAM, SEG::_DL_INIT_PARAM, SEG::DL_RESULT, std::vector<SEG::DL_RESULT>> Initializer();
87
void SegmentAnything(std::vector<std::unique_ptr<SAM>>& samSegmentors, const SEG::_DL_INIT_PARAM& params_encoder, const SEG::_DL_INIT_PARAM& params_decoder, const cv::Mat& img,
98
std::vector<SEG::DL_RESULT> &resSam,

include/utils.h renamed to include/sam_onnx_ros/utils.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
#define RET_OK nullptr
55

6-
#include <string>
76
#include <vector>
87
#include <cstdio>
98
#include "onnxruntime_cxx_api.h"
10-
#include "dl_types.h"
119
#ifdef USE_CUDA
1210
#include <cuda_fp16.h>
1311
#endif
1412

13+
#include "sam_onnx_ros/dl_types.hpp"
14+
1515
class Utils
1616
{
1717
public:

src/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#include "segmentation.h"
2-
#include <iostream>
3-
#include <vector>
41
#include <filesystem>
52
#include <opencv2/opencv.hpp>
63

4+
#include "sam_onnx_ros/segmentation.hpp"
5+
76
int main()
87
{
98
// Running inference

src/sam_inference.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#include "sam_inference.h"
2-
#include "utils.h"
3-
41
#include <regex>
52
#include <console_bridge/console.h>
63

4+
#include "sam_onnx_ros/sam_inference.hpp"
5+
#include "sam_onnx_ros/utils.hpp"
6+
77
#define benchmark
88
//#define ROI
99

@@ -97,11 +97,11 @@ const char *SAM::CreateSession(SEG::DL_INIT_PARAM &iParams) {
9797
auto input_shape =
9898
_session->GetInputTypeInfo(0).GetTensorTypeAndShapeInfo().GetShape();
9999

100-
auto output_shape =
101-
_session->GetOutputTypeInfo(0).GetTensorTypeAndShapeInfo().GetShape();
102-
auto output_type = _session->GetOutputTypeInfo(0)
103-
.GetTensorTypeAndShapeInfo()
104-
.GetElementType();
100+
// auto output_shape =
101+
// _session->GetOutputTypeInfo(0).GetTensorTypeAndShapeInfo().GetShape();
102+
// auto output_type = _session->GetOutputTypeInfo(0)
103+
// .GetTensorTypeAndShapeInfo()
104+
// .GetElementType();
105105

106106
WarmUpSession_(_modelType);
107107
return RET_OK;
@@ -251,9 +251,10 @@ const char *SAM::TensorProcess_(clock_t &starttime_1, const cv::Mat &iImg,
251251
embeddings.data(), // Use the embeddings from the encoder
252252
embeddings.size(), // Total number of elements
253253
decoderInputDims.data(), decoderInputDims.size());
254+
254255
// Use center of bounding box as foreground point
255-
float centerX = box.x + box.width / 2.0;
256-
float centerY = box.y + box.height / 2.0;
256+
// float centerX = box.x + box.width / 2.0;
257+
// float centerY = box.y + box.height / 2.0;
257258

258259
// Convert bounding box to points
259260
std::vector<float> pointCoords = {

src/segmentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "segmentation.h"
1+
#include "sam_onnx_ros/segmentation.hpp"
22

33
std::tuple<std::vector<std::unique_ptr<SAM>>, SEG::DL_INIT_PARAM,
44
SEG::DL_INIT_PARAM, SEG::DL_RESULT, std::vector<SEG::DL_RESULT>>

src/utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "utils.h"
2-
#include <opencv2/ximgproc/edge_filter.hpp> // for guided filter
1+
#include "sam_onnx_ros/utils.hpp"
2+
33
//#define LOGGING
44

55
// Constructor

0 commit comments

Comments
 (0)