配置 GCNv2_SLAM 所需环境并实现 AutoDL 云端运行项目的全过程记录。

1. 引子

前几天写了一篇在本地虚拟机里面 CPU 运行 GCNv2_SLAM 项目的博客:链接,关于 GCNv2_SLAM 项目相关的介绍请移步此文章,本文不再重复说明。

在之前的测试中,本地虚拟机 CPU 运行的效果非常差,推理速度只有可怜兮兮的 0.5 HZ,但是我手头又没有带显卡的环境,所以想到了可以去网上租个带显卡的容器化环境。

AutoDL 就是一个租 GPU 环境的平台: https://www.autodl.com/,而且 autodl 租显卡是可以按小时付费的,比按月付费的更加划算,更好过自己买个显卡在本地倒腾 ubuntu 环境,所以就直接开整了!

先注册一个 AutoDL 的账户,给里面充值一丢丢钱,然后就可以租一个显卡容器化环境来运行 GCNv2_SLAM 啦!

image.png

2. AutoDL 环境选择

老版本 PyTorch 的镜像由于 4090 无法使用太低的 cuda 版本导致无法选择,如果需要使用更低版本的 pytorch 镜像,则需要租用 2080ti 或者 1080ti 显卡的环境。

2080ti 显卡可以选择如下环境,实测可用:

plaintext
1
2
3
PyTorch  1.5.1
Python 3.8(ubuntu18.04)
Cuda 10.1

image.png

创建环境后,建议使用左侧的 ssh 登录指令直接在本地终端里面执行,登录到云端。如果你没有本地的 ssh 终端,也可以点击 JupyterLab 里面的终端来运行命令。

image.png

后文涉及到下载很多文件,如果从 github 下载很慢,可以在本地下好之后通过 JupyterLab 传到云端去。注意传文件之前要先在文件列表里面选好目标的目录。

image.png

还可以尝试 autodl 自带的代理:www.autodl.com/docs/network_turbo/,但是慕雪试用的时候这个代理一直返回 503,不可用状态。

3. 依赖安装

3.1. 需要的 apt 包安装

运行之前先更新一下环境,这部分操作和在本地虚拟机里面安装环境都是一样的。

bash
1
2
sudo apt-get update -y
sudo apt-get upgrade -y

更新的时候会有一个新的 sshd 配置的提醒,这里直接选择 1 用新版本配置就可以了

plaintext
1
2
3
4
5
6
7
8
A new version (/tmp/file1bBLK4) of configuration file /etc/ssh/sshd_config is available, but the version installed currently has been
locally modified.

1. install the package maintainer's version 5. show a 3-way difference between available versions
2. keep the local version currently installed 6. do a 3-way merge between available versions
3. show the differences between the versions 7. start a new shell to examine the situation
4. show a side-by-side difference between the versions
What do you want to do about modified configuration file sshd_config? 1

因为选了 Pytorch 镜像,Python 工具组系统已经自带了,不需要安装。

安装要用的到的工具包

bash
1
2
3
4
5
6
7
8
# 工具包
sudo apt-get install -y \
apt-utils \
curl wget unzip zip \
cmake make automake \
openssh-server \
net-tools \
vim git gcc g++

安装 x11 相关的依赖包

bash
1
2
3
4
5
6
7
8
# x11 for gui
sudo apt-get install -y \
libx11-xcb1 \
libfreetype6 \
libdbus-1-3 \
libfontconfig1 \
libxkbcommon0 \
libxkbcommon-x11-0

3.2. Pangolin-6.0

3.2.1. 依赖项安装

安装 Pangolin 之前先安装如下依赖包

bash
1
2
3
4
5
6
7
8
9
# pangolin
sudo apt-get install -y \
libgl1-mesa-dev \
libglew-dev \
libboost-dev \
libboost-thread-dev \
libboost-filesystem-dev \
libpython2.7-dev \
libglu1-mesa-dev freeglut3-dev

在 AutoDL 的 PyTorch 1.5.1 镜像中,安装 Pangolin 依赖包的时候的终端输出如下,出现了依赖项版本冲突问题。

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@autodl-container-e39d46b8d3-01da7b14:~# apt-get install -y     libgl1-mesa-dev     libglew-dev     libboost-dev     libboost-thread-dev     libboost-filesystem-dev     libpython2.7-dev     libglu1-mesa-dev freeglut3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
freeglut3-dev : Depends: libxext-dev but it is not going to be installed
Depends: libxt-dev but it is not going to be installed
libgl1-mesa-dev : Depends: mesa-common-dev (= 20.0.8-0ubuntu1~18.04.1) but it is not going to be installed
Depends: libx11-dev but it is not going to be installed
Depends: libx11-xcb-dev but it is not going to be installed
Depends: libxdamage-dev but it is not going to be installed
Depends: libxext-dev but it is not going to be installed
Depends: libxfixes-dev but it is not going to be installed
Depends: libxxf86vm-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

这里依赖冲突的问题是安装的 x11 依赖包有两个版本过高了,需要降级下面这两个依赖包。如果你安装依赖项时没有出现依赖项冲突就成功安装了,则不需要执行下面的降级命令

bash
1
2
3
apt-get install -y \
libx11-xcb1=2:1.6.4-3ubuntu0.4 \
libx11-6=2:1.6.4-3ubuntu0.4

降级成功后,重新执行上述安装 Pangolin 依赖项的命令,就能成功安装了。

image.png

3.2.2. 编译安装

随后使用如下命令来编译安装 Pangolin,Github 地址:Pangolin-0.6

建议这些依赖包都进入 ~/autodl-tmp 数据盘来下载和安装,这样即便后续需要更换镜像也能保留数据,不需要重新下载

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 下载
wget -O Pangolin-0.6.tar.gz https://github.com/stevenlovegrove/Pangolin/archive/refs/tags/v0.6.tar.gz
# 解压
tar -zxvf Pangolin-0.6.tar.gz

pushd Pangolin-0.6
rm -rf build
mkdir build && cd build
# 编译安装
cmake -DCPP11_NO_BOOST=1 ..
make -j$(nproc)
make install
# 刷新动态库
ldconfig
popd

编译安装成功

image.png

示例代码 HelloPangolin 也能编译成功,只不过当前我们还没有配置 GUI,所以会有 x11 错误无法运行(后文会讲述如何配置 GUI 和 VNC)

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/Pangolin-0.6/build# cd ../examples/HelloPangolin
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/Pangolin-0.6/examples/HelloPangolin# mkdir build && cd build
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/Pangolin-0.6/examples/HelloPangolin/build# cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 3.10)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.

-- Configuring done
CMake Warning (dev) at CMakeLists.txt:5 (add_executable):
Policy CMP0003 should be set before this line. Add code such as

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

as early as possible but after the most recent call to
cmake_minimum_required or cmake_policy(VERSION). This warning appears
because target "HelloPangolin" links to some libraries for which the linker
must search:

rt, pthread, rt, pthread

and other libraries with known full path:

/usr/local/lib/libpangolin.so

CMake is adding directories in the second list to the linker search path in
case they are needed to find libraries from the first list (for backwards
compatibility with CMake 2.4). Set policy CMP0003 to OLD or NEW to enable
or disable this behavior explicitly. Run "cmake --help-policy CMP0003" for
more information.
This warning is for project developers. Use -Wno-dev to suppress it.

-- Generating done
-- Build files have been written to: /root/pkg/Pangolin-0.6/examples/HelloPangolin/build
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/Pangolin-0.6/examples/HelloPangolin/build# make
Scanning dependencies of target HelloPangolin
[ 50%] Building CXX object CMakeFiles/HelloPangolin.dir/main.o
[100%] Linking CXX executable HelloPangolin
[100%] Built target HelloPangolin
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/Pangolin-0.6/examples/HelloPangolin/build# ./HelloPangolin
terminate called after throwing an instance of 'std::runtime_error'
what(): Pangolin X11: Failed to open X display
Aborted (core dumped)

3.3. OpenCV 3.4.5

先安装依赖项

bash
1
2
3
4
5
sudo apt-get install -y \
build-essential libgtk2.0-dev \
libavcodec-dev libavformat-dev \
libjpeg.dev libtiff5.dev libswscale-dev \
libcanberra-gtk-module

因为 AutoDL 环境是 amd64,所以直接用下面的命令安装 libjasper 就 OK 了,不需要额外的处理

bash
1
2
3
4
5
# amd64 添加新源后继续安装
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt-get -y update
sudo apt-get install -y libjasper1 libjasper-dev

以下是安装 libjasper 的截图

image.png

安装好了依赖项后,使用如下命令编译 opencv,Github 地址:opencv 的 3.4.5 版本

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 下载和解压
wget -O opencv-3.4.5.tar.gz https://github.com/opencv/opencv/archive/refs/tags/3.4.5.tar.gz
tar -zxvf opencv-3.4.5.tar.gz
# 开始编译和安装
pushd opencv-3.4.5
rm -rf build
mkdir build && cd build
# 构建和编译安装,-j4代表4线程并发
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j$(nproc)
make install
# 刷新动态库
ldconfig
popd

正常编译安装,莫得问题

image.png

3.4. Eigen 3.7

Eigen 包在 gitlab 里面下载:gitlab.com/libeigen/eigen/-/releases/3.3.7

bash
1
2
3
4
5
6
7
8
9
10
# 下载
wget -O eigen-3.3.7.tar.gz https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
tar -zxvf eigen-3.3.7.tar.gz
# 开始编译和安装
cd eigen-3.3.7
mkdir build && cd build
cmake ..
make && make install
# 拷贝路径(避免头文件引用不到)
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include

还是用相同的 cpp 的 demo 代码来测试是否安装成功(直接 g++ 编译就可以了)

cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
//需要将头文件从 /usr/local/include/eigen3/ 复制到 /usr/local/include
#include <Eigen/Dense>
//using Eigen::MatrixXd;
using namespace Eigen;
using namespace Eigen::internal;
using namespace Eigen::Architecture;
using namespace std;
int main()
{
cout<<"*******************1D-object****************"<<endl;
Vector4d v1;
v1<< 1,2,3,4;
cout<<"v1=\n"<<v1<<endl;

VectorXd v2(3);
v2<<1,2,3;
cout<<"v2=\n"<<v2<<endl;

Array4i v3;
v3<<1,2,3,4;
cout<<"v3=\n"<<v3<<endl;

ArrayXf v4(3);
v4<<1,2,3;
cout<<"v4=\n"<<v4<<endl;
}

正常编译运行

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/eigen-3.3.7/build# g++ test.cpp -o t
root@autodl-container-e39d46b8d3-01da7b14:~/pkg/eigen-3.3.7/build# ./t
*******************1D-object****************
v1=
1
2
3
4
v2=
1
2
3
v3=
1
2
3
4
v4=
1
2
3

3.5. Libtorch 1.5.0

3.5.1. 关于手工编译的说明

因为我们选择的 autodl 环境里面已经带了 Pytorch 了,所以可以不需要自己手动从源码构建了。

我尝试过从源码构建 pytorch 1.1.0 版本,会在构建的半路被 killed 掉,不清楚问题在哪里,猜测是构建占用内存 cpu 过多导致的,当时被 kill 掉的输出如下,大约在 74% 的时候,前后都没有出现 error,就直接被干掉了。

image.png
image.png

3.5.2. 不能使用本地已有的版本

我们选用的 autodl 镜像里面其实已经自带了一个可用的 Torch 目录,路径如下所示

plaintext
1
/root/miniconda3/lib/python3.8/site-packages/torch/share/cmake/Torch

但是这个目录中引用的 libtorch 预编译版本是不包含 C++11ABI 兼容机制的,会最终导致 Pangolin 链接失败,错误输出如下所示。这个链接失败的问题和使用的 Pangolin 版本没有关系,尝试过 Pangolin5.0 和 6.0 都会链接失败。

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[100%] Linking CXX executable ../GCN2/rgbd_gcn
../lib/libORB_SLAM2.so: undefined reference to `pangolin::Split(std::string const&, char)'
../lib/libORB_SLAM2.so: undefined reference to `pangolin::CreatePanel(std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `DBoW2::FORB::fromString(cv::Mat&, std::string const&)'
../lib/libORB_SLAM2.so: undefined reference to `pangolin::BindToContext(std::string)'
../lib/libORB_SLAM2.so: undefined reference to `DBoW2::FORB::toString(cv::Mat const&)'
../lib/libORB_SLAM2.so: undefined reference to `pangolin::CreateWindowAndBind(std::string, int, int, pangolin::Params const&)'
collect2: error: ld returned 1 exit status
CMakeFiles/rgbd_gcn.dir/build.make:152: recipe for target '../GCN2/rgbd_gcn' failed
make[2]: *** [../GCN2/rgbd_gcn] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/rgbd_gcn.dir/all' failed
make[1]: *** [CMakeFiles/rgbd_gcn.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

在 GCNv2 的 GITHUB 中是有提到这个问题的,翻译过来就是不要使用预编译版本的 libtorch,因为会出现 CXX11 ABI 导致的连接错误。

image.png

在 Pytroch 1.3.0 之后的版本,官方就已经提供了带 CXX11 ABI 兼容的预编译版本了,所以可以下载预编译包之后来使用。直接使用容器内的 libtorch 依旧会有链接问题。

3.5.3. 下载预编译版本

最开始我选择的就是 pytorch1.1.0 版本的镜像,但是由于没办法从源码编译所以切换成了 pytorch1.5.1 的镜像。因为在 pytorch1.3.0 之后官方才提供了 CXX11 ABI 兼容的预编译包,在这之前的版本都需要手工编译,否则会有链接错误。

我们需要做的操作是从官网上下一个带 CXX11 ABI 兼容的 libtorch 预编译包,下载地址中包含 cxx11-abi 的才是带有 CXX11 ABI 兼容的。1.5.0 版本的 libtorch 包下载地址如下,其中 cu101 代表 cuda10.1,最后的 libtorch 版本是 1.5.0(libtorch 1.5.1 版本的包下不了)

plaintext
1
https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.5.0.zip

直接通过 unzip 解压这个目录,就能得到一个 libtorch 文件夹,后文需要的 TORCH_PATH 在 libtorch 的 libtorch/share/cmake/Torch 目录中就有:

plaintext
1
2
root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp# ls libtorch/share/cmake/Torch
TorchConfig.cmake TorchConfigVersion.cmake

预编译的 libtorch 包容量都挺大的,建议本地提前下好然后上传到 autodl 里面,在 autodl 里面直接下载太耗时了,都是钱呐!

image.png

4. 编译 GCNv2_SLAM

上正主了,克隆一下代码

bash
1
git clone https://github.com/jiexiong2016/GCNv2_SLAM.git

因为这次是在 autodl 环境中跑,有了显卡,pytorch 的版本和之前的博客中的完全不一样,所以需要修改的代码内容也不一样。可以参考博客 GCNv2_SLAM-CPU 详细安装教程 (ubuntu18.04)-CSDN 博客 中的说明进行修改。

4.1. 修改 build.sh

预编译版本的 TORCH_PATH 在压缩包解压后 libtorch 目录中,即 libtorch/share/cmake/Torch 目录。修改 build.sh 脚本中的路径为此目录就可以了

plaintext
1
-DTORCH_PATH=/root/autodl-tmp/libtorch/share/cmake/Torch

修改之后就可以开始编译,并根据报错来解决后面的一些问题了

4.2. 修改代码兼容高版本 libtorch

这部分修改可以在我的 Github 仓库中找到:github.com/musnows/GCNv2_SLAM/tree/pytorch1.5.0

4.2.1. C++14 编译配置

初次运行会出现如下错误,高版本的 torch 需要 C++14 来编译,因为用到了 14 的新特性

plaintext
1
2
3
/root/autodl-tmp/libtorch/include/c10/util/C++17.h:27:2: error: #error You need C++14 to compile PyTorch
27 | #error You need C++14 to compile PyTorch
| ^~~~~

需要我们修改 camke 文件,修改 GCNv2_SLAM/CMakeLists.txt,新增如下内容

cmake
1
2
3
4
5
6
# 头部插入
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 修改尾部的11为14
# set_property(TARGET rgbd_gcn PROPERTY CXX_STANDARD 11)
set_property(TARGET rgbd_gcn PROPERTY CXX_STANDARD 14)

然后还需要注释掉和 C++11 判断相关的 cmake 配置,也就是下面这一堆

cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#Check C++11 or C++0x support
#include(CheckCXXCompilerFlag)
#CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
#CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
#if(COMPILER_SUPPORTS_CXX11)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
# message(STATUS "Using flag -std=c++11.")
#elseif(COMPILER_SUPPORTS_CXX0X)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
# add_definitions(-DCOMPILEDWITHC0X)
# message(STATUS "Using flag -std=c++0x.")
#else()
# message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
#endif()

其中 add_definitions(-DCOMPILEDWITHC11) 不要注释掉,有用!

修改 cmake 后需要删除 GCNv2_SLAM/build 目录重新运行 build.sh 脚本,否则修改可能不会生效。

4.2.2. 缺少对应的 operator=

报错如下

plaintext
1
2
3
4
5
6
7
8
9
10
11
/root/autodl-tmp/GCNv2_SLAM/src/GCNextractor.cc: In constructor ‘ORB_SLAM2::GCNextractor::GCNextractor(int, float, int, int, int)’:
/root/autodl-tmp/GCNv2_SLAM/src/GCNextractor.cc:218:37: error: no match for ‘operator=’ (operand types are ‘std::shared_ptr<torch::jit::Module>’ and ‘torch::jit::Module’)
module = torch::jit::load(net_fn);
^
In file included from /usr/include/c++/7/memory:81:0,
from /root/miniconda3/lib/python3.8/site-packages/torch/include/c10/core/Allocator.h:4,
from /root/miniconda3/lib/python3.8/site-packages/torch/include/ATen/ATen.h:3,
from /root/miniconda3/lib/python3.8/site-packages/torch/include/torch/csrc/api/include/torch/types.h:3,
from /root/miniconda3/lib/python3.8/site-packages/torch/include/torch/script.h:3,
from /root/autodl-tmp/GCNv2_SLAM/include/GCNextractor.h:24,
from /root/autodl-tmp/GCNv2_SLAM/src/GCNextractor.cc:63:

问题主要是 torch::jit::Module 入参不再是一个指针了,所以要把 shared_ptr 给改成普通对象。

修改 GCNv2_SLAM/include/GCNextractor.h 文件的 99 行:

cpp
1
2
3
4
//原代码
std::shared_ptr<torch::jit::script::Module> module;
//更改为
torch::jit::script::Module module;

还需要对应修改 GCNv2_SLAM/src/GCNextractor.cc 的 270 行:

cpp
1
2
3
4
//原代码
auto output = module->forward(inputs).toTuple();
//更改为
auto output = module.forward(inputs).toTuple();

4.2.3. 标准库 chrono 编译问题

如果你的 cmake 修改不对,还可能会遇到 chrono 导致的编译报错

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc: In function ‘int main(int, char**)’:
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:97:22: error: ‘std::chrono::monotonic_clock’ has not been declared
std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
^~~~~~~~~~~~~~~
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:106:22: error: ‘std::chrono::monotonic_clock’ has not been declared
std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
^~~~~~~~~~~~~~~
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:109:84: error: ‘t2’ was not declared in this scope
double ttrack = std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
^~
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:109:84: note: suggested alternative: ‘tm’
double ttrack = std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
^~
tm
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:109:89: error: ‘t1’ was not declared in this scope
double ttrack = std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
^~
/root/autodl-tmp/GCNv2_SLAM/GCN2/rgbd_gcn.cc:109:89: note: suggested alternative: ‘tm’
double ttrack = std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();
^~
tm
^CCMakeFiles/rgbd_gcn.dir/build.make:62: recipe for target 'CMakeFiles/rgbd_gcn.dir/GCN2/rgbd_gcn.cc.o' failed
make[2]: *** [CMakeFiles/rgbd_gcn.dir/GCN2/rgbd_gcn.cc.o] Interrupt
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/rgbd_gcn.dir/all' failed
make[1]: *** [CMakeFiles/rgbd_gcn.dir/all] Interrupt
Makefile:83: recipe for target 'all' failed
make: *** [all] Interrupt

错误的主要含义就是 std::chrono::monotonic_clock 不存在,这是老版本的一个类,C++11 新版本已经给它删掉了。查看 GCN2/rgbd_gcn.cc 代码可以发现,这里有宏定义来区分

cpp
1
2
3
4
5
6
// GCNv2_SLAM/GCN2/rgbd_gcn.cc
#ifdef COMPILEDWITHC11
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
#else
std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
#endif

前文提到的 GCNv2_SLAM/CMakeLists.txt 中需要保留 add_definitions(-DCOMPILEDWITHC11) 就是这个原因。有了这个宏定义此处代码就会编译 std::chrono::steady_clock,不会有编译错误了。

4.2.4. 修改 PT 文件

依旧需要修改 3 个 pt 文件,注意这时候修改的内容和 CPU 运行不一样!

修改 GCNv2_SLAM/GCN2 下 gcn2_320x240.pt、gcn2_640x480.pt 和 gcn2_tiny_320x240.pt 中的内容。需要先解压文件

bash
1
unzip gcn2_320x240.pt

解压出来之后会有 GCNv2_SLAM/GCN2/gcn/code/gcn.py 文件,这里的 grid_sampler 函数在 pytorch 1.3.0 之前是默认传入 True 的,1.3.0 改成默认 False 了,所以需要手动传入 True

python
1
2
3
4
# 原代码
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0))
# 修改为
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0, True))

替换了之后,重新压缩 pt 文件,先删了原本的,重新压缩

bash
1
2
3
rm -rf gcn2_320x240.pt
zip -r gcn2_320x240.pt gcn
rm -rf gcn #删除刚刚的gcn文件夹

这只是一个例子,其他几个 gcn2 压缩包都要用相同的方式修改!

bash
1
2
3
4
5
6
7
unzip gcn2_640x480.pt
rm -rf gcn2_640x480.pt
# 修改下面这个文件
# GCNv2_SLAM/GCN2/gcn2_480x640/code/gcn2_480x640.py
# 重新压缩
zip -r gcn2_640x480.pt gcn2_480x640
rm -rf gcn2_480x640
bash
1
2
3
4
5
6
7
unzip gcn2_tiny_320x240.pt
rm -rf gcn2_tiny_320x240.pt
# 修改文件
# gcnv2slam/GCNv2_SLAM/GCN2/gcn2_tiny/code/gcn2_tiny.py
# 重新压缩
zip -r gcn2_tiny_320x240.pt gcn2_tiny
rm -rf gcn2_tiny

4.3. 编译项目

修改了上面提到的几处问题,就能正常编译成功了

image.png

如果需要从头重新编译项目,需要删除 build 目录缓存。

bash
1
2
3
4
rm -rf Thirdparty/g2o/build/
rm -rf Thirdparty/DBoW2/build/
rm -rf Vocabulary/*.bin
rm -rf ./build

5. 配置 VNC 环境

5.1. 安装 VNC 服务端

默认情况下 autodl 是没有 GUI 环境的,也就没有办法运行项目(会有 x11 报错)

所以我们需要依照官方文档来配置一下 GUI:www.autodl.com/docs/gui/

bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 安装基本的依赖包
apt update && apt install -y libglu1-mesa-dev mesa-utils xterm xauth x11-xkb-utils xfonts-base xkb-data libxtst6 libxv1

# 安装libjpeg-turbo和turbovnc
export TURBOVNC_VERSION=2.2.5
export LIBJPEG_VERSION=2.0.90
wget http://aivc.ks3-cn-beijing.ksyun.com/packages/libjpeg-turbo/libjpeg-turbo-official_${LIBJPEG_VERSION}_amd64.deb
wget http://aivc.ks3-cn-beijing.ksyun.com/packages/turbovnc/turbovnc_${TURBOVNC_VERSION}_amd64.deb
dpkg -i libjpeg-turbo-official_${LIBJPEG_VERSION}_amd64.deb
dpkg -i turbovnc_${TURBOVNC_VERSION}_amd64.deb
rm -rf *.deb

# 启动VNC服务端,这一步可能涉及vnc密码配置(注意不是实例的账户密码)。另外如果出现报错xauth未找到,那么使用apt install xauth再安装一次
rm -rf /tmp/.X1* # 如果再次启动,删除上一次的临时文件,否则无法正常启动
USER=root /opt/TurboVNC/bin/vncserver :1 -desktop X -auth /root/.Xauthority -geometry 1920x1080 -depth 24 -rfbwait 120000 -rfbauth /root/.vnc/passwd -fp /usr/share/fonts/X11/misc/,/usr/share/fonts -rfbport 6006

# 检查是否启动,如果有vncserver的进程,证明已经启动
ps -ef | grep vnc | grep -v grep

启动 vnc 服务端会让你输入密码,为了方便我直接用了 autodl 实例的密码。只读密码 view-only password 选择 n 不设置。

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@autodl-container-e39d46b8d3-01da7b14:~/vnc]$ USER=root /opt/TurboVNC/bin/vncserver :1 -desktop X -auth /root/.Xauthority -geometry 1920x1080 -depth 24 -rfbwait 120000 -rfbauth /root/.vnc/passwd -fp /usr/share/fonts/X11/misc/,/usr/share/fonts -rfbport 6006

You will require a password to access your desktops.

Password:
Warning: password truncated to the length of 8.
Verify:
Would you like to enter a view-only password (y/n)? n
xauth: file /root/.Xauthority does not exist

Desktop 'TurboVNC: autodl-container-e39d46b8d3-01da7b14:1 (root)' started on display autodl-container-e39d46b8d3-01da7b14:1

Creating default startup script /root/.vnc/xstartup.turbovnc
Starting applications specified in /root/.vnc/xstartup.turbovnc
Log file is /root/.vnc/autodl-container-e39d46b8d3-01da7b14:1.log

启动 vnc 服务端后就能搜到进程了

plaintext
1
2
root@autodl-container-e39d46b8d3-01da7b14:~/vnc# ps -ef | grep vnc | grep -v grep
root 28861 1 0 11:22 pts/0 00:00:00 /opt/TurboVNC/bin/Xvnc :1 -desktop TurboVNC: autodl-container-64eb44b6f5-c569ba8d:1 (root) -httpd /opt/TurboVNC/bin//../java -auth /root/.Xauthority -geometr

如果关闭了实例之后需要重启 vnc,执行这两个命令就行了

bash
1
2
rm -rf /tmp/.X1*  # 如果再次启动,删除上一次的临时文件,否则无法正常启动
USER=root /opt/TurboVNC/bin/vncserver :1 -desktop X -auth /root/.Xauthority -geometry 1920x1080 -depth 24 -rfbwait 120000 -rfbauth /root/.vnc/passwd -fp /usr/share/fonts/X11/misc/,/usr/share/fonts -rfbport 6006

5.2. 本地端口绑定

随后还需要进行本地 ssh 端口绑定,先到 autodl 的控制台实例列表里面复制一下 ssh 链接命令,应该长这样

bash
1
ssh -p 端口号 root@域名

使用下面这个命令在本地的终端运行,就能实现把远程的端口绑定到本地的 6006 端口了

bash
1
ssh -CNgv -L 6006:127.0.0.1:6006 root@域名 -p 端口号

如果命令正确,输入这个命令后会让你键入 autodl 实例的密码,在控制台里面复制然后 ctrl+shift+v(command+v)粘贴就行了。

期间需要保持这个终端一直开启,不然转发会终止。

5.3. 链接 VNC

这里我使用了祖传的 VNC Viewer 来连云端,全平台都有客户端,下载安装就可以了。

安装了之后,直接在顶栏输入 127.0.0.1:6006 来链接云端。

image.png

如果提示 connection closed 大概率是 vnc 服务没有正常安装或者端口转发没有成功,请重试上述步骤。顺利的话,就会弹出来让你输入密码。

这里的密码是启动 vnc 服务端时设置的密码,根据你设置的密码输入就行。

链接成功,会是黑屏,正常情况

image.png

5.4. 测试 VNC 是否安装成功

我们可以用 Pangolin 的示例程序来试试有没有配置成功

bash
1
2
3
4
cd Pangolin-0.6/examples/HelloPangolin
mkdir build && cd build
cmake ..
make

编译完成之后需要先执行 export DISPLAY=:1 启用 GUI 再启动需要 GUI 的程序

bash
1
2
export DISPLAY=:1
./HelloPangolin

如果没有 export 直接启动,还是会报错

plaintext
1
2
3
4
root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp/Pangolin-0.6/examples/HelloPangolin/build# ./HelloPangolin 
terminate called after throwing an instance of 'std::runtime_error'
what(): Pangolin X11: Failed to open X display
Aborted (core dumped)

export 了环境变量之后就能正常启动,且 VNC 里面也能看到画面了

plaintext
1
2
root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp/Pangolin-0.6/examples/HelloPangolin/build# export DISPLAY=:1
root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp/Pangolin-0.6/examples/HelloPangolin/build# ./HelloPangolin

出现下面这个魔方就是安装 VNC 成功啦

image.png

你也可以编译 opencv 的 demo 来测试 vnc 是否正常

bash
1
2
3
4
5
6
7
cd opencv-3.4.5/samples/cpp/example_cmake
mkdir build && cd build
cmake ..
make
# 导入环境变量之后再启动
export DISPLAY=:1
./opencv_example

如果正常,vnc 里面会出现一个 hello opencv,因为没有摄像头所以是黑屏

image.png

6. 运行 GCNv2_SLAM 分析 TUM 数据集

接下来就可以运行项目了,还是去下载 TUM 数据集,这里把之前博客的命令 copy 过来。

6.1. 下载数据集

下载地址:cvg.cit.tum.de/data/datasets/rgbd-dataset/download

下载 fr1/desk 数据集,这是一个桌子的 RGBD 数据

image.png

在 GCNv2_SLAM 工程下新建 datasets/TUM, 将数据集下载到其中

bash
1
2
3
4
5
6
7
# 新建datasets/TUM数据集文件夹
mkdir -p datasets/TUM
cd datasets/TUM
# 下载数据集到datasets/TUM文件夹内
wget -O rgbd_dataset_freiburg1_desk.tgz https://cvg.cit.tum.de/rgbd/dataset/freiburg1/rgbd_dataset_freiburg1_desk.tgz
# 解压数据集
tar -xvf rgbd_dataset_freiburg1_desk.tgz

然后还需要下载一个 associate.py 脚本来处理一下数据集才能正常运行

下载地址:svncvpr.in.tum.de,同时在我的 Github 仓库也做了留档。

plaintext
1
wget -O associate.py https://svncvpr.in.tum.de/cvpr-ros-pkg/trunk/rgbd_benchmark/rgbd_benchmark_tools/src/rgbd_benchmark_tools/associate.py

这个脚本只能用 python2 运行,需要下载 numpy 库。注意 autodl 的环境中 python 绑定到了 python3,环境中的 python2 被拦掉了,所以需要安装独立的 python2 命令来运行 python2。

在 Pytorch1.5.1 版本的 autodl 镜像中,可以直接使用下面的命令来安装 python2 和 pip2:

bash
1
apt-get install -y python-dev python-pip

随后安装 numpy 库就 ok 了

plaintext
1
2
3
4
5
6
7
8
root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp/GCNv2_SLAM/datasets/TUM# pip2 install numpy
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Looking in indexes: http://mirrors.aliyun.com/pypi/simple
Collecting numpy
Downloading http://mirrors.aliyun.com/pypi/packages/3a/5f/47e578b3ae79e2624e205445ab77a1848acdaa2929a00eeef6b16eaaeb20/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl (17.0 MB)
|████████████████████████████████| 17.0 MB 21.1 MB/s
Installing collected packages: numpy
Successfully installed numpy-1.16.6

执行脚本来处理两个文件,在数据文件夹里执行命令

bash
1
python2 associate.py rgbd_dataset_freiburg1_desk/rgb.txt rgbd_dataset_freiburg1_desk/depth.txt > rgbd_dataset_freiburg1_desk/associate.txt

执行 python 命令后可以看看合并成功了没有,如下应该就是没问题了。

plaintext
1
2
3
1305031472.895713 rgb/1305031472.895713.png 1305031472.892944 depth/1305031472.892944.png
1305031472.927685 rgb/1305031472.927685.png 1305031472.924814 depth/1305031472.924814.png
1305031472.963756 rgb/1305031472.963756.png 1305031472.961213 depth/1305031472.961213.png

在同一个网站下载的其他 TUM 数据集也需要用相同的方式进行处理

6.2. 运行项目

随后进入项目的 GCN2 目录执行命令,我把命令中的路径都改成了相对路径

bash
1
2
3
4
5
# 注意需要导入vnc环境变量
export DISPLAY=:1
# 运行项目
cd GCN2
GCN_PATH=gcn2_320x240.pt ./rgbd_gcn ../Vocabulary/GCNvoc.bin TUM3_small.yaml ../datasets/TUM/rgbd_dataset_freiburg1_desk ../datasets/TUM/rgbd_dataset_freiburg1_desk/associate.txt

项目能正常运行,VNC 中也有图像输出

image.png

运行结束后的输出如下

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[root@autodl-container-e39d46b8d3-01da7b14:~/autodl-tmp/GCNv2_SLAM/GCN2]$ GCN_PATH=gcn2_320x240.pt ./rgbd_gcn ../Vocabulary/GCNvoc.bin TUM3_small.yaml ../datasets/TUM/rgbd_dataset_freiburg1_desk ../datasets/TUM/rgbd_dataset_freiburg1_desk/associate.txt

ORB-SLAM2 Copyright (C) 2014-2016 Raul Mur-Artal, University of Zaragoza.
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
under certain conditions. See LICENSE.txt.

Input sensor was set to: RGB-D

Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!


Camera Parameters:
- fx: 267.7
- fy: 269.6
- cx: 160.05
- cy: 123.8
- k1: 0
- k2: 0
- p1: 0
- p2: 0
- fps: 30
- color order: RGB (ignored if grayscale)

ORB Extractor Parameters:
- Number of Features: 1000
- Scale Levels: 8
- Scale Factor: 1.2
- Initial Fast Threshold: 20
- Minimum Fast Threshold: 7

Depth Threshold (Close/Far Points): 5.97684

-------
Start processing sequence ...
Images in the sequence: 573

Framebuffer with requested attributes not available. Using available framebuffer. You may see visual artifacts.New map created with 251 points
Finished!
-------

median tracking time: 0.0187857
mean tracking time: 0.0193772

Saving camera trajectory to CameraTrajectory.txt ...

trajectory saved!

Saving keyframe trajectory to KeyFrameTrajectory.txt ...

trajectory saved!

用时 0.0187857,约合 53hz,和论文里面 GTX1070laptop 的 80hz 还是差的有点远。

后面又跑了几次,结果更慢了。不过整体还是比 CPU 运行快了 n 多倍了!

plaintext
1
2
median tracking time: 0.0225817
mean tracking time: 0.0236844

7. 尝试 4090 运行失败

7.1. 环境配置(PyTorch 1.11.0)

我尝试使用过 4090 显卡,环境如下。4090 没办法选更低版本的 PyTorch 了。

plaintext
1
2
3
PyTorch  1.11.0
Python 3.8(ubuntu20.04)
Cuda 11.3

依赖项都用相同的命令安装,以下是安装依赖项时的部分截图。

image.png

对应的 Pytorch 1.11.0 版本的 libtorch 下载链接如下。

plaintext
1
https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip

整个包比较大,一共有 1.6GB,需要慢慢等待下载了。建议还是本地提前下好再传上去,毕竟 autodl 每一分钟都是钱呐!

image.png

最终项目可以正常编译完成(也需要执行上文提到的代码修改)

image.png

7.2. 数据集处理

在 Pytorch1.11.0 镜像中需要用下面的方式安装 python2 来处理数据集,主要是 python-pip 包会提示不可用,没办法直接安装。

bash
1
2
3
4
5
# 安装python2
apt-get install -y python-dev-is-python2
# 安装pip2
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py

获取到的 python2 如下,随后正常安装 numpy 来运行脚本就行了

plaintext
1
2
3
4
root@autodl-container-64eb44b6f5-c569ba8d:~# python2 -V
Python 2.7.18
root@autodl-container-64eb44b6f5-c569ba8d:~# pip2 -V
pip 20.3.4 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

7.3. 运行 GCN2 发生 coredump

还是用相同的命令启动程序

bash
1
2
3
export DISPLAY=:1
cd GCN2
GCN_PATH=gcn2_320x240.pt ./rgbd_gcn ../Vocabulary/GCNvoc.bin TUM3_small.yaml ../datasets/TUM/rgbd_dataset_freiburg1_desk ../datasets/TUM/rgbd_dataset_freiburg1_desk/associate.txt

完蛋,coredump 了!

plaintext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Camera Parameters: 
- fx: 267.7
- fy: 269.6
- cx: 160.05
- cy: 123.8
- k1: 0
- k2: 0
- p1: 0
- p2: 0
- fps: 30
- color order: RGB (ignored if grayscale)
terminate called after throwing an instance of 'c10::Error'
what(): Legacy model format is not supported on mobile.
Exception raised from deserialize at ../torch/csrc/jit/serialization/import.cpp:267 (most recent call first):
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) + 0x6b (0x7fefb6de20eb in /root/autodl-tmp/libtorch/lib/libc10.so)
frame #1: c10::detail::torchCheckFail(char const*, char const*, unsigned int, char const*) + 0xd1 (0x7fefb6dddc41 in /root/autodl-tmp/libtorch/lib/libc10.so)
frame #2: <unknown function> + 0x35dd53d (0x7feff3ef353d in /root/autodl-tmp/libtorch/lib/libtorch_cpu.so)
frame #3: torch::jit::load(std::shared_ptr<caffe2::serialize::ReadAdapterInterface>, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0x1cd (0x7feff3ef48ad in /root/autodl-tmp/libtorch/lib/libtorch_cpu.so)
frame #4: torch::jit::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0xc1 (0x7feff3ef64c1 in /root/autodl-tmp/libtorch/lib/libtorch_cpu.so)
frame #5: torch::jit::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, c10::optional<c10::Device>) + 0x6f (0x7feff3ef65cf in /root/autodl-tmp/libtorch/lib/libtorch_cpu.so)
frame #6: ORB_SLAM2::GCNextractor::GCNextractor(int, float, int, int, int) + 0x670 (0x7ff071e213c0 in /root/autodl-tmp/GCNv2_SLAM/lib/libORB_SLAM2.so)
frame #7: ORB_SLAM2::Tracking::Tracking(ORB_SLAM2::System*, DBoW2::TemplatedVocabulary<cv::Mat, DBoW2::FORB>*, ORB_SLAM2::FrameDrawer*, ORB_SLAM2::MapDrawer*, ORB_SLAM2::Map*, ORB_SLAM2::KeyFrameDatabase*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) + 0x1e7e (0x7ff071dfcf0e in /root/autodl-tmp/GCNv2_SLAM/lib/libORB_SLAM2.so)
frame #8: ORB_SLAM2::System::System(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ORB_SLAM2::System::eSensor, bool) + 0x5ae (0x7ff071de459e in /root/autodl-tmp/GCNv2_SLAM/lib/libORB_SLAM2.so)
frame #9: main + 0x22f (0x5609d811ae2f in ./rgbd_gcn)
frame #10: __libc_start_main + 0xf3 (0x7fefb704a083 in /lib/x86_64-linux-gnu/libc.so.6)
frame #11: _start + 0x2e (0x5609d811c7ce in ./rgbd_gcn)

Aborted (core dumped)

GPT 说此问题是因为 save 模型和 load 模型的 PyTorch 版本不一致,导致无法加载。如果不出意外的话 GCNv2 应该是用 README 里面写的 PyTorch 1.0.1 版本来保存模型的,可能是 1.0.1 版本已经和 1.11.0 版本完全不兼容了。

这个问题我没找到解决方案,于是放弃治疗。本来 GCNv2 就是一个很老的项目了,在 40 系显卡上不好运行也正常。网上其实能搜到一篇在 4060 拯救者上运行 GCNv2 的博客,但是那篇博客里面并没有提到这个 coredump 的问题,问 GPT 也没给出一个可行的方案,还是不浪费时间了。

7.4. 尝试使用 PyTorch 1.10.0 镜像

上面这个 coredump 搜到了几篇 github issue,有的提到了可能是 PyTorch 1.11.0 版本和之前版本的镜像加载方式不同,导致无法 load 镜像。所以尝试使用 PyTorch 1.10.0 版本来重新测试一下。

plaintext
1
2
3
PyTorch  1.10.0
Python 3.8(ubuntu20.04)
Cuda 11.3

对应版本 libtorch 的下载链接,其他依赖项用上文提到的命令安装就可以了。

plaintext
1
https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.10.0%2Bcu113.zip

然而并不行,依旧会有错误,这一次没有加载模型的 error 了,变成了段错误。

plaintext
1
2
3
4
5
6
7
Start processing sequence ...
Images in the sequence: 573

Pass 'Combine redundant instructions' is not initialized.
Verify if there is a pass dependency cycle.
Required Passes:
Segmentation fault (core dumped)

在类似项目 YOLO_ORB_SLAM3 的仓库中能找到相关的 issue:github.com/YWL0720/YOLO_ORB_SLAM3/issues/12,依旧是 libtorch 版本不对导致的问题,issue 中提到的解决办法是将 libtorch 降低到 1.7.1 版本。

看来是没辙啦,因为 40 系显卡至少需要 CUDA 11.3 版本,在 AutoDL 上最低只能选择到 PyTorch 1.10.0 的镜像了,没法装 1.7.0 的镜像。

不再尝试了。

8. The end

本文成功在 2080ti 的环境上运行了 GCNv2_SLAM 项目,虽然运行速度依旧抵不上论文中用 1070laptop 跑出来的 80HZ,但总比本地 CPU 运行的龟速快多了。