Pytorch1.4下运行 GCNv2slam 需要修改的地方

1 .编译
GCNextractor.h 第99行:

std::shared_ptr<torch::jit::script::Module> module;

改为:

 torch::jit::script::Module module;

GCNextractor.cc 第270行:

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

改为:

auto output = module.forward(inputs).toTuple();

2.运行GCN模式:
由于开源项目中打包的 gcn2_320x240.pt 模型文件 pytorch 版本为1.0.1;在1.4版本下,函数torch.grid_sampler()相比于1.0.1多了一个参数 ,具体见:这里

因此运行时会报错:

aten::grid_sampler(Tensor input, Tensor grid, int interpolation_mode, int padding_mode, bool align_corners) -> (Tensor):
Argument align_corners not provided.

The original call is:
at code/gcn.py:67:22
_25 = torch.slice(vu, 0, 0, 9223372036854775807, 1)
_26 = torch.select(_25, 1, 0)
_27 = torch.slice(vu, 0, 0, 9223372036854775807, 1)
_28 = torch.select(_27, 1, 1)
_29 = torch.to(_26, dtype=4, layout=0, device=torch.device("cuda:0"), non_blocking=False, copy=False)
_30 = torch.to(_28, dtype=4, layout=0, device=torch.device("cuda:0"), non_blocking=False, copy=False)
_31 = torch.unsqueeze(torch.index(CONSTANTS.c1, [_29, _30]), 1)
ref_points = torch.cat([_24, _31], 1)
grid = torch.view(ref_points, [1, 1, -1, 2])
_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0))
~~~~~~~~~~~~~~~~~~ <--- HERE
desc_1 = torch.t(_32)
desc_2 = torch.to(torch.gt(desc_1, 0), 6, False, False)
_33 = ops.prim.NumToTensor(torch.size(desc_2, 0))
desc_3 = torch.view(desc_2, [int(_33), 32, 8])
desc_4 = torch.mul(desc_3, CONSTANTS.c2)
desc = torch.sum(desc_4, [2], False)
_34 = (_17, torch.to(desc, 0, False, False))
return _34`

由于作者没有公布权重文件,在不用回到pytorch 1.0.1,仍然想使用pytorch1.4运行的话,需要做以下的修改:
用压缩工具软件打开gcn2_320x240.pt (不解压),在’/gcn/code/'下找到 ‘gcn.py’,定位到报错所在行(第67行):

_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0))
~~~~~~~~~~~~~~~~~~ <--- HERE

在最后新添加一个参数’True’:

_32 = torch.squeeze(torch.grid_sampler(input, grid, 0, 0, True))

保存。
下边是源码的警告信息,

if align_corners is None:
        warnings.warn("Default grid_sample and affine_grid behavior has changed "
                      "to align_corners=False since 1.3.0. Please specify "
                      "align_corners=True if the old behavior is desired. "
                      "See the documentation of grid_sample for details.")
        align_corners = False

英语渣,我猜的添加True,能跑通。。。。。

评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值