【发布时间】:2021-03-16 20:30:28
【问题描述】:
def Log(A):
'''
theta = arccos((tr(A)-1)/2)
K=1/(2sin(theta))(A-A^T)
log(A)=theta K
'''
theta=torch.acos(torch.tensor((torch.trace(A)-1)/2))
K=(1/(2*torch.sin(theta)))*(torch.add(A,-torch.transpose(A,0,1)))
return theta*K
def tensor_Log(A):
blah=[[Log(A[i,j]) for j in range(A.shape[1])] for i in range(A.shape[0])]
new=torch.tensor(blah)
return new
ValueError: only one element tensors can be converted to Python scalars
在获取我的网络输出的训练期间,上述函数产生以下错误,它在自定义层内被调用,我不知道它引用了什么,有什么想法吗?
【问题讨论】:
-
tensor_Log和Log的输入是什么形状? -
@Ivan tensor_log 是一个 4 张量,而 Log 只是一个矩阵
-
@Ivan 更具体地说 tensor_Log 是 bs x extra dim x 3 x 3 并且 log 接受 3x3 矩阵
-
好的,究竟哪一行会抛出这个错误?
标签: neural-network pytorch layer