当前位置: 代码迷 >> 综合 >> RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
  详细解决方案

RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.

热度:86   发布时间:2023-11-23 14:16:08.0
    在运行自己修改后的pytorch程序时,遇到错误RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.定位到出错语句为:classes, scores, boxes = [x[:args.top_k].cpu().numpy() for x in t[:3]]按照错误提示,将代码修改为:classes, scores, boxes = [x[:args.top_k].cpu().detach().numpy() for x in t[:3]]保存后重新运行,不再报错成功运行。
  相关解决方案