loss_l1 = criterion_loss(fake_img, usm)
loss_percep = criterion_perceptual(fake_img, usm)
loss_gan = criterion_gan(fake_out, True, is_disc = False)
loss_g += loss_l1 + loss_percep + loss_gan
loss_g.backward()
위처럼 하고 싶은데 += 이렇게 중첩 시키면 backward에서 오류남
Trying to backward through the graph a second time (or directly access saved tensors after they have already been freed). Saved intermediate values of the graph are freed when you call .backward() or autograd.grad(). Specify retain_graph=True if you need to backward through the graph a second time or if you need to access saved tensors after calling backward.
loss = loss_g + loss_l1 + loss_percep + loss_gan loss.backward()