alike-cpp 编译

1. 源码链接:

https://github.com/Shiaoming/ALIKE-cpp

2.已经安装好显卡驱动,cuda,cudnn,没安装的参考:

切记装cuda-11.x的版本,最好cuda11.3的版本

ubuntu重装系统后,安装cuda,cudnn-CSDN博客

3.安装opencv

下载所需要的版本,camke 安装即可

4.libtorch

官网给出了下载链接**(用这个最好)** :https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip

但是只支持cuda11.3的版本,由于系统是ubuntu 22.04,无法安装cuda11.3的版本,我这里是安装的cuda11.8的版本,需要pytorch的支持的版本也是11.8的,找到libtorch的下载网址:https://download.pytorch.org/libtorch/cu118,其他版本可参考:清华源和torch源_torch清华源-CSDN博客

将CMakeLists.txt中的torch路径指定到刚才下载的版本上:

set(Torch_DIR "/xx/libtorch/share/cmake/Torch")

然后开始编译:

mkdir build

cd build

cmake ..

make

编译完成后运行时报错:

terminate called after throwing an instance of 'c10::CUDAError' what(): CUDA error: an illegal memory access was encountered CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.

应该是torch版本不兼容,我下载的是torch2.0.0+cu118,应该用torch1.11.0+cu118,

这里不要用cuda12以上的版本,编译很浪费时间,直接换成cuda-11.x的版本,别问我怎么知道的

5.下载pytorch源码进行编译

参考:【libtorch】pytorch源码编译生成c++ 17 libtorch记录_libtorch编译-CSDN博客

(1)先下载pytorch源码,不要从官网下载source,里面third_party中的内容还要单独下载,直接用下面的命令下载:

复制代码
git clone https://github.com/pytorch/pytorch.git

(2)切换到libtorch版本对应tag

cd pytorch

git tag -l *1.11.0* // git tag查看版本,git tag -l搜索特定版本的tag

git checkout v1.11.0 // 切换到特定tag的代码

(3)更新所有显示modified的submodule

git submodule sync

git submodule update --init --recursive

(4)cmake 安装:

cd pytorch

mkdir build && cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/opt/libtorch -D CMAKE_CXX_STANDARD=17 -D CMAKE_CXX_STANDARD_REQUIRED=ON -D USE_CUDA=ON -D USE_CUDNN=ON -DCMAKE_CUDA_ARCHITECTURES=86 ..

make -j4

make install

将CMakeLists.txt中的torch路径指定到刚才编译的版本上即可:

set(Torch_DIR "/opt/libtorch/share/cmake/Torch")

(5)编译时提示:

可忽略,也可参考:cmake配置libtorch报错Failed to compute shorthash for libnvrtc.so-CSDN博客,在CMakeLists.txt最开始加上find_package(PythonInterp REQUIRED)

(6)运行: ./demo 图像文件夹目录 模型 --cuda

相关推荐
davidson14712 天前
gazebo仿真中对无人机集成的相机进行标定(VINS-Fusion)
ubuntu·无人机·slam·d435i·px4·gazebo·vins-fusion
听风吹雨yu2 天前
JY901-ROS2驱动代码
slam·ros2·humble·rviz·imu·foxy
火星机器人life8 天前
ubuntu20使用自主探索算法explore_lite实现机器人自主探索导航建图
slam
Perishell12 天前
无人机避障——感知部分(Ubuntu 20.04 复现Vins Fusion跑数据集)胎教级教程
无人机·slam·建图感知
xMathematics17 天前
ORB-SLAM2学习笔记:ORBextractor::operator()函数的逐行解析
人工智能·计算机视觉·机器人·无人机·slam
大鹅同志18 天前
ROS合集(七)SVIn2声呐模块分析
slam·sonar·rov·水下slam
清 澜19 天前
《三维点如何映射到图像像素?——相机投影模型详解》
计算机视觉·机器人·自动驾驶·slam·三维重建·三维视觉·投影变换
点云SLAM1 个月前
PCL点云库点云数据处理入门系列教材目录(2025年5月更新....)
计算机视觉·slam·点云配准·点云数据处理·pcl点云库·点云分割·点云识别
simple_whu1 个月前
Ubuntu24.04编译ORB_SLAM的一系列报错解决
ubuntu·slam
Livan.Tang1 个月前
LIO-SAM框架理解
人工智能·机器学习·slam