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

    在运行自己修改后的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]]
    保存后重新运行,不再报错成功运行。

你可能感兴趣的:(RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.)