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

RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same or input should be a MKLDNN tensor and weight is a dense tensor


错误原因:

这个错误提示表明输入数据的类型和模型权重的类型不匹配,可能是因为模型权重是在GPU上训练的,而输入数据是在CPU上进行的。

可以使用model.to('cpu')将模型权重转移到CPU上,然后再对输入数据进行处理。

model_path = '模型路径'
model = torch.load(model_path)
model.to('cpu')

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
扎眼的阳光的头像扎眼的阳光普通用户
上一篇 2023年11月7日
下一篇 2023年11月7日

相关推荐