GAN网络走过的坑
程序员文章站
2023-12-31 21:03:34
...
所用语言:PyTorch,python3.6
复现DCGAN代码时出现ERROR如下:Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.
后在所有的loss中添加retain_graph=True,解决了该问题。loss_d.backward(retain_graph=True)
但伴随着出现了如下问题out of memory
在gen_data后加detach(),删除上面添加的retain_graph=True,解决了上述所有问题
d_fake = discriminator(gen_data.detach())