我有一组旋转矩阵RS:
Rs.shape = [62x3x3]
和一组翻译组件JS:
Js.shape = [62x3]
我一直在试图找到一种将它们组合到[62x4x4]矩阵中的有效方法,该矩阵是62个均匀变换矩阵。目前,我正在以一个愚蠢的循环进行:
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毫秒的形成。我如何张紧这个?
不确定它是否有助于效率,但这应该矢量化您的代码:
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)