Skip to content
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

Deploying C++ OT model on ROS #9

Closed
SiqianLi opened this issue Sep 1, 2022 · 5 comments
Closed

Deploying C++ OT model on ROS #9

SiqianLi opened this issue Sep 1, 2022 · 5 comments

Comments

@SiqianLi
Copy link

SiqianLi commented Sep 1, 2022

Hello, thank you for your great work!

Have you tried deploying the C++ OT model on ROS?
I am having a hard time running the OT model with ROS Kinetic in C++. The libtorch breaks the ROS when I try to include it in my package CMakelist.txt. But this "fast_ot.cpp" works in my environment compiled by cmake.

My Environment:
Ubuntu 20.04, CUDA 11.1, Pytorch 1.10.0, Libtorch 1.8.0/1.9.0/1.10.0 (all I have tried, but with no success on ROS)

@BIT-MJY
Copy link
Member

BIT-MJY commented Sep 2, 2022

Hello @SiqianLi,

Thanks for using our code!

Actually we have not implemented OT with ROS. If possible, could you provide the log related to your error here?

@SiqianLi
Copy link
Author

SiqianLi commented Sep 3, 2022

Here is my log at catkin_make:

[ 8%] Building CXX object lidar_localization/CMakeFiles/data_pretreat_node.dir/src/mapping/loop_closing/loop_closing_flow.cpp.o
In file included from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/data/dataloader_options.h:4,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/data/dataloader/base.h:3,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/data/dataloader/stateful.h:3,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/data/dataloader.h:3,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/data.h:3,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/all.h:8,
from /home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/torch.h:3,
from /home/ubuntu/learn/14nn_ws/src/lidar_localization/src/mapping/loop_closing/loop_closing.cpp:17:
/home/ubuntu/Downloads/Tools/libtorch/include/torch/csrc/api/include/torch/types.h:39:16: error: conflicting declaration ‘constexpr const auto torch::kUInt8’
39 | constexpr auto kUInt8 = at::kByte;
| ^~~~~~
In file included from /home/ubuntu/learn/14nn_ws/src/lidar_localization/third_party/libtorch/include/torch/script.h:3,
from /home/ubuntu/learn/14nn_ws/src/lidar_localization/src/mapping/loop_closing/loop_closing.cpp:16:
/home/ubuntu/learn/14nn_ws/src/lidar_localization/third_party/libtorch/include/torch/csrc/api/include/torch/types.h:39:16: note: previous declaration as ‘constexpr const c10::ScalarType torch::kUInt8’
39 | constexpr auto kUInt8 = at::kByte;
| ^~~~~~

Following is my CMakelists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(lidar_localization)

SET(CMAKE_BUILD_TYPE "Release")
#SET(CMAKE_BUILD_TYPE "Debug")
SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

add_compile_options(-std=c++14)
add_definitions(-std=c++14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

set(CMAKE_PREFIX_PATH "/home/ubuntu/Downloads/Tools/libtorch/share/cmake/Torch;/opt/ros/noetic")

set(Torch_DIR /home/ubuntu/Downloads/Tools/libtorch/share/cmake/Torch)
find_package(Torch REQUIRED)
include_directories(/home/ubuntu/Downloads/Tools/libtorch/share/cmake/Torch/include/)
list(APPEND ALL_TARGET_LIBRARIES ${TORCH_LIBRARIES})

add_executable(loop_closing_node src/apps/loop_closing_node.cpp ${ALL_SRCS})
add_dependencies(loop_closing_node ${catkin_EXPORTED_TARGETS} ${PROJECT_NAME}_generate_messages_cpp)
#target_link_libraries(loop_closing_node PUBLIC ${TORCH_LIBRARIES} ${catkin_LIBRARIES} ${ALL_TARGET_LIBRARIES})
target_link_libraries(loop_closing_node PUBLIC ${catkin_LIBRARIES} ${ALL_TARGET_LIBRARIES})

And attached is my running result of ./fast_ot which outputs the similar between frame 000000.bin and 000020.bin.
fast_ot with cpp

@smalltheater
Copy link

I deployed this work on ROS, It might caused by wrong version of libtorch. You should not use pre cxx 11 , it conflicted to your ROS c++ standard.

@SiqianLi
Copy link
Author

SiqianLi commented Sep 5, 2022

Thanks! This works for me!

@Chen-Xieyuanli
Copy link
Member

It seems the issue has been solved. I will therefore close it. Please feel free to ask us to reopen it if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants