Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

Posted LiQiang33

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same相关的知识,希望对你有一定的参考价值。

1. 原因

  • 输入的矩阵的数据类型与神经网络权重的数据类型不一致

解决办法

  • 将输入的数据与神经网络放到同一个设备上

device = torch.device("cuda:0")

# -------

x, y = x.to(device), y.to(device)

# --------

model.to(device)

以上是关于Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same的主要内容,如果未能解决你的问题,请参考以下文章