美文网首页
RuntimeError: Found dtype Long b

RuntimeError: Found dtype Long b

作者: 在努力的Jie | 来源:发表于2020-11-10 11:07 被阅读0次

说明此时需要float型数据,但识别到long型数据,此时需要对入参和出参做一下类型转换

output=output.to(torch.float32)
target=target.to(torch.float32)

例证如下:

output =net(input)
target = variable(t.arange(0,10))

#the point
output=output.to(torch.float32)
target=target.to(torch.float32)

criterion = nn.MSELoss()
loss = criterion(output,target)

net.zero_grad()
print("反向传播之前conv1.bias的梯度")
print(net.conv1.bias.grad)
loss.backward()          #此处疑难杂症  先跳过
print("反向传播之后conv1.bias的梯度")
print(net.conv1.bias.grad)

相关文章

网友评论

      本文标题:RuntimeError: Found dtype Long b

      本文链接:https://www.haomeiwen.com/subject/rirlbktx.html