【问题标题】:Pytorch - How to efficiently form this Transform tensor?Pytorch - 如何有效地形成这个变换张量?
【发布时间】:2019-07-08 20:48:19
【问题描述】:

我有一组旋转矩阵 Rs:

Rs.shape = [62x3x3]

还有一套翻译组件Js:

Js.shape = [62x3]

我一直在尝试找到一种有效的方法将它们组合成一个 [62x4x4] 矩阵,该矩阵是 62 个同质变换矩阵。目前我正在用一个愚蠢的 for 循环来做这件事:

def make_A(R, t):
    R_homo = torch.cat([R, torch.zeros(1, 3).cuda()], dim = 0)
    t_homo = torch.cat([t.view(3,1), torch.ones(1, 1).cuda()], dim = 0)
    return torch.cat([R_homo, t_homo], dim=1)

transforms = self.NUM_JOINTS*[None]
for idj in range(0, self.NUM_JOINTS):
    transforms[idj] = make_A(Rs[idj, :], Js[idj,:])

FinalMatrix = torch.stack(transforms, dim=0)

这是非常低效的,并且需要将近 10 毫秒才能形成。我怎样才能张张这个?

【问题讨论】:

  • 我靠近了:torch.cat([Rs, torch.unsqueeze(J_vec, -1)], dim = 2) 我只需要弄清楚如何添加 [0,0,0 ,1]

标签: pytorch


【解决方案1】:

不确定它是否有助于提高效率,但这应该矢量化您的代码:

def make_A(Rs, Js):
    R_homo = torch.cat((Rs, torch.zeros(Rs.shape[0], 1, 3)), dim=1)
    t_homo = torch.cat((Js, torch.ones(Js.shape[0], 1)), dim=1)
    return torch.cat((R_homo, t_homo.unsqueeze(2)), dim=2)

【讨论】:

    猜你喜欢
    • 2019-05-10
    • 2020-10-04
    • 1970-01-01
    • 2022-01-16
    • 2021-07-23
    • 2020-12-04
    • 1970-01-01
    • 2021-10-11
    • 2022-10-17
    相关资源
    最近更新 更多