exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "F:/GPAI/secondTimes/CatchYou/Train.py", line 49, in <module>
pre_rect = out[0].numpy()
RuntimeError: Can't call numpy() on Variable that requires grad. Use var.detach().numpy() instead.
問題代碼:
按報錯提醒修改後,成功運行。。。在有求導要求的參數上不能直接用numpy()轉,要用var.detach().numpy()
直接打印出來可以看到, 第一個tensor可以直接numpy(),第二個要轉