【Bug】Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be same

今天部署模型时遇到一个问题:
RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the same

报错原因:
原因是cpu和cdua 使用的不一致,我这里是因为模型加载时没用将其分配到GPU中,做个记录。

解决办法:

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
model = torch.load('best.pt')
model = model.to(device)  # 加上这一句

或者

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
print(device)
model = torch.load('best.pt',map_location=device)

参考:
https://blog.csdn.net/momo_mo520/article/details/105668810

上一篇:mxgate是gpcopy同步速度的2倍


下一篇:Unity实现鼠标长按对象打开麦克风,鼠标松开关闭麦克风(IPointerDownHandler,IPointerUpHandler)