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')

猜你喜欢

转载自blog.csdn.net/weixin_45888522/article/details/130221913