Input type and weight type should be the same

时间:2025-05-07 15:53:50

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


错误原因:

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

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

model_path = '模型路径'
model = (model_path)
('cpu')