记录一次Yolo5 GPU模型在CPU运行问题
问题
- Exception has occurred: RuntimeError
Input type (torch.FloatTensor) and weight type (torch.HalfTensor) should be the same - 输入的类型(CPU)应该和模型类型一致 (GPU)
问题解析
- 因为模型一开始是在GPU训练的 后来换了一台没有GPU只有CPU的机器使用模型
- 把GPU模型转为CPU模型加载使用
解决方案
-
#此处的device的类型已是CPU model = torch.load(weights, map_location=device)['model'] model.to(device).eval() #将上边这一句替换为下边即可 或加入float() model.to(device).float().eval()
参考资料
- [1] Github