pytorch1.2.0下使用目标检测模型训练报错"RuntimeError: expected device cpu and dtype Float but got device cuda"解决办法

pytorch1.2.0下使用目标检测模型训练报错"RuntimeError: expected device cpu and dtype Float but got device cuda"解决办法


  • 报错信息:
    RuntimeError: expected device cpu and dtype Float but got device cuda

  • 报错原因:
    报错可能是代码中存在device为cuda和device为cpu的torch.tensor运算

  • 调试方法
    可以打印可能有问题的torch.tensor变量的device属性来查看

  • 解决方法
    统一device即可,可以使用cpu()方法统一device为cpu。

版权声明:本文为weixin_42398077原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。