pytorch框架在写test.py时,报了一个输入,输出类型不一致;
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
输出类型是torch.cuda.FloatTensor,是因为模型训练在gpu上跑的;
所以在加载模型时,指定设备为cpu这样就与输入类型保持一致。指定代码:
map_location=torch.device("cpu")
例如:
module = torch.load("vincent_0.pth", map_location=torch.device("cpu"))
然后问题解决了。