项目场景:
手搓神经网络
问题描述:
RuntimeError: Input type (torch.cuda.DoubleTensor) and weight type (torch.cuda.FloatTensor) should be the same
原因分析:
没有把输入数据类型转为float类型
解决方案:
x = x.type(torch.cuda.FloatTensor)
注意,加上 .cuda
我参考的文章给了我思路,在我实践的时候,发现还需要添加.cuda
参考链接
链接: link.

在实现手搓神经网络时遇到RuntimeError,原因是输入数据类型与权重数据类型不一致。问题根源在于输入数据未转换为浮点型。解决方案是在输入数据x前添加.type(torch.cuda.FloatTensor)进行类型转换,并确保使用.cuda()处理GPU设备。参考文章提供了关键思路,实践中发现实际操作还需包括.cuda()来完成数据迁移。
4504

被折叠的 条评论
为什么被折叠?



