下面的代码会导致 报错同一个内存被多个索引使用。需要改成 repeat
batch_rotation_matrix = single_rotation_matrix.unsqueeze(0).expand(N, -1, -1)
修改之后,成功运行:
batch_rotation_matrix = single_rotation_matrix.repeat(N, 1, 1)
文章讲述了在Python代码中,原始的内存分配方式(unsqueeze和expand)导致同一个内存被多个索引访问引发错误。作者提供了一种解决方案,即通过`repeat`函数来正确地重复单个旋转矩阵,从而成功避免了错误。
下面的代码会导致 报错同一个内存被多个索引使用。需要改成 repeat
batch_rotation_matrix = single_rotation_matrix.unsqueeze(0).expand(N, -1, -1)
修改之后,成功运行:
batch_rotation_matrix = single_rotation_matrix.repeat(N, 1, 1)

被折叠的 条评论
为什么被折叠?