简体   繁体   English

pytorch 错误:“预期 isFloatingType(grad.scalar_type()) || (input_is_complex == grad_is_complex) 为真,但结果为假”

[英]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.

相关问题 Pytorch autograd 引发错误:“预期 isFloatingType(grads[i].type().scalarType()) 为真,但在 loss.backward() 时为假” - Pytorch autograd raising the error: "Expected isFloatingType(grads[i].type().scalarType()) to be true, but got false" when loss.backward() PyTorch torch.no_grad() 与 requires_grad=False - PyTorch torch.no_grad() versus requires_grad=False pytorch 收集失败,sparse_grad=True - pytorch gather failed with sparse_grad=True pytorch 如何设置 .requires_grad False - pytorch how to set .requires_grad False 我可以将 volatile = False 更改为 torch.set_grad_enabled(True) 吗??(在 Pytorch 中) - Can I change volatile = False to torch.set_grad_enabled(True)??(in Pytorch) PyTorch autograd - 只能为标量输出隐式创建grad - PyTorch autograd — grad can be implicitly created only for scalar outputs Pytorch 错误:输入应该是标量类型 Long 但发现是 Float - Pytorch error: input is expected to be scalar type Long but found Float 在遗留 PyTorch 中使用 requires_grad=False 将张量包装在变量中的实用程序 - Utility of wrapping tensor in Variable with requires_grad=False in legacy PyTorch 冻结 pytorch model 的问题 - requires_grad 始终为真 - Problem with freezing pytorch model - requires_grad is always true Pytorch 输入张量是正确的数据类型,但抛出 RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #3 - Pytorch input tensor is correct data type, but throws RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM