From 29b826aa3bb6b9b6b3d5f4a18f698e36521e41a2 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Sat, 1 Apr 2023 15:36:21 +0200 Subject: [PATCH 01/11] Find torch based on pip install --- ed_sensor_integration/CMakeLists.txt | 22 ++++++++++++++++++---- ed_sensor_integration/tools/test_torch.cpp | 7 +++++++ 2 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 ed_sensor_integration/tools/test_torch.cpp diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 67934c20..26b75f11 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -4,8 +4,20 @@ project(ed_sensor_integration) add_compile_options(-Wall -Werror=all) add_compile_options(-Wextra -Werror=extra) +find_package (Python COMPONENTS Interpreter REQUIRED) +execute_process( + COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0])" + OUTPUT_VARIABLE TORCH_LIBRARY_PATH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) +message(VERBOSE "TORCH_LIBRARY_PATH: ${TORCH_LIBRARY_PATH}") + find_package(OpenCV REQUIRED) find_package(PCL REQUIRED COMPONENTS common kdtree) +find_package(Torch 1.10 REQUIRED + PATHS "${TORCH_LIBRARY_PATH}/share/cmake" +) find_package(catkin REQUIRED COMPONENTS code_profiler ed @@ -31,7 +43,7 @@ catkin_package( INCLUDE_DIRS include LIBRARIES ed_kinect CATKIN_DEPENDS code_profiler ed ${PROJECT_NAME}_msgs geolib2 image_geometry rgbd rgbd_image_buffer roscpp tue_config visualization_msgs - DEPENDS OpenCV PCL + DEPENDS OpenCV PCL Torch ) # ------------------------------------------------------------------------------------------------ @@ -42,6 +54,7 @@ include_directories( include SYSTEM ${OpenCV_INCLUDE_DIRS} + ${TORCH_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS} ) @@ -121,6 +134,9 @@ target_link_libraries(ed_clearer_plugin ${catkin_LIBRARIES}) # TOOLS # ------------------------------------------------------------------------------------------------ +add_executable(test_torch tools/test_torch.cpp) +target_link_libraries(test_torch ${TORCH_LIBRARIES}) + add_executable(ed_image_saver tools/image_saver.cpp) target_link_libraries(ed_image_saver ${catkin_LIBRARIES}) add_dependencies(ed_image_saver ${catkin_EXPORTED_TARGETS}) @@ -168,6 +184,7 @@ install( ed_fitter_live ed_image_saver ed_segmenter + test_torch DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) @@ -184,6 +201,3 @@ if (CATKIN_ENABLE_TESTING) catkin_add_gtest(test_laser_fitting test/test_laser_segmenter.cpp) target_link_libraries(test_laser_fitting ${PROJECT_NAME}_console_bridge ed_laser ${OpenCV_LIBRARIES} ${catkin_LIBRARIES}) endif () - - - diff --git a/ed_sensor_integration/tools/test_torch.cpp b/ed_sensor_integration/tools/test_torch.cpp new file mode 100644 index 00000000..5537724c --- /dev/null +++ b/ed_sensor_integration/tools/test_torch.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + torch::Tensor tensor = torch::eye(3); + std::cout << tensor << std::endl; +} From cb65978a4c8ab635388828bca4ea02b081a0db68 Mon Sep 17 00:00:00 2001 From: Lotte Messing Date: Sat, 1 Apr 2023 15:41:57 +0200 Subject: [PATCH 02/11] First version of yolo test exec --- ed_sensor_integration/CMakeLists.txt | 4 ++++ ed_sensor_integration/tools/test_yolo.cpp | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 ed_sensor_integration/tools/test_yolo.cpp diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 26b75f11..d99b513a 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -137,6 +137,9 @@ target_link_libraries(ed_clearer_plugin ${catkin_LIBRARIES}) add_executable(test_torch tools/test_torch.cpp) target_link_libraries(test_torch ${TORCH_LIBRARIES}) +add_executable(test_yolo tools/test_yolo.cpp) +target_link_libraries(test_yolo ${TORCH_LIBRARIES}) + add_executable(ed_image_saver tools/image_saver.cpp) target_link_libraries(ed_image_saver ${catkin_LIBRARIES}) add_dependencies(ed_image_saver ${catkin_EXPORTED_TARGETS}) @@ -185,6 +188,7 @@ install( ed_image_saver ed_segmenter test_torch + test_yolo DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) diff --git a/ed_sensor_integration/tools/test_yolo.cpp b/ed_sensor_integration/tools/test_yolo.cpp new file mode 100644 index 00000000..5537724c --- /dev/null +++ b/ed_sensor_integration/tools/test_yolo.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + torch::Tensor tensor = torch::eye(3); + std::cout << tensor << std::endl; +} From ca57360309b5f98656d51469f17a4c1899bedf17 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Sat, 1 Apr 2023 21:09:02 +0200 Subject: [PATCH 03/11] [TEMP] Add dep on torch --- ed_sensor_integration/package.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ed_sensor_integration/package.xml b/ed_sensor_integration/package.xml index 7cddbf8c..be9146ad 100644 --- a/ed_sensor_integration/package.xml +++ b/ed_sensor_integration/package.xml @@ -36,6 +36,8 @@ tue_filesystem tue_filesystem + python3-pytorch-pip + catkin_lint_cmake doxygen From 55941f42eabafb04676a9d8349d0d98f8ed794ee Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 3 Apr 2023 08:48:14 +0200 Subject: [PATCH 04/11] Print PYTHON_EXECUTABLE --- ed_sensor_integration/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index d99b513a..21a7b8d0 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -5,6 +5,7 @@ add_compile_options(-Wall -Werror=all) add_compile_options(-Wextra -Werror=extra) find_package (Python COMPONENTS Interpreter REQUIRED) +message(WARNING "PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0])" OUTPUT_VARIABLE TORCH_LIBRARY_PATH From 241a81acf0f62be2fecf57db31a04610fe4f43dc Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 3 Apr 2023 09:52:38 +0200 Subject: [PATCH 05/11] PYTHON_EXECUTABLE->Python_EXECUTABLE --- ed_sensor_integration/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 21a7b8d0..548a18d7 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -5,9 +5,8 @@ add_compile_options(-Wall -Werror=all) add_compile_options(-Wextra -Werror=extra) find_package (Python COMPONENTS Interpreter REQUIRED) -message(WARNING "PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") execute_process( - COMMAND ${PYTHON_EXECUTABLE} -c "import torch; print(torch.__path__[0])" + COMMAND ${Python_EXECUTABLE} -c "import torch; print(torch.__path__[0])" OUTPUT_VARIABLE TORCH_LIBRARY_PATH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET From ae95b3596f8b537293d9c7a9beb92939d83bf9ba Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Sun, 2 Apr 2023 09:01:23 +0200 Subject: [PATCH 06/11] [TEMP] print torch paths --- ed_sensor_integration/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 548a18d7..4b10c2b7 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -11,13 +11,14 @@ execute_process( OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) -message(VERBOSE "TORCH_LIBRARY_PATH: ${TORCH_LIBRARY_PATH}") +message(WARNING "TORCH_LIBRARY_PATH: ${TORCH_LIBRARY_PATH}") find_package(OpenCV REQUIRED) find_package(PCL REQUIRED COMPONENTS common kdtree) find_package(Torch 1.10 REQUIRED PATHS "${TORCH_LIBRARY_PATH}/share/cmake" ) +message(WARNING "TORCH_INCLUDE_DIRS: ${TORCH_INCLUDE_DIRS}") find_package(catkin REQUIRED COMPONENTS code_profiler ed From ac32b5d33d77e4ebc7b140de2b754eb44cecee63 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Sun, 2 Apr 2023 09:21:25 +0200 Subject: [PATCH 07/11] [TEMP] don't silence python error --- ed_sensor_integration/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 4b10c2b7..09a284b6 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -9,7 +9,6 @@ execute_process( COMMAND ${Python_EXECUTABLE} -c "import torch; print(torch.__path__[0])" OUTPUT_VARIABLE TORCH_LIBRARY_PATH OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_QUIET ) message(WARNING "TORCH_LIBRARY_PATH: ${TORCH_LIBRARY_PATH}") From 00ec82f12d9ddcef3e4180f5f6769c066fe45a8c Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Sun, 2 Apr 2023 09:43:41 +0200 Subject: [PATCH 08/11] [TEMP] also print to stderr --- ed_sensor_integration/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index 09a284b6..ee30268a 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -6,7 +6,7 @@ add_compile_options(-Wextra -Werror=extra) find_package (Python COMPONENTS Interpreter REQUIRED) execute_process( - COMMAND ${Python_EXECUTABLE} -c "import torch; print(torch.__path__[0])" + COMMAND ${Python_EXECUTABLE} -c "import torch; from sys import stderr; print(torch.__path__[0]); print(f'{torch.__path__[0]}=', file=stderr)" OUTPUT_VARIABLE TORCH_LIBRARY_PATH OUTPUT_STRIP_TRAILING_WHITESPACE ) From 2641ccba53dfc952d495a2e8500183d0b3305da2 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 3 Apr 2023 08:48:14 +0200 Subject: [PATCH 09/11] Print PYTHON_EXECUTABLE --- ed_sensor_integration/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index ee30268a..a261e35a 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -5,6 +5,7 @@ add_compile_options(-Wall -Werror=all) add_compile_options(-Wextra -Werror=extra) find_package (Python COMPONENTS Interpreter REQUIRED) +message(WARNING "PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") execute_process( COMMAND ${Python_EXECUTABLE} -c "import torch; from sys import stderr; print(torch.__path__[0]); print(f'{torch.__path__[0]}=', file=stderr)" OUTPUT_VARIABLE TORCH_LIBRARY_PATH From 6f10c8de64e141352497fd8cfbb2fb88f5bc3b7b Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 3 Apr 2023 09:05:09 +0200 Subject: [PATCH 10/11] Add build dep on python3 --- ed_sensor_integration/package.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ed_sensor_integration/package.xml b/ed_sensor_integration/package.xml index be9146ad..fff5e3df 100644 --- a/ed_sensor_integration/package.xml +++ b/ed_sensor_integration/package.xml @@ -27,6 +27,8 @@ tue_config visualization_msgs + python3 + geometry_msgs geometry_msgs rosconsole_bridge From a1cb1a7cbd1f56c54f35c4817b95bfcb0c2819bd Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Mon, 3 Apr 2023 09:52:38 +0200 Subject: [PATCH 11/11] PYTHON_EXECUTABLE->Python_EXECUTABLE --- ed_sensor_integration/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ed_sensor_integration/CMakeLists.txt b/ed_sensor_integration/CMakeLists.txt index a261e35a..020b1dbc 100644 --- a/ed_sensor_integration/CMakeLists.txt +++ b/ed_sensor_integration/CMakeLists.txt @@ -5,7 +5,7 @@ add_compile_options(-Wall -Werror=all) add_compile_options(-Wextra -Werror=extra) find_package (Python COMPONENTS Interpreter REQUIRED) -message(WARNING "PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") +message(WARNING "Python_EXECUTABLE: ${Python_EXECUTABLE}") execute_process( COMMAND ${Python_EXECUTABLE} -c "import torch; from sys import stderr; print(torch.__path__[0]); print(f'{torch.__path__[0]}=', file=stderr)" OUTPUT_VARIABLE TORCH_LIBRARY_PATH