Enviroment:
# OCR optimizer
ocr_loss.backward(retain_graph=True)
self.ocr_optimizer.step()

# Total generator loss
loss_G = loss_content + self.opt.lambda_adv * loss_GAN + self.opt.lambda_pixel * loss_pixel
loss_G += ocr_loss
loss_G.backward(retain_graph=True)
self.optimizer_G.step()

…
Error:
RuntimeError: 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.