Saving/exporting models with torch.save relies on pickling the given network, which results in errors for the generator models in the code base as they use unpickable lambda functions when an identity operation needs to be used.
These changes replace the usage of lambda functions by their corresponding torch operations, enabling the saving of models.
The error can be simply reproduced for a given model using the following code:
import torch
from models.stylegan_generator import StyleGANGenerator
model = StyleGANGenerator('stylegan_ffhq')
torch.save(model.model, 'model.pt')
for the StyleGAN model and
import torch
from models.pggan_generator_model import PGGANGeneratorModel
model = PGGANGenerator('pggan_celebahq')
torch.save(model.model, 'model.pt')
for the PGGAN one.
Edit: the identity operation is a relatively new feature and has been merged in this PR.
Saving/exporting models with
torch.save
relies on pickling the given network, which results in errors for the generator models in the code base as they use unpickable lambda functions when an identity operation needs to be used.These changes replace the usage of lambda functions by their corresponding torch operations, enabling the saving of models.
The error can be simply reproduced for a given model using the following code:
for the StyleGAN model and
for the PGGAN one.
Edit: the identity operation is a relatively new feature and has been merged in this PR.