JCBrouwer / maua-stylegan2

This is the repo for my experiments with StyleGAN2. There are many like it, but this one is mine. Contains code for the paper Audio-reactive Latent Interpolations with StyleGAN.
https://wavefunk.xyz/audio-reactive-stylegan
179 stars 29 forks source link

Error when converting tensorflow .pkl checkpoint to pytorch .pt checkpoint #13

Closed kirkegross closed 3 years ago

kirkegross commented 3 years ago

Hi! I loaded in my own .pkl model and got this error after trying to convert tensorflow .pkl checkpoint to pytorch .pt checkpoint. Is there something wrong with my model?

Traceback (most recent call last): File "../stylegan2-pytorch/convert_weight.py", line 236, in generator, discriminator, g_ema = pickle.load(f) TypeError: 'Sequential' object is not iterable

Best, Kirke

JCBrouwer commented 3 years ago

Hey there, it looks like the pickle file you're loading isn't returning a tuple of (generator, discriminator, g_ema). It's probably only the generator (as that's all you need for the colab).

Double clicking the file in the file browser on the left will open an editor. You can edit that line to remove , discriminator, g_ema. Then you can try running the !python convert_weight.py ... cell again.

kirkegross commented 3 years ago

Thank you, will try it out !

kirkegross commented 3 years ago
Screenshot 2021-02-13 at 19 21 15

If I removed this I got this error now. Can I also change this line to something else: size = g_ema.output_shape[2]

JCBrouwer commented 3 years ago

Oh, my bad g_ema is the one that gets used later on (that's the moving average of the generator which tends to have higher quality outputs). You should make sure the line is g_ema = pickle.load(f).

kirkegross commented 3 years ago

Thank you! I changed line 236 to this g_ema = pickle.load(f)

Screenshot 2021-02-14 at 09 29 36

Now I got this: AttributeError: 'Sequential' object has no attribute '_inbound_nodes'

JCBrouwer commented 3 years ago

How have you created this .pkl file? What repository did you use to train your StyleGAN2 network?

This error seems to show that your .pkl file doesn't have some properties that the correct tensorflow network checkpoint should have.

kirkegross commented 3 years ago

Ok I see, thanks! That's what I thought. I trained my model following this tutorial https://github.com/jeffheaton/t81_558_deep_learning/blob/master/t81_558_class_07_2_Keras_gan.ipynb (Implementing DCGANs in Keras). In this tutorial the model was saved as .h5 and I converted it to .pkl.

But I understand now that I should have trained my model as StyleGAN2 network. Thanks for all the help! I will train my model as StyleGAN2 now and then I can use this repo.