[英]pytorch error : " Expected isFloatingType(grad.scalar_type()) || (input_is_complex == grad_is_complex) to be true, but got false "
I am working on the implementation of the classification problem.我正在研究分类问题的实现。 My code works well before inserting the complex noise into the output layer.
在将复杂噪声插入 output 层之前,我的代码运行良好。
The following code does not work with Pytorch error以下代码不适用于 Pytorch 错误
def forward(self, x):
#Encoder Process
out = self.feature(x)
out = self.encoder(out)
out = self.last(out)
#### Start of error point ######
batch_size, y = out.size()
out_real = x[:, 0:int(y / 2)]
out_comp = x[:, int(y / 2) : y + 1]
out_comp = out_comp * 1j
symbols = out_real + out_comp
n = torch.randn(symbols.shape. dtype=torch.cfloat).to(device)
out = symbols + n
out_real = out.real
out_imag = out.imag
out = torch.cat((out_real, out_imag),1)
#### End of error point ######
#Decoder process
out0 = self.decoder0(out)
out1 = self.decoder1(out0)
out1 += self.shortcut(out0)
out2 = self.decoder2(out1)
out2 += self.shortcut(out1)
Before adding '### start of error point ###... ### end of error point ###' lines the code works well and classification works.在添加 '### start of error point ###... ### end of error point ###' 行之前,代码运行良好并且分类工作正常。 But I get the following error on last line after adding codes:
RuntimeError: Expected isFloatingType(grad.scalar_type()) || (input_is_complex == grad_is_complex) to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
但是我在添加代码后的最后一行出现以下错误:
RuntimeError: Expected isFloatingType(grad.scalar_type()) || (input_is_complex == grad_is_complex) to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
RuntimeError: Expected isFloatingType(grad.scalar_type()) || (input_is_complex == grad_is_complex) to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)
What could that be?那会是什么? What should I do?
我应该怎么办? I want to add noise with complex, not real.
我想添加复杂的噪音,而不是真实的。
I think this error message is the least of your worries.我认为此错误消息是您最不担心的。
What are you trying to do?你想做什么? What is the meaning of adding complex noise, when you treat your features as two real parts?
当您将特征视为两个实部时,添加复杂噪声的含义是什么? How is it different than just adding noise to
out
?与只是在
out
添加噪音有什么不同?
If you really want to make your decoder complex, you should leave out
as a complex tensor and allow the weights of the decoders and shortcuts to be complex as well.如果你真的想让你的解码器变得复杂,你应该
out
一个复杂的张量,并允许解码器的权重和捷径也变得复杂。 This will actually create interactions between the real parts and the imaginary parts of your tensor.这实际上会在你的张量的实部和虚部之间创建交互。 Right now, there is no "complex" meaning for the real and imaginary parts of
out
, they are just additional dimensions.现在,
out
的实部和虚部没有“复杂”的含义,它们只是附加维度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.