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
錯(cuò)誤原因:
這個(gè)錯(cuò)誤提示表明輸入數(shù)據(jù)的類型和模型權(quán)重的類型不匹配,可能是因?yàn)槟P蜋?quán)重是在GPU上訓(xùn)練的,而輸入數(shù)據(jù)是在CPU上進(jìn)行的。文章來源:http://www.zghlxwxcb.cn/news/detail-739826.html
可以使用model.to('cpu')
將模型權(quán)重轉(zhuǎn)移到CPU上,然后再對(duì)輸入數(shù)據(jù)進(jìn)行處理。文章來源地址http://www.zghlxwxcb.cn/news/detail-739826.html
model_path = '模型路徑'
model = torch.load(model_path)
model.to('cpu')
到了這里,關(guān)于Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!