mganprior icon indicating copy to clipboard operation
mganprior copied to clipboard

How to use Multi-Code method for StyleGAN?

Open zhufeida opened this issue 5 years ago • 8 comments

Hi, in derivable_generator.py, several configurations are listed. However, there is no multi-code configuration for StyleGAN. In fact, StyleGAN's design is different from pggan, where w is inserted into each middle layers of the generator by AdaIN. How to use multi-code scheme in StyleGAN scenario?

def get_derivable_generator(gan_model_name, generator_type, args):
    if generator_type == 'PGGAN-z':  # Single latent code
        return PGGAN(gan_model_name)
    elif generator_type == 'StyleGAN-z':
        return StyleGAN(gan_model_name, 'z')
    elif generator_type == 'StyleGAN-w':
        return StyleGAN(gan_model_name, 'w')
    elif generator_type == 'StyleGAN-w+':
        return StyleGAN(gan_model_name, 'w+')
    elif generator_type == 'PGGAN-Multi-Z':  # Multiple Latent Codes
        return PGGAN_multi_z(gan_model_name, args.composing_layer, args.z_number, args)
    else:
        raise Exception('Please indicate valid `generator_type`')

zhufeida avatar Apr 09 '20 13:04 zhufeida

Same issue!

yue95213 avatar Apr 13 '20 07:04 yue95213

Hi, @yue95213 and @zhufeida. Thank you for your question. It worth noticing that the stylegan has multi-code design natively (the style code for each layer) and the stylegan-w+ is for the inversion using these codes. Use multi-code strategy on stylegan is equivalent to an over-parameterization version of stylegan-w+ inversion. So in the released code, we recommend using stylegan-w+.

JasonGUTU avatar Apr 17 '20 01:04 JasonGUTU

What parameters you are using for invert stylegan? I use

python multi_code_inversion.py --gan_model stylegan_bedroom 

--target_images ./examples/gan_inversion/bedroom 

 --outputs ./gan_inversion_bedroom2 

--inversion_type StyleGAN-w+

However, the results are not very realistic. What parameters should I use?

betterze avatar Apr 20 '20 16:04 betterze

What parameters you are using for invert stylegan? I use

python multi_code_inversion.py --gan_model stylegan_bedroom 

--target_images ./examples/gan_inversion/bedroom 

 --outputs ./gan_inversion_bedroom2 

--inversion_type StyleGAN-w+

However, the results are not very realistic. What parameters should I use?

Have you tried on face images? How does the face experiment work? And try to use Norm initialization. The initialization method is influential for stylegan.

JasonGUTU avatar Apr 20 '20 17:04 JasonGUTU

python multi_code_inversion.py
--gan_model stylegan2_ffhq
--target_images ./examples/face
--outputs ./gan_inversion_face
--composing_layer 8
--z_number 20
--iterations 3000
--inversion_type StyleGAN-w+
--init_type Normal
--optimization Adam
--loss_type VGG

Traceback (most recent call last): File "multi_code_inversion.py", line 112, in main(args) File "multi_code_inversion.py", line 37, in main latent_estimates, history = inversion.invert(generator, y_gt, loss, batch_size=1, video=args.video) File "/content/drive/My Drive/stylegan2/source code/mganprior/inversion/inversion_methods.py", line 24, in invert input_size_list = generator.input_size() File "/content/drive/My Drive/stylegan2/source code/mganprior/derivable_models/derivable_generator.py", line 77, in input_size return [(self.stylegan.net.synthesis.num_layers, 512)] File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 772, in getattr type(self).name, name)) torch.nn.modules.module.ModuleAttributeError: 'StyleGAN2GeneratorNet' object has no attribute 'net'

Xiaomao136 avatar Sep 18 '20 09:09 Xiaomao136

@Xiaomao136 Hello, have you solved this bug?

liuliuliu11 avatar Oct 09 '20 08:10 liuliuliu11

Please refer to genforce/idinvert project, I switched to genforce/idinvert project

liuliuliu11 [email protected] 于2020年10月9日周五 下午4:47写道:

@Xiaomao136 https://github.com/Xiaomao136 Hello, have you solved this bug?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/genforce/mganprior/issues/3#issuecomment-706055461, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMU4MTFFQ22ENHNWNQVB663SJ3E3NANCNFSM4MEXG7SA .

Xiaomao136 avatar Oct 09 '20 09:10 Xiaomao136

@JasonGUTU using stylegan_w+ for face is still far from ideal, can you show that how to split stylegan? I did that following PGGAN-Multi-Z, but it reported error that in x = self.epilogue(x, w), the shape of w is desired to be [1, 512], but actually [1, 18, 512], I've no idea what happened.

fungtion avatar Oct 30 '20 03:10 fungtion