During Gan’s training, we often encounter this problem: runtimeerror: trying to backward through the graph a second time, but the saved intermediate results have already been free
The description of this error is that when you are propagating in the direction, the cache is released in advance. Many solutions are to change loss. Backward() to loss. Backward (retain_graph = true). In fact, most of the code problems are not here, and the retention of the calculation chart may cause the cache to accumulate rapidly and lead to the explosion of the video memory, In fact, the real reason is that the discriminator and the producer share the same variables. Just add detach () when using variables for the first time.
#### Update Discriminator ###
real_preds = netD(real_gt)
fake_preds = netD(fake_coarse)
#### Update Generator #####
real_preds = netD(real_gt)
fake_preds = netD(fake_coarse)
Change to:
#### Update Discriminator ###
real_preds = netD(real_gt.detach())
fake_preds = netD(fake_coarse.detach())
#### Update Generator #####
real_preds = netD(real_gt)
fake_preds = netD(fake_coarse)
It’s not easy to find the method. Thank you for your support
Read More:
- [Solved] Pytorch3d Error: RuntimeError: Not compiled with GPU support.
- [Solved] pytorch CrossEntropyLoss Error: RuntimeError: 1D target tensor expected, multi-target not supported
- [Solved] pytorch Load Error: “RuntimeError: Error(s) in loading state_dict for Sequential:”
- [Solved] Failed to allocate graph: MYRIAD device is not opened.
- [Solved] rqt_graph Skipped loading plugin with error & Format: “dot“ not recognized
- [Solved] MindSpore Error: task_fail_info or current_graph_ is nullptr
- [Solved] src/delly.h:8:42: fatal error: boost/graph/adjacency_list.hpp: No such file or directory
- MacOS Mojave uses SMB LAN share as backup disk of timemachine time machine. Disk does not support time machine backups. (error 45)
- Build the graph With the gmapping algorithm error: ERROR: cannot launch node of type [gmapping/slam_gmapping]: gmapping
- Pytorch failed to specify GPU resolution
- How to Solve “Status bar could not find cached time string image. Rendering in-process.” in Xcode
- [Solved] Runtimeerror during dcgan training: found dtype long but expected float
- [Solved] Pytorch loading model specified GPU card number error or failed to specify
- [Solved] MindSpore Error: “RuntimeError: Unable to data from Generator..”
- [Solved] RuntimeError: CUDA error: out of memory
- [Solved] .NetCore2.2 Upgrade to 3.1 Error: HTTP Error 500.37 – ANCM Failed to Start Within Startup Time
- RuntimeError: CUDNN_STATUS_EXECUTION_FAILED [How to Solve]
- RuntimeError: Exporting the operator uniform to ONNX opset version 12 is not supported.
- How to Solve Error: RuntimeError: all tensors must be on devices[0]
- Run-time error “70“:Permission denied [How to Solve]