遇到报错
TypeError: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of:
- (name dim0, name dim1)
- (int dim0, int dim1)
请问应该怎么解决呢?
遇到报错
TypeError: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of:
根据错误信息,R.transpose(0, 2, 1)
函数接收到了 (int, int, int)
类型的参数,但是期望的参数类型是 (name dim0, name dim1)
或者 (int dim0, int dim1)
,这说明应该是输入的参数格式有误。
根据你的代码,R
是一个形状为 (B, 3, 3)
的张量,其中 B
是 batch size。因此,正确的 transpose 函数调用方式应该是:
R.transpose(1, 2) # 将 R 张量的第 1 维和第 2 维进行转置
在这里,我们将第 1 维和第 2 维进行转置,因为你想要对每个 batch 中的 3x3 矩阵进行转置。
修改后的代码如下:
def mge_transform(g, a, normals=None):
R = g[..., :3, :3] # (B, 3, 3)
p = g[..., :3, 3] # (B, 3)
if len(g.shape) == len(a.shape):
b = F.matmul(a, R.transpose(1, 2)) + F.expand_dims(p, axis=1)
else:
raise NotImplementedError
如果还有问题,请检查一下 igt
和 points_src
张量的维度是否与上述代码中的张量维度相同。