我正在使用这个自定义函数来重塑自定义损失函数中的张量。
def reshape_fortran(x, shape):
if len(x.shape) > 0:
x = x.permute(*reversed(range(len(x.shape))))
return x.reshape(*reversed(shape)).permute(*reversed(range(len(shape))))尽管如此,我还是收到这个错误:
RuntimeError: _unsafe_view does not support automatic differentiation for outputs with complex dtype.
用于reshape_fortran输出。
你知道问题出在哪里吗?在复数的Pytorch autograd中不支持哪个函数?
发布于 2021-06-22 00:03:07
Complex Autograd在测试版1.8中,但现在是稳定的,应该完全支持像1.9这样的操作。
发布于 2020-11-06 10:16:59
我能够通过使用这个函数来解决这个问题,但我不知道为什么它不能工作,为什么它现在能工作:
def convert_output84_torch(input):
shape84 = (8,4)
T1 = torch.transpose(input,0,2).permute(0,1,2).contiguous()
T2 = T1.view(shape84[::-1])
output = torch.transpose(T2,0,1)
return output我用view替换了reshape,它工作得很好(目前)。但由于我的代码之前运行良好,我不确定这是否是一个长期的解决方案,因为我不知道主要的源代码。
https://stackoverflow.com/questions/64689253
复制相似问题