Learner.load() on superres-gan returns error

On the lesson7-superres-gan.ipynb notebook, after you save the gan learner and try to load it again, there is an error:

AttributeError: Can't pickle local object 'gan_loss_from_func.<locals>._loss_G'

I looked in the code and couldn’t find if the GANTrainer saved the generator and critic weights during the training process. Should we save the weights for each network manually? How can the GAN Learner load its weights, especially with custom loss functions?

Try learn.load(‘my-model’, purge=False)

Doesn’t work. Gives an error AttributeError: 'GANLearner' object has no attribute 'gen_mode' on learn.show_results() or any another inference method.

1 Like

Hi @phmagic, I got the same error as you when I try to load GANLearner weights. Did you figure it out how to do this ?

Hey @nicolivesey, I ended up saving and loading the generator / critic portions separately.

Thank you for your response, so there is no way to make a clear inference script of a GANLearner ? You have to train it each time you want to use it ?

I think we can link this issue (more like a missing feature) to this post by the way Learn.export() not working with GANs

Hi could you show the code that enabled you to save the gan critic & generator separately? Thanks!

I faced the same problem while saving and loading gan, did you find any solution?

Not yet no - I have pushed on into part 2 of the course with the hope I might understand more!