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(),第二个要转