Ubuntu16.04中GCNv2-SLAM的CPU版本

Ubuntu16.04中GCNv2-SLAM的CPU版本

代码下载:
https://github.com/jiexiong2016/GCNv2_SLAM
libtorch个版本下载:
https://blog.csdn.net/weixin_43742643/article/

注意:下载cxx11 ABI版本

我使用的是
libtorch-cxx11-abi-shared-with-deps-1.7.1%2Bcu101.zip

一.编译之前的修改

Pytorch1.4及以后版本下运行 GCNv2slam 需要修改的地方,libtorch1.4之后使用的是C++14,之前为c++11

GCNextractor.h 第99行:

std::shared_ptr<torch::jit::script::Module> module;
//改为
auto output = module->forward(inputs).toTuple();

GCNextractor.cc 第270行:

auto output = module->forward(inputs).toTuple();
//改为
auto output = module.forward(inputs).toTuple();

GCNv2_SLAM-master下的CMakeLists.txt

//更改c++编译标准 
set(CMAKE_CXX_STANDARD 14)
 
 
//在if( TORCH_PATH ) 
set(TORCH_PATH "/home/***/libtorch/share/cmake/Torch")
 
//最后项目链接  从11改成14
set_property(TARGET rgbd_gcn PROPERTY CXX_STANDARD 14)

双击打开gcn2_320x240.pt (其他pt文件同理)(无需解压)/gcn/code/'下找到 ‘gcn.py’

#原   这是因为1.3以前默认true   1.3以后默认false
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0))
#改为
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0, True))

二.CPU下运行需要修改的地方:

将GCNextractor.cc的218行改为:

    torch::DeviceType device_type;//##
    device_type = torch::kCPU;//##
    torch::Device device(device_type);//##

    const char *net_fn = getenv("GCN_PATH");
    net_fn = (net_fn == nullptr) ? "gcn2.pt" : net_fn;
    module = torch::jit::load(net_fn, device);//##

并使用全局搜索,将torch::kCUDA替换为torch::kCPU
将GCN2/gcn2_320x240.pt文件中的gcn/code/gcn.py中的cuda:0替换为cpu

编译、运行

GCNv2_SLAM-master下执行

./build.sh

//运行,在GCN2下执行
./run.sh

记得要修改run.sh中内容:相关路径换成自己的
例如:

# Run GCN, removed resolution requirment. The current model was trained with resolution 320x240 as input. Use other resolution may affect the actual performance. Ideally, GCNv2 should be trained/finetuned in desired resolution.
GCN_PATH=gcn2_320x240.pt ./rgbd_gcn ../Vocabulary/GCNvoc.bin TUM3_small.yaml /home/用户名/Data/rgbd_dataset_freiburg3_long_office_household /home/用户名/Data/rgbd_dataset_freiburg3_long_office_household/associations.txt

运行结果:
在这里插入图片描述

参考博客:
https://blog.csdn.net/qq_35942419/article/details/120556046
https://blog.csdn.net/u011622208/article/details/116935969

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值