赞
踩
已有cuda11.4,eigen3.3.4,ros melodic,ceres 1.14,boost 1.65
注意:我没有尝试过cuda11.4+cuDnn8.4.1+tensorRT8.4.3是否可以,但是根据cuda和cudnn的对应、tensorRT8.4.3支持列表,其实是支持的。我是重新装了cuda。如果大家装了别的cuda11,可以先尝试一下。重装了cuda和cuDnn后要删除opencv的build文件夹,重新编译和安装。
1、cuda11.6(重装cuda之前要记得看nvidia驱动是否支持,不支持要重装驱动)
- #查看驱动版本和支持的cuda
- nvidia-smi
重装驱动我后续再写一篇。
卸载原来的cuda:
- cd /usr/local/cuda-xx.x/bin/ (进入你的cuda文件夹下)
- sudo ./cuda-uninstaller
- sudo rm -rf /usr/local/cuda-xx.x(删除cuda文件夹)
安装新的cuda:
CUDA Toolkit Archive | NVIDIA Developer
选择x86 ubuntu 18.04和runfile
我这里使用了run的方式,你也可以使用deb的方式。
- wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
- sudo sh cuda_11.6.2_510.47.03_linux.run
"x"表示选中,不要安装附带驱动,然后其他默认即可。
添加路径:
- gedit ~/.bashrc
- #输入
- export PATH=$PATH:/usr/local/cuda/bin
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
- export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
- #保存退出
- source ~/.bashrc
完成后使用nvcc -V查看版本。
2、cuDnn8.4.1
推荐deb安装,参考官方Installation Guide - NVIDIA Docs,下载链接:
cuDNN Archive | NVIDIA Developer
- sudo dpkg -i cudnn-local-repo-ubuntu1804-8.4.1.50_1.0-1_amd64.deb
- #根据提示导入KEY,不要复制
- sudo cp /var/cudnn-local-repo-*/cudnn-local-*-keyring.gpg /usr/share/keyrings/
-
- sudo apt-get update
- sudo apt-get install libcudnn8=8.4.1.50-1+cuda11.6
- sudo apt-get install libcudnn8-dev=8.4.1.50-1+cuda11.6
- sudo apt-get install libcudnn8-samples=8.4.1.50-1+cuda11.6
- #我有点不记得"="后面的版本号了,可以使用apt-cache查询,或者不指定
- sudo apt-get install libcudnn8
- sudo apt-get install libcudnn8-dev
- sudo apt-get install libcudnn8-samples
- sudo dpkg -l | grep cudnn
- #查看
3、opencv4.2(如果重装cuda,要重新编译安装)
sudo apt-get install build-essential cmake libjpeg-dev libtiff5-dev libpng-dev libavcodec-dev libavformat-dev libswscale-dev libxvidcore-dev libx264-dev libxine2-dev libv4l-dev v4l-utils libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgtk2.0-dev mesa-utils libgl1-mesa-dri libgtkgl2.0-dev libgtkglext1-dev libatlas-base-dev gfortran libeigen3-dev
下载opencv4.2和opencv-contrib-4.2,分别解压缩,opencv-contrib文件夹放进opencv-4.2文件夹中,我的显卡是2080Ti,所以bin是7.5
- mkdir build && cd build
-
- cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/uestc213/data/opencv-4.2.0/opencv_contrib/modules -DOPENCV_DNN_CUDA=ON -DWITH_CUDA=ON -DCUDA_ARCH_BIN=7.5 -DBUILD_TESTS=OFF -D BUILD_SHARED_LIBS=ON -D BUILD_STATIC_LIBS=ON ..
-
- make -j8
-
- sudo make install
4、g2o 20230223
- sudo apt install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5
- git clone https://github.com/RainerKuemmerle/g2o.git
- cd g2o
- mkdir build
- cd build
- cmake ..
- make -j8
- sudo make install
5、tensorRT8.4.2
下载需要注册账号
以下方法安装成功,但是我的c++项目编译不通过,找不到tensorRT。
sudo gedit ~/.bashrc 输入 export LD_LIBRARY_PATH=/home/213/TensorRT-8.4.3.1/lib:$LD_LIBRARY_PATH export LIBRARY_PATH=/home/213/TensorRT-8.4.3.1/lib::$LIBRARY_PATH 保存退出 source ~/.bashrc
# 安装后可使用python调用TensorRT cd TensorRT- 8.4.3.1/python pip3 install tensorrt-8.4.3.1-cp36-none-linux_x86_64.whl # 安装UFF,支持tensorflow模型转化,若使用pytorch可以不装 cd TensorRT- 8.4.3.1/uff pip3 install uff-0.6.9-py2.py3-none-any.whl # 安装graphsurgeon,支持自定义结构 cd TensorRT- 8.4.3.1/graphsurgeon pip3 install graphsurgeon-0.4.6-py2.py3-none-any.whl
用deb的方式:参考Installation Guide :: NVIDIA Deep Learning TensorRT DocumentationThis NVIDIA TensorRT 8.4.3 Installation Guide provides the installation requirements, a list of what is included in the TensorRT package, and step-by-step instructions for installing TensorRT.https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-843/install-guide/index.html#installing-debian首先要加入cuda11.6的deb(network),保证依赖验证通过
- wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
- sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
- sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub
- sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
- sudo apt-get update
- #如果安装过了cuda,这里就不要安装了。
- #sudo apt-get -y install cuda
然后下载tensorRT的deb
- #安装deb,这里的文件名,改为自己下载下来的,也可以tab补全
- sudo dpkg -i nv-tensorrt-repo-${os}-${tag}_1-1_amd64.deb
- sudo apt-key add /var/nv-tensorrt-repo-${os}-${tag}/*.pub
-
- sudo apt-get update
- sudo apt-get install tensorrt
- #我这里不与tensorflow使用,只安装我需要的
-
- python3 -m pip install numpy
- sudo apt-get install python3-libnvinfer-dev
- sudo apt-get install onnx-graphsurgeon
- sudo apt-get install tensorrt-libs
- sudo apt-get install tensorrt-dev
- #维持旧版cuda与tensorrt关联
- sudo apt-mark hold tensorrt-dev
-
- #可以取消
- sudo apt-mark unhold tensorrt-dev
6、glog
- git clone https://github.com/google/glog.git
- cd glog
- cmake -S . -B build -G "Unix Makefiles"
- cmake --build build
- cmake --build build --target test
- sudo cmake --build build --target install
7、ceres 2.0.0
可以直接去github下载压缩包,也可以
- git clone --branch 2.0.0 https://github.com/ceres-solver/ceres-solver.git
-
- cd ceres-solver
- mkdir build
- cd build
- #因为我已经装了一个ceres1.14,防止冲突,我重新设置路径
- sudo mkdir /usr/local/ceres2.0.0
- cmake -D CMAKE_INSTALL_PREFIX=/usr/local/ceres2.0.0 ..
- make -j8
- sudo make install
8、编译AIRVO
- mkdir -p airvo_ws/src
- cd airvo_ws/src/
- git clone https://github.com/sair-lab/AirVO.git
- cd ..
- catkin_make
- source devel/setup.bash
9、遇到的错误和修改
1......
- In file included from /usr/local/include/g2o/core/base_fixed_sized_edge.h:39:0,
- from /usr/local/include/g2o/core/base_binary_edge.h:30,
- from /usr/local/include/g2o/types/slam3d/types_slam3d.h:31,
- from /home/uestc213/data/airvio_ws/src/AirVO/include/utils.h:25,
- from /home/uestc213/data/airvio_ws/src/AirVO/src/camera.cc:4:
- /usr/local/include/g2o/stuff/tuple_tools.h: In function ‘void g2o::tuple_apply_i(F&&, T&, int)’:
- /usr/local/include/g2o/stuff/tuple_tools.h:45:35: error: ‘tuple_size_v’ is not a member of ‘std’
- std::make_index_sequence<std::tuple_size_v<std::decay_t<T>>>());
- ^~~~~~~~~~~~
- /usr/local/include/g2o/stuff/tuple_tools.h:45:35: note: suggested alternative: ‘tuple_size’
修改cmakelist中
set(CMAKE_CXX_STANDARD 14)
为
set(CMAKE_CXX_STANDARD 17)
2.......
error: ‘make_unique’ is not a member of ‘g2o’
auto linear_solver = g2o::make_unique<SlamLinearSolver>();
使用20230223版本的g2o
3.......
- /usr/local/include/g2o/core/base_variable_sized_edge.hpp:90:12: error: ‘class ceres::internal::FixedArray’ has no member named ‘fill’
- add_vi.fill(0.);
单独安装ceres2.0.0在/usr/local/ceres2.0.0中
cmakelist中指定
set(Ceres_DIR /usr/local/ceres2.0.0/lib/cmake/Ceres)
find_package(Ceres 2.0.0 REQUIRED)
include_directories( ${CERES_INCLUDE_DIRS} )
target_link_libraries( ${CERES_LIBRARIES} )
4.....
如果是ubuntu18.04,还需要编译一个cv_bridge,否则容易运行报错
可以参考最后一部分,opencv4的cv_bridge部分
5....
编译可以通过,但是在运行时崩溃,提示libg2o_opengl_helper.so找不到,
用ldd devel/lib/libair_vo_lib.so | grep g2o,可以看到这个动态链接库找不到。
此时如果你的g2o安装路径是默认的,在/usr/local中,则使用sudo ldconfig,然后重新编译airvo即可。如果有不一样的安装路径,如多版本共存,则需要修改FindG2O.cmake文件,在AirVO的cmake文件夹中。添加上你的安装路径中的include和lib,然后在/etc/ld.so.conf.d/libc.conf文件中增加你的安装路径。再执行sudo ldconfig,再重新编译AirVO。
10、运行
- source devel/setup.bash
- roslaunch air_vo oivio.launch
-
- roslaunch air_vo uma_bumblebee_indoor.launch
-
- roslaunch air_vo euroc.launch
-
- roslaunch air_vo euroc_ros.launch
附、onnxruntime 1.12.1
这个我没有安装,但是可以运行。
根据NVIDIA - TensorRT | onnxruntime和NVIDIA - CUDA | onnxruntime
- https://github.com/microsoft/onnxruntime.git
- cd onnxruntime
- git checkout v1.12.1
- git submodule update --init --recursive
- ./build.sh --skip_tests --config Release --build_shared_lib
- ./build.sh --skip_tests --use_cuda --config Release --build_shared_lib --parallel --cuda_home /usr/local/cuda --cudnn_home /usr/local/cuda
- ./build.sh --build_shared_lib --skip_tests --config Release --use_cuda --cudnn_home /usr/local/cuda --cuda_home /usr/local/cuda --use_tensorrt --tensorrt_home /home/213/TensorRT-8.4.3.1
- 进入
- /home/uestc213/onnxruntime/build/Linux/Release
- 然后sudo make install
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。