Closed mattiasmar closed 1 year ago
Got same undefined reference
errors yesterday on amlmost all rtabmap's core functions. Not sure why, maybe pytorch is packaged with difference version of standard libraries.. As a workaround I built pytorch from source. The build passes, but got this new issue https://github.com/introlab/rtabmap/issues/1064 when running the code. I'll try later with an older pytorch version.
Otherwise for your case, as you are using a Dockerfile, I'll suggest to start from pytorch base image (FROM nvcr.io/nvidia/pytorch:22.08-py3
) directly like in this example: https://github.com/introlab/rtabmap/blob/master/docker/frontiers2022/Dockerfile. And like explained in this other post, you can then install ros in it.
How do I install ROS2 Humble in the frontiers2022 image? That dockerfile holds Ubuntu 20, and as far as I can tell ROS2 requires Ubuntu22. Please correct me if I'm wrong.
Oh yeah, I read too quickly the name of the image FROM nvcr.io/nvidia/pytorch:22.08-py3
, and based on my post, it would be indeed 20.04. You can install ros2 foxy on 20.04. If you need humble + 22.04, you may check if nvidia has already a pytorch image, otherwise you would need to do like what you did. To go around undefined reference
errors, you may have to rebuild pytorch from source though. This is how I installed pytorch on my computer:
git clone https://github.com/pytorch/pytorch
git clone https://github.com/pytorch/vision
cd pytorch
python3 setup.py install
cd ..
cd vision
python3 setup.py install
If you want fixed version, you may check at this table: https://github.com/pytorch/vision#installation
I'm building now with pytorch 1.13.1. Will report on results once ready. Building from source like you wrote compiles but fails during runtime, as in #1064, correct?
Yes, with latest pytorch version at least. And those lines can be useful to regenerate the superpoint model based on your pytorch version: https://github.com/introlab/rtabmap/blob/59d5675fe63e0b100954c73b0c4e2f0a8ac6a07e/docker/frontiers2022/Dockerfile#L58-L62
Let me know if you don't get a seg fault with 1.13.1.
I tried with pytorch 1.13.1 and 1.12.0. Both gave me build (linkage) errors.
#PyTorch 1.13.1
RUN pip3 install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
RUN wget https://download.pytorch.org/libtorch/cu117/libtorch-shared-with-deps-1.13.1%2Bcu117.zip
RUN unzip libtorch-shared-with-deps-1.13.1+cu117.zip -d /torch
#PyTorch 1.12.0
RUN pip3 install torch==1.12.0+cu113 torchvision==0.13.0+cu113 torchaudio==0.12.0 --extra-index-url https://download.pytorch.org/whl/cu113
RUN wget https://download.pytorch.org/libtorch/cu111/libtorch-shared-with-deps-1.12.0%2Bcu113.zip
RUN unzip libtorch-shared-with-deps-1.12.0+cu113.zip -d /torch
Testing humble with pytorch built from source + Testing foxy on nvidia's pytorch/ubuntu20 image. Results ready by tomorrow.
What will I loose when moving from humble to foxy? Anything special you would want to make a Rtabmap user aware of?
From rtabmap point of view, it is the same code on foxy and humble. Note also I did fix the seg fault I had, so confirming it is also working with latest pytorch (2.1).
Good news: dockerimage based on nvidia/cuda:11.8.0-devel-ubuntu22.04, with pytorch compiled from source allowed to build rtabmap. Yet to test this and then continue towards rtabmap_ros.
3 questions: When you said pytorch 2.1 you really meant 2.0.1, right? Does your existing frontiers image build the master branch for you? Does that colcon build of rtabmap_ros work for you in that image too?
Things look indeed much better now.
In terms of compilation the only issue that seems to remain for me now is that unless I in rtabmap/corelib/src/CMakeLists.txt
under the IF(WITH_PYTHON AND Python3_FOUND)
clause (line 209) use LIBRARIES
instead of PUBLIC_LIBRARIES
(the current state in the master) I get this build error:
Starting >>> rtabmap_conversions
--- stderr: rtabmap_conversions
** WARNING ** io features related to pcap will be disabled
** WARNING ** io features related to png will be disabled
CMake Error at CMakeLists.txt:53 (add_library):
Target "rtabmap_conversions" links to target "Python3::Python" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
CMake Error at CMakeLists.txt:53 (add_library):
Target "rtabmap_conversions" links to target "Python3::NumPy" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
I'm building using this command:
colcon build --symlink-install --cmake-args -DRTABMAP_SYNC_MULTI_RGBD=ON -DWITH_OPENGV=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_CXX_STANDARD=17 -D WITH_TORCH=ON -D WITH_PYTHON=ON -D Torch_DIR=/usr/local/lib/python3.10/dist-packages/torch/share/cmake/Torch/ -DCMAKE_CXX_FLAGS="-I/usr/include/python3.10/"
These line of CMakeLists was changed by this commit
I fixed the python dep missing in commit above.
For the frontiers docker image, there is a COPY . rtabmap
, if you cloned the master version, it will be master.
For pytorch, the latest master seems to be 2.1.0:
~/.local/lib/python3.8/site-packages/torch/share/cmake/Torch$ cat TorchConfigVersion.cmake
set(PACKAGE_VERSION "2.1.0")
I didn't try colcon on that image, only noetic catkin. I don't see why colcon would not work. Make sure to source setup.bash
of ros before doing colcon.
Thanks for the help. Rtabmap now builds and runs with torch. Still don't understand the importance of recompiling pytorch, but it does the trick.
I cannot find the post, but someone said recently that it was because pytorch binaries were built with a different version of cpp library.
EDIT: found the post: https://github.com/introlab/rtabmap/issues/896#issuecomment-1602362071
Is there a known problem with compiling Rtabmap against ROS2 (humble) together with Torch? I've created a Dockerfile with the latest and greatest dependencies (as far as I could tell from reading a lot of issues and commits in this repo), nevertheless when I compile the rtabmap master branch with TORCH=ON I get a lot of linker errors (
undefined reference to...
). The rtabmap build configuration is copied below. It looks fine to me, but maybe it isn't.I would be very grateful for an Ubuntu 22 Dockerfile with ROS2 Humble installation inside that can successfully compile the Rtabmap master branch with Torch enabled.
Dockerfile
Build command
Start container while mapping rtabmap repo to
/root/ws/src/rtabmap
. call:source /opt/ros/humble/setup.bash
From the folder
/root/ws/src/rtabmap/build
call:or from the folder
/root/ws/src/
which besides rtabmap also could hold rtabmap_ros call:Output: Rtabmap build configuration:
Build error messages